Skip to content

Commit f779cb9

Browse files
authored
fix: macos 3.16 plugin register issue (#13)
1 parent b5b1576 commit f779cb9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

macos/Classes/ProtocolHandlerPlugin.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Cocoa
22
import 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

Comments
 (0)