11import Cocoa
22import FlutterMacOS
33
4- public class ProtocolHandlerPlugin : NSObject , FlutterPlugin {
4+ public class ProtocolHandlerPlugin : NSObject , FlutterPlugin , FlutterAppLifecycleDelegate {
55 private static var _instance : ProtocolHandlerPlugin ?
66 private var channel : FlutterMethodChannel !
77 private var _initialUrl : String ?
@@ -12,18 +12,22 @@ public class ProtocolHandlerPlugin: NSObject, FlutterPlugin {
1212 }
1313 }
1414
15- override init ( ) {
16- super. init ( ) ;
17- NSAppleEventManager . shared ( ) . setEventHandler ( self , andSelector: #selector( handleURLEvent ( _: with: ) ) , forEventClass: AEEventClass ( kInternetEventClass) , andEventID: AEEventID ( kAEGetURL) )
18- }
19-
20- public static func register( with registrar: FlutterPluginRegistrar ) {
15+ public static func register( with registrar: FlutterPluginRegistrar ) {
2116 let channel = FlutterMethodChannel ( name: " protocol_handler " , binaryMessenger: registrar. messenger)
2217 let instance = ProtocolHandlerPlugin ( )
2318 _instance = instance
2419 instance. channel = channel
2520 registrar. addMethodCallDelegate ( instance, channel: channel)
21+ registrar. addApplicationDelegate ( instance)
2622 }
23+ public func handleWillFinishLaunching( _ notification: Notification ) {
24+ NSAppleEventManager . shared ( ) . setEventHandler (
25+ self ,
26+ andSelector: #selector( handleURLEvent ( _: with: ) ) ,
27+ forEventClass: AEEventClass ( kInternetEventClass) ,
28+ andEventID: AEEventID ( kAEGetURL)
29+ )
30+ }
2731
2832 @objc
2933 public func handleURLEvent( _ event: NSAppleEventDescriptor , with replyEvent: NSAppleEventDescriptor ) {
0 commit comments