Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Drag gestures over a web browser open the donut with the default scope

KnifeLemon6eab65aa5495
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 20a2887f..8855c26b 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -52,6 +52,8 @@
## Files dragged from a web browser
A picture, a link to a file or a download dragged out of a browser opens the donut like a file from the file manager.
+A drag gesture over a browser (`WebBrowsers`, by process name) counts as over the file manager, so the default scope
+covers it; click and key gestures don't, as they read the file manager's selection.
`DraggedFiles.Read` asks `BrowserDrags` (App, reads Avalonia's drag data) first; `BrowserDrag` (Core, pure rules)
decides what in the drag is a file:
diff --git a/src/Filee.App/Services/Triggers/TriggerService.cs b/src/Filee.App/Services/Triggers/TriggerService.cs
index ecbd6182..7032470f 100644
--- a/src/Filee.App/Services/Triggers/TriggerService.cs
+++ b/src/Filee.App/Services/Triggers/TriggerService.cs
@@ -6,6 +6,7 @@ using System.Diagnostics;
using Avalonia.Threading;
using Filee.Core.Platform;
using Filee.Core.Settings;
+using Filee.Core.Web;
using Microsoft.Extensions.Logging;
using SharpHook;
using SharpHook.Data;
@@ -252,14 +253,16 @@ public sealed class TriggerService : IDisposable
_detector.MouseMove(_estX, _estY, Map(e.RawEvent.Mask), HeldButton(e.RawEvent.Mask));
}
- private bool InScope(TriggerGesture gesture, int x, int y)
+ internal bool InScope(TriggerGesture gesture, int x, int y)
{
var process = _platform.ProcessNameAt(x, y);
if (Trace)
_log.LogInformation("Trace: {Gesture} at {X},{Y} over {Process}", gesture.Kind, x, y, process ?? "(none)");
if (process is not null && (string.Equals(process, _ownProcess, StringComparison.OrdinalIgnoreCase) || _excluded.Contains(process)))
return false;
- return gesture.Scope == TriggerScope.Anywhere || _platform.IsFileManagerAt(x, y);
+ return gesture.Scope == TriggerScope.Anywhere || _platform.IsFileManagerAt(x, y)
+ // A picture or link dragged out of a web page opens the donut like a file.
+ || gesture.Kind == TriggerKind.Drag && WebBrowsers.IsBrowser(process);
}
private static void Post(Action action) => Dispatcher.UIThread.Post(action);
diff --git a/src/Filee.Core/Web/WebBrowsers.cs b/src/Filee.Core/Web/WebBrowsers.cs
new file mode 100644
index 00000000..48995a85
--- /dev/null
+++ b/src/Filee.Core/Web/WebBrowsers.cs
@@ -0,0 +1,28 @@
+// Web browsers by process name (Windows without ".exe", the Linux executable, the macOS app name). A drag gesture over
+// one opens the donut even when gestures are limited to the file manager: a picture or link dragged out of a page
+// reaches the donut like a file (see BrowserDrag). Click and key gestures stay off there: they read the file manager's
+// selection, which a browser doesn't have.
+
+namespace Filee.Core.Web;
+
+public static class WebBrowsers
+{
+ private static readonly HashSet<string> Processes = new(StringComparer.OrdinalIgnoreCase)
+ {
+ // Windows
+ "chrome", "msedge", "firefox", "brave", "opera", "vivaldi", "whale", "arc", "zen", "librewolf", "waterfox",
+ "floorp", "chromium", "yandex",
+ // Linux
+ "firefox-esr", "firefox-bin", "google-chrome", "chromium-browser", "microsoft-edge", "brave-browser",
+ "vivaldi-bin", "naver-whale",
+ // macOS
+ "Safari", "Google Chrome", "Microsoft Edge", "Brave Browser", "Naver Whale", "Chromium", "Zen Browser",
+ "Firefox Developer Edition", "Firefox Nightly", "Google Chrome Canary", "Microsoft Edge Dev", "Orion",
+ };
+
+ /// <summary>True for a web browser's process, by the name the platform reports.</summary>
+ public static bool IsBrowser(string? processName) =>
+ processName is not null && Processes.Contains(processName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)
+ ? processName[..^4]
+ : processName);
+}
diff --git a/tests/Filee.App.Tests/TriggerServiceLifecycleTests.cs b/tests/Filee.App.Tests/TriggerServiceLifecycleTests.cs
index 61e955a7..478759f5 100644
--- a/tests/Filee.App.Tests/TriggerServiceLifecycleTests.cs
+++ b/tests/Filee.App.Tests/TriggerServiceLifecycleTests.cs
@@ -166,6 +166,30 @@ public sealed class TriggerServiceLifecycleTests
}
/// <summary>Runs the work the hook posted to the UI thread for a moment, then reads the value.</summary>
+ [AvaloniaFact]
+ public void A_drag_over_a_web_browser_counts_as_over_the_file_manager()
+ {
+ var platform = new NullPlatformServicesForHooks { FileManager = false, Process = "msedge" };
+ using var service = new TriggerService(platform, NullLogger<TriggerService>.Instance);
+ var drag = new TriggerGesture { Kind = TriggerKind.Drag, Scope = TriggerScope.FileManager };
+ Assert.True(service.InScope(drag, 10, 10));
+ // Click and key gestures read the file manager's selection, which a browser doesn't have.
+ Assert.False(service.InScope(new TriggerGesture { Kind = TriggerKind.Hold, Scope = TriggerScope.FileManager }, 10, 10));
+ Assert.False(service.InScope(new TriggerGesture { Kind = TriggerKind.KeyChord, Scope = TriggerScope.FileManager }, 10, 10));
+ foreach (var browser in new[] { "chrome", "firefox", "Safari", "Google Chrome", "whale.exe" })
+ {
+ platform.Process = browser;
+ Assert.True(service.InScope(drag, 10, 10), browser);
+ }
+ platform.Process = "notepad";
+ Assert.False(service.InScope(drag, 10, 10));
+ // An excluded browser stays excluded.
+ platform.Process = "msedge";
+ var settings = new AppSettings { ExcludedProcesses = ["msedge.exe"] };
+ service.Apply(settings);
+ Assert.False(service.InScope(drag, 10, 10));
+ }
+
internal static T Settle<T>(Func<T> read)
{
for (var i = 0; i < 20; i++)
@@ -287,8 +311,10 @@ public sealed class TriggerServiceLifecycleTests
internal sealed class NullPlatformServicesForHooks : IPlatformServices
{
public bool PressCarriesPosition { get; init; } = true;
- public bool IsFileManagerAt(int x, int y) => true;
- public string? ProcessNameAt(int x, int y) => "explorer";
+ public bool FileManager { get; set; } = true;
+ public string? Process { get; set; } = "explorer";
+ public bool IsFileManagerAt(int x, int y) => FileManager;
+ public string? ProcessNameAt(int x, int y) => Process;
public IReadOnlyList<string> GetFileManagerSelection() => [];
public int SystemDragThreshold => 4;
public bool PrefersReducedMotion => false;