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.

macOS: ask for Accessibility at start, remind on the home page, start gestures as soon as it is given

KnifeLemon8a7dff565fe8
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.cs
index 8d290037..4e93f277 100644
--- a/src/Filee.App/App.axaml.cs
+++ b/src/Filee.App/App.axaml.cs
@@ -76,6 +76,12 @@ public partial class App : Application
};
triggers.Start();
log.LogInformation("Filee {Version} started", UpdateService.CurrentVersion);
+ // macOS: ask for Accessibility with the system's own alert when the user opened Filee (not at sign-in) and
+ // a drag gesture is on. The home page keeps a reminder until it is given.
+ if (OperatingSystem.IsMacOS() && triggers.NeedsPermission && !Program.Options.Background
+ && platform is Filee.Platform.MacOS.MacOSPlatformServices mac
+ && store.Settings.Triggers.Any(t => t.Enabled && t.Kind == TriggerKind.Drag))
+ mac.RequestAccessibilityPermission();
store.SettingsChanged += (_, _) => ApplySettings(store.Settings);
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index f6b30dfd..cb93018f 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -24,6 +24,7 @@
"home.drop_hint": "Or hold {0} while dragging files in Explorer. The donut toolbar opens at your cursor.",
"home.drop_hint_macos": "Or hold {0} while dragging files in Finder. The donut toolbar opens at your cursor.",
"home.drop_hint_linux": "Or hold {0} while dragging files in your file manager. The donut toolbar opens at your cursor.",
+ "home.accessibility_needed": "To open the donut by dragging with ⌥ Option, allow Filee under Accessibility. It works as soon as you switch it on.",
"home.recent": "Recent conversions",
"home.recent_empty": "Your converted files will show up here.",
"home.open_folder": "Open folder",
@@ -178,7 +179,7 @@
"triggers.title": "Shortcuts",
"triggers.description": "Choose how the donut toolbar opens. You can add as many gestures as you like.",
- "triggers.macos_permissions": "Allow Filee in System Settings > Privacy & Security > Accessibility, then retry gestures. Finder also asks for Automation permission when you first use a selection shortcut.",
+ "triggers.macos_permissions": "Allow Filee in System Settings > Privacy & Security > Accessibility; gestures start as soon as you switch it on. Finder also asks for Automation permission when you first use a selection shortcut.",
"triggers.linux_x11": "Drag gestures use X11. The first enabled keyboard shortcut is assigned to the Thunar Filee action when file manager integration is on. Close Thunar before changing it, then reopen Thunar. Hold gestures and global selection shortcuts in other file managers are unavailable; use their Filee menu action or the drop zone.",
"triggers.linux_wayland": "Cursor-following gestures are unavailable in this Wayland session. Use an X11 session for drag gestures, or convert through file manager actions and the drop zone. Thunar can use the first enabled keyboard shortcut after it restarts.",
"triggers.open_accessibility": "Open Accessibility settings",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 8e47a004..fdd406f9 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -24,6 +24,7 @@
"home.drop_hint": "또는 탐색기에서 {0} 키를 누른 채 파일을 드래그하면 커서 위치에 원형 툴바가 열려요.",
"home.drop_hint_macos": "또는 Finder에서 {0} 키를 누른 채 파일을 드래그하면 커서 위치에 원형 툴바가 열려요.",
"home.drop_hint_linux": "또는 파일 관리자에서 {0} 키를 누른 채 파일을 드래그하면 커서 위치에 원형 툴바가 열려요.",
+ "home.accessibility_needed": "⌥ Option 드래그로 원형 툴바를 열려면 손쉬운 사용에서 Filee를 허용해 주세요. 켜는 즉시 동작해요.",
"home.recent": "최근 변환",
"home.recent_empty": "변환한 파일이 여기에 표시됩니다.",
"home.open_folder": "폴더 열기",
@@ -178,7 +179,7 @@
"triggers.title": "단축키",
"triggers.description": "원형 툴바를 여는 방법을 정하세요. 제스처는 원하는 만큼 추가할 수 있어요.",
- "triggers.macos_permissions": "시스템 설정 > 개인정보 보호 및 보안 > 손쉬운 사용에서 Filee를 허용한 뒤 제스처를 다시 시도해 주세요. 선택 파일 단축키를 처음 사용하면 Finder 자동화 권한도 요청해요.",
+ "triggers.macos_permissions": "시스템 설정 > 개인정보 보호 및 보안 > 손쉬운 사용에서 Filee를 허용하면 바로 제스처를 쓸 수 있어요. 선택 파일 단축키를 처음 사용하면 Finder 자동화 권한도 요청해요.",
"triggers.linux_x11": "드래그 제스처는 X11에서 작동해요. 파일 관리자 연동을 켜면 첫 번째 활성 키보드 단축키를 Thunar의 Filee 동작에 연결해요. 변경할 때는 Thunar를 닫고 변경 후 다시 열어 주세요. 길게 누르기와 다른 파일 관리자의 전역 선택 단축키는 사용할 수 없어요. Filee 메뉴나 드롭 영역을 사용해 주세요.",
"triggers.linux_wayland": "이 Wayland 세션에서는 커서를 따라가는 제스처를 사용할 수 없어요. 드래그 제스처는 X11 세션에서 사용하거나, 파일 관리자 메뉴와 드롭 영역으로 변환해 주세요. Thunar는 다시 시작한 뒤 첫 번째 활성 키보드 단축키를 사용할 수 있어요.",
"triggers.open_accessibility": "손쉬운 사용 설정 열기",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 96781436..73229bb1 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -24,6 +24,7 @@
"home.drop_hint": "或在资源管理器中按住 {0} 拖动文件,环形工具栏会在光标处打开。",
"home.drop_hint_macos": "或在访达中按住 {0} 拖动文件,环形工具栏会在光标处打开。",
"home.drop_hint_linux": "或在文件管理器中按住 {0} 拖动文件,环形工具栏会在光标处打开。",
+ "home.accessibility_needed": "要按住 ⌥ Option 拖动打开环形工具栏,请在“辅助功能”中允许 Filee。打开后立即生效。",
"home.recent": "最近的转换",
"home.recent_empty": "转换后的文件会显示在这里。",
"home.open_folder": "打开文件夹",
@@ -178,7 +179,7 @@
"triggers.title": "快捷操作",
"triggers.description": "选择打开环形工具栏的方式。可以添加任意多个手势。",
- "triggers.macos_permissions": "请在系统设置 > 隐私与安全性 > 辅助功能中允许 Filee,然后重试手势。首次使用选择文件的快捷键时,Finder 还会请求自动化权限。",
+ "triggers.macos_permissions": "请在系统设置 > 隐私与安全性 > 辅助功能中允许 Filee,打开后手势立即可用。首次使用选择文件的快捷键时,Finder 还会请求自动化权限。",
"triggers.linux_x11": "拖动手势需要 X11。启用文件管理器集成后,第一个已启用的键盘快捷键会分配给 Thunar 的 Filee 操作。修改前请关闭 Thunar,修改后重新打开。不支持长按手势及其他文件管理器的全局选择快捷键,请使用 Filee 菜单或拖放区域。",
"triggers.linux_wayland": "当前 Wayland 会话不支持跟随光标的手势。请使用 X11 会话进行拖动,或通过文件管理器操作和拖放区域转换。重启 Thunar 后可使用第一个已启用的键盘快捷键。",
"triggers.open_accessibility": "打开辅助功能设置",
diff --git a/src/Filee.App/Services/Triggers/TriggerService.cs b/src/Filee.App/Services/Triggers/TriggerService.cs
index 24eb0bf3..0f50b684 100644
--- a/src/Filee.App/Services/Triggers/TriggerService.cs
+++ b/src/Filee.App/Services/Triggers/TriggerService.cs
@@ -63,12 +63,26 @@ public sealed class TriggerService : IDisposable
StringComparer.OrdinalIgnoreCase);
}
+ /// <summary>macOS without Accessibility permission: gestures wait for it (and start by themselves once it is given).</summary>
+ public bool NeedsPermission { get; private set; }
+
+ private Timer? _permissionWatch;
+
public void Start()
{
if (_hook is not null)
return;
if (!_platform.SupportsGlobalPointerGestures)
+ {
+ if (OperatingSystem.IsMacOS())
+ WatchForPermission();
return;
+ }
+ if (NeedsPermission)
+ {
+ NeedsPermission = false;
+ NotifyStatus();
+ }
Error = null;
try
{
@@ -153,8 +167,33 @@ public sealed class TriggerService : IDisposable
return name.StartsWith("Vc", StringComparison.Ordinal) ? name[2..] : name;
}
+ /// <summary>
+ /// Checks every two seconds whether the user switched Filee on under Accessibility, then starts the gestures;
+ /// no restart needed.
+ /// </summary>
+ private void WatchForPermission()
+ {
+ if (!NeedsPermission)
+ {
+ NeedsPermission = true;
+ _log.LogInformation("Gestures wait for the Accessibility permission");
+ NotifyStatus();
+ }
+ _permissionWatch ??= new Timer(_ =>
+ {
+ if (!_platform.SupportsGlobalPointerGestures)
+ return;
+ _permissionWatch?.Dispose();
+ _permissionWatch = null;
+ _log.LogInformation("Accessibility permission granted");
+ Post(Start);
+ }, null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
+ }
+
public void Dispose()
{
+ _permissionWatch?.Dispose();
+ _permissionWatch = null;
_hook?.Dispose();
_hook = null;
}
diff --git a/src/Filee.App/ViewModels/Pages/HomePageViewModel.cs b/src/Filee.App/ViewModels/Pages/HomePageViewModel.cs
index 84e1e862..9384c8af 100644
--- a/src/Filee.App/ViewModels/Pages/HomePageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/HomePageViewModel.cs
@@ -47,12 +47,16 @@ public sealed partial class HomePageViewModel : ObservableObject, IDisposable
private readonly UserDataStore _store;
private readonly ILocalizer _loc;
private readonly IPlatformServices _platform;
+ private readonly Services.Triggers.TriggerService? _triggers;
- public HomePageViewModel(UserDataStore store, ILocalizer loc, IPlatformServices platform)
+ public HomePageViewModel(UserDataStore store, ILocalizer loc, IPlatformServices platform, Services.Triggers.TriggerService? triggers = null)
{
_store = store;
_loc = loc;
_platform = platform;
+ _triggers = triggers;
+ if (triggers is not null)
+ triggers.StatusChanged += OnTriggerStatusChanged;
var drag = store.Settings.Triggers.FirstOrDefault(t => t.Enabled && t.Kind == TriggerKind.Drag);
DropHint = loc.Format(OperatingSystem.IsMacOS() ? "home.drop_hint_macos" : OperatingSystem.IsLinux() ? "home.drop_hint_linux" : "home.drop_hint", drag is null ? "—" : GestureText.Modifiers(drag.Modifiers));
store.HistoryChanged += OnHistoryChanged;
@@ -61,7 +65,24 @@ public sealed partial class HomePageViewModel : ObservableObject, IDisposable
private void OnHistoryChanged(object? sender, EventArgs e) => Dispatcher.UIThread.Post(Reload);
- public void Dispose() => _store.HistoryChanged -= OnHistoryChanged;
+ public void Dispose()
+ {
+ _store.HistoryChanged -= OnHistoryChanged;
+ if (_triggers is not null)
+ _triggers.StatusChanged -= OnTriggerStatusChanged;
+ }
+
+ private void OnTriggerStatusChanged(object? sender, EventArgs e) => OnPropertyChanged(nameof(NeedsAccessibility));
+
+ /// <summary>macOS: gestures wait for the Accessibility permission (the reminder above the drop zone).</summary>
+ public bool NeedsAccessibility => _triggers?.NeedsPermission == true;
+
+ [RelayCommand]
+ private void OpenAccessibility()
+ {
+ if (OperatingSystem.IsMacOS() && _platform is Filee.Platform.MacOS.MacOSPlatformServices mac)
+ mac.OpenAccessibilitySettings();
+ }
public string DropHint { get; }
diff --git a/src/Filee.App/Views/Pages/HomePage.axaml b/src/Filee.App/Views/Pages/HomePage.axaml
index c80c4e82..c4d1acb7 100644
--- a/src/Filee.App/Views/Pages/HomePage.axaml
+++ b/src/Filee.App/Views/Pages/HomePage.axaml
@@ -22,6 +22,16 @@
<StackPanel Spacing="22">
<TextBlock Classes="h1" Text="{DynamicResource home.title}" />
+ <!-- macOS without Accessibility permission: the drag gesture can't work yet. Gone once it is given. -->
+ <Border IsVisible="{Binding NeedsAccessibility}" Background="{DynamicResource AccentFaintBrush}"
+ BorderBrush="{DynamicResource AccentSoftBrush}" BorderThickness="1" CornerRadius="{DynamicResource SoftRadius}" Padding="14,10">
+ <DockPanel>
+ <Button DockPanel.Dock="Right" VerticalAlignment="Center" Margin="12,0,0,0" Classes="accent"
+ Content="{DynamicResource triggers.open_accessibility}" Command="{Binding OpenAccessibilityCommand}" />
+ <TextBlock VerticalAlignment="Center" TextWrapping="Wrap" Text="{DynamicResource home.accessibility_needed}" />
+ </DockPanel>
+ </Border>
+
<!-- Drop zone: files dropped here open the donut toolbar at the cursor. -->
<Border x:Name="DropZone" DragDrop.AllowDrop="True" MinHeight="220"
Background="{DynamicResource AccentFaintBrush}" BorderBrush="{DynamicResource AccentSoftBrush}"
diff --git a/src/Filee.Platform.MacOS/MacOSPlatformServices.cs b/src/Filee.Platform.MacOS/MacOSPlatformServices.cs
index 9b5963ac..6ed44d31 100644
--- a/src/Filee.Platform.MacOS/MacOSPlatformServices.cs
+++ b/src/Filee.Platform.MacOS/MacOSPlatformServices.cs
@@ -17,6 +17,9 @@ public sealed class MacOSPlatformServices : IPlatformServices
public bool HasAccessibilityPermission => NativeMethods.AXIsProcessTrusted();
+ /// <summary>Asks for Accessibility with macOS's own alert (nothing happens when Filee already has it).</summary>
+ public bool RequestAccessibilityPermission() => NativeMethods.RequestAccessibility();
+
public bool SupportsGlobalPointerGestures => HasAccessibilityPermission;
public bool SupportsSelectionShortcut => true;
diff --git a/src/Filee.Platform.MacOS/NativeMethods.cs b/src/Filee.Platform.MacOS/NativeMethods.cs
index e5247b31..7e4b907a 100644
--- a/src/Filee.Platform.MacOS/NativeMethods.cs
+++ b/src/Filee.Platform.MacOS/NativeMethods.cs
@@ -107,6 +107,36 @@ internal static class NativeMethods
[return: MarshalAs(UnmanagedType.I1)]
internal static extern bool AXIsProcessTrusted();
+ /// <summary>
+ /// Whether Filee may watch input; when not, macOS shows its own alert (Open System Settings / Deny) and lists
+ /// Filee under Accessibility, switched off, so the user only has to switch it on.
+ /// </summary>
+ internal static bool RequestAccessibility()
+ {
+ var coreFoundation = NativeLibrary.Load(CoreFoundation);
+ var trueValue = Marshal.ReadIntPtr(NativeLibrary.GetExport(coreFoundation, "kCFBooleanTrue"));
+ var key = CFStringCreateWithCString(0, "AXTrustedCheckOptionPrompt", 0x08000100);
+ var options = CFDictionaryCreate(0, [key], [trueValue], 1,
+ NativeLibrary.GetExport(coreFoundation, "kCFTypeDictionaryKeyCallBacks"),
+ NativeLibrary.GetExport(coreFoundation, "kCFTypeDictionaryValueCallBacks"));
+ try
+ {
+ return AXIsProcessTrustedWithOptions(options);
+ }
+ finally
+ {
+ CFRelease(options);
+ CFRelease(key);
+ }
+ }
+
+ [DllImport(ApplicationServices)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ private static extern bool AXIsProcessTrustedWithOptions(nint options);
+
+ [DllImport(CoreFoundation)]
+ private static extern nint CFDictionaryCreate(nint allocator, nint[] keys, nint[] values, nint count, nint keyCallBacks, nint valueCallBacks);
+
[DllImport(CoreGraphics)]
private static extern nint CGWindowListCopyWindowInfo(uint option, uint relativeToWindow);