@hasna/recordings 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env swift
2
+ // Test: NSEvent.addGlobalMonitorForEvents — does it see fn key?
3
+ import Cocoa
4
+
5
+ print("Testing NSEvent global monitor for 15 seconds...")
6
+ print("Press fn, Option, any key. Ctrl+C to quit.\n")
7
+
8
+ let app = NSApplication.shared
9
+ app.setActivationPolicy(.accessory)
10
+
11
+ // Monitor flagsChanged (modifier keys including fn)
12
+ NSEvent.addGlobalMonitorForEvents(matching: [.flagsChanged, .keyDown, .keyUp]) { event in
13
+ if event.type == .flagsChanged {
14
+ let fn = event.modifierFlags.contains(.function) ? " [fn]" : ""
15
+ let cmd = event.modifierFlags.contains(.command) ? " [cmd]" : ""
16
+ let opt = event.modifierFlags.contains(.option) ? " [opt]" : ""
17
+ let ctrl = event.modifierFlags.contains(.control) ? " [ctrl]" : ""
18
+ print("flagsChanged keyCode=\(event.keyCode)\(fn)\(cmd)\(opt)\(ctrl)")
19
+ } else if event.type == .keyDown {
20
+ print("keyDown keyCode=\(event.keyCode) chars=\(event.characters ?? "")")
21
+ } else if event.type == .keyUp {
22
+ print("keyUp keyCode=\(event.keyCode)")
23
+ }
24
+ }
25
+
26
+ print("✅ Global monitor registered\n")
27
+
28
+ DispatchQueue.main.asyncAfter(deadline: .now() + 15) {
29
+ print("\nDone.")
30
+ exit(0)
31
+ }
32
+
33
+ app.run()
@@ -60,11 +60,47 @@ class AppDelegate: NSObject, NSApplicationDelegate {
60
60
 
61
61
  // ── Global Hotkey ───────────────────────────────────────────────────────
62
62
 
63
+ /// Check if Accessibility permission is granted. If not, show a dialog and open System Settings.
64
+ func checkAccessibilityPermission() -> Bool {
65
+ // First check without prompting
66
+ let trusted = AXIsProcessTrustedWithOptions(
67
+ [kAXTrustedCheckOptionPrompt.takeUnretainedValue(): false] as CFDictionary
68
+ )
69
+ if trusted { return true }
70
+
71
+ // Not trusted — show dialog explaining why we need it
72
+ let alert = NSAlert()
73
+ alert.messageText = "Accessibility Permission Required"
74
+ alert.informativeText = "RecordingsHelper needs Accessibility access to detect the global hotkey (hold Space to record).\n\nClick 'Open Settings' to grant permission, then restart the app."
75
+ alert.alertStyle = .warning
76
+ alert.addButton(withTitle: "Open Settings")
77
+ alert.addButton(withTitle: "Quit")
78
+
79
+ let response = alert.runModal()
80
+ if response == .alertFirstButtonReturn {
81
+ // Prompt the system dialog AND open System Settings > Accessibility
82
+ AXIsProcessTrustedWithOptions(
83
+ [kAXTrustedCheckOptionPrompt.takeUnretainedValue(): true] as CFDictionary
84
+ )
85
+ if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility") {
86
+ NSWorkspace.shared.open(url)
87
+ }
88
+ } else {
89
+ NSApplication.shared.terminate(nil)
90
+ }
91
+ return false
92
+ }
93
+
63
94
  func registerHotkey() {
64
95
  // Hold Space for 1+ second to start recording, release to stop.
65
96
  // Uses CGEventTap to monitor all keyboard events globally.
66
97
  // Normal space presses (< 1 second) pass through untouched.
67
98
 
99
+ // Check Accessibility permission BEFORE attempting event tap
100
+ if !checkAccessibilityPermission() {
101
+ return
102
+ }
103
+
68
104
  let eventMask: CGEventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue) | (1 << CGEventType.flagsChanged.rawValue)
69
105
 
70
106
  guard let tap = CGEvent.tapCreate(