-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDelegate.swift
30 lines (26 loc) · 1.23 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Cocoa
import FlutterMacOS
import protocol_handler
import app_links
import macos_window_utils
@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
NSApp.hide(self)
return true
}
override func applicationWillFinishLaunching(_ notification: Notification) {
super.applicationWillFinishLaunching(notification)
NSAppleEventManager.shared().setEventHandler(self, andSelector:#selector(handleURLEvent(_:with:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
@objc public func handleURLEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
guard let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue else { return }
let window = self.mainFlutterWindow?.contentViewController as! MacOSWindowUtilsViewController
let messenger = window.flutterViewController.engine.binaryMessenger
let channel = FlutterMethodChannel(name: "protocol_handler", binaryMessenger: messenger)
let args: NSDictionary = [
"url": urlString,
]
channel.invokeMethod("onProtocolUrlReceived", arguments: args)
}
}