Skip to content

Expose ProtocolHandlerPlugin so it's possible to call 'handleEventURL' for multiple plugins #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions macos/Classes/ProtocolHandlerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import Cocoa
import FlutterMacOS

public class ProtocolHandlerPlugin: NSObject, FlutterPlugin {
private static var _instance: ProtocolHandlerPlugin?
private var channel: FlutterMethodChannel!

private var _initialUrl: String?

public static var instance: ProtocolHandlerPlugin {
get {
return _instance!
}
}

override init(){
super.init();
Expand All @@ -14,12 +20,13 @@ public class ProtocolHandlerPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "protocol_handler", binaryMessenger: registrar.messenger)
let instance = ProtocolHandlerPlugin()
_instance = instance
instance.channel = channel
registrar.addMethodCallDelegate(instance, channel: channel)
}

@objc
private func handleURLEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
public func handleURLEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
guard let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue else { return }
if (_initialUrl == nil) {
_initialUrl = urlString
Expand Down