Skip to content

Commit 7def439

Browse files
authored
Feature: Added support for PowerToys Peek (#17954)
1 parent 6cca0bb commit 7def439

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System.IO;
5+
6+
namespace Files.App.Services.PreviewPopupProviders
7+
{
8+
public sealed class PowerToysPeekProvider : IPreviewPopupProvider
9+
{
10+
public static PowerToysPeekProvider Instance { get; } = new();
11+
12+
private static string? _peekExecutablePath;
13+
14+
public async Task TogglePreviewPopupAsync(string path)
15+
{
16+
await DoPreviewAsync(path);
17+
}
18+
19+
public async Task SwitchPreviewAsync(string path)
20+
{
21+
// Not used
22+
}
23+
24+
private async Task DoPreviewAsync(string path)
25+
{
26+
if (_peekExecutablePath != null)
27+
{
28+
try
29+
{
30+
var psi = new ProcessStartInfo
31+
{
32+
FileName = _peekExecutablePath,
33+
Arguments = $"\"{path}\"",
34+
UseShellExecute = true,
35+
CreateNoWindow = true,
36+
WindowStyle = ProcessWindowStyle.Hidden
37+
};
38+
39+
Process.Start(psi);
40+
}
41+
catch
42+
{
43+
// Ignore
44+
}
45+
}
46+
}
47+
48+
public async Task<bool> DetectAvailability()
49+
{
50+
var exeName = "PowerToys.Peek.UI.exe";
51+
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
52+
var perUserPath = Path.Combine(localAppData, "PowerToys", "WinUI3Apps", exeName);
53+
54+
// User path
55+
if (File.Exists(perUserPath))
56+
{
57+
_peekExecutablePath = perUserPath;
58+
return true;
59+
}
60+
61+
// Machine-wide path
62+
string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
63+
string machinePath = Path.Combine(programFiles, "PowerToys", "WinUI3Apps", exeName);
64+
65+
if (File.Exists(machinePath))
66+
{
67+
_peekExecutablePath = machinePath;
68+
return true;
69+
}
70+
71+
// Not found
72+
return false;
73+
}
74+
}
75+
}

src/Files.App/Services/PreviewPopupProviders/PreviewPopupService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ internal sealed partial class PreviewPopupService : ObservableObject, IPreviewPo
88
{
99
public async Task<IPreviewPopupProvider?> GetProviderAsync()
1010
{
11+
if (await PowerToysPeekProvider.Instance.DetectAvailability())
12+
return await Task.FromResult<IPreviewPopupProvider>(PowerToysPeekProvider.Instance);
1113
if (await QuickLookProvider.Instance.DetectAvailability())
1214
return await Task.FromResult<IPreviewPopupProvider>(QuickLookProvider.Instance);
1315
if (await SeerProProvider.Instance.DetectAvailability())

0 commit comments

Comments
 (0)