feat: use NSService instead of Apple Events for dock icon text drops (#2712)

enables Dock icon text-drop even when the app is not running
This commit is contained in:
Shlomo
2025-09-21 18:59:50 +03:00
committed by GitHub
parent b00e187b5b
commit 2823bee062
2 changed files with 7 additions and 18 deletions
+6 -17
View File
@@ -43,7 +43,7 @@ class AppDelegate: FlutterAppDelegate {
channel = FlutterMethodChannel(name: "main-delegate-channel", binaryMessenger: controller.engine.binaryMessenger)
channel?.setMethodCallHandler(handleFlutterCall)
self.setupDockIconTextDropEventListener()
NSApplication.shared.servicesProvider = self
let localsendBrandColor = NSColor(red: 0, green: 0.392, blue: 0.353, alpha: 0.8) // #00645a
DockProgress.style = .squircle(color: localsendBrandColor)
@@ -81,16 +81,6 @@ class AppDelegate: FlutterAppDelegate {
}
}
private func setupDockIconTextDropEventListener() {
let appleEventManager = NSAppleEventManager.shared()
appleEventManager.setEventHandler(
self,
andSelector: #selector(handleOpenContentsEvent(_:withReplyEvent:)),
forEventClass: AEEventClass(kCoreEventClass),
andEventID: AEEventID(kAEOpenContents)
)
}
private func setupStatusBarItem(i18n: [String: String]) {
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
@@ -277,11 +267,10 @@ class AppDelegate: FlutterAppDelegate {
}
}
// END: handle opened files
/// Handle **text** dropped onto the Dock icon
@objc func handleOpenContentsEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
if let string = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue {
Defaults[.pendingStrings].append(string)
}
/// Also handles text dropped on the Dock icon
@objc func handleSendTextService(_ pasteboard: NSPasteboard, userData: String, error: NSErrorPointer) {
guard let string = pasteboard.string(forType: .string) else { return }
Defaults[.pendingStrings].append(string)
}
}
+1 -1
View File
@@ -145,7 +145,7 @@
<string>Send to LocalSend</string>
</dict>
<key>NSMessage</key>
<string>handleTextDropEvent</string>
<string>handleSendTextService</string>
<key>NSPortName</key>
<string>LocalSend</string>
<key>NSSendTypes</key>