1
1
import Cocoa
2
2
import FlutterMacOS
3
3
4
- public class ProtocolHandlerPlugin : NSObject , FlutterPlugin {
4
+ public class ProtocolHandlerPlugin : NSObject , FlutterPlugin , FlutterAppLifecycleDelegate {
5
5
private static var _instance : ProtocolHandlerPlugin ?
6
6
private var channel : FlutterMethodChannel !
7
7
private var _initialUrl : String ?
@@ -12,18 +12,22 @@ public class ProtocolHandlerPlugin: NSObject, FlutterPlugin {
12
12
}
13
13
}
14
14
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 ) {
21
16
let channel = FlutterMethodChannel ( name: " protocol_handler " , binaryMessenger: registrar. messenger)
22
17
let instance = ProtocolHandlerPlugin ( )
23
18
_instance = instance
24
19
instance. channel = channel
25
20
registrar. addMethodCallDelegate ( instance, channel: channel)
21
+ registrar. addApplicationDelegate ( instance)
26
22
}
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
+ }
27
31
28
32
@objc
29
33
public func handleURLEvent( _ event: NSAppleEventDescriptor , with replyEvent: NSAppleEventDescriptor ) {
0 commit comments