mirror of
https://github.com/localsend/localsend.git
synced 2026-06-23 04:10:07 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user