Skip to content

An open-source cross-platform alternative to AirDrop

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

Shlomo2823bee06236
diff --git a/app/macos/Runner/AppDelegate.swift b/app/macos/Runner/AppDelegate.swift
index 4bb41315..3237ca1e 100644
--- a/app/macos/Runner/AppDelegate.swift
+++ b/app/macos/Runner/AppDelegate.swift
@@ -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)
}
}
diff --git a/app/macos/Runner/Info.plist b/app/macos/Runner/Info.plist
index 21cc01eb..1477186c 100644
--- a/app/macos/Runner/Info.plist
+++ b/app/macos/Runner/Info.plist
@@ -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>