Skip to content

Commit 0a3ffbf

Browse files
authored
Fix: macOS support broken since Flutter 3.16.0 (#16)
* Use NSApplicationDelegate's openURLs method via FlutterAppLifecycleDelegate to receive and consume URL events instead of NSAppleEventManager * Bump version number to 0.1.7 * Add changelog for 0.1.7 * Update README for 0.1.7 and fix wrong link to uni_links
1 parent 1b72b02 commit 0a3ffbf

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
## 0.1.7
2+
3+
- [macos] Fix implementation to work with Flutter 3.16.0 #15
4+
15
## 0.1.6
26

3-
* Make sure the web project build
7+
- Make sure the web project build
48

59
## 0.1.5
610

7-
* [windows] Add quotes to executable path #8
11+
- [windows] Add quotes to executable path #8
812

913
## 0.1.4
1014

11-
* [windows] fix crash: win event channel #5
15+
- [windows] fix crash: win event channel #5
1216

1317
## 0.1.3
1418

15-
* Remove protocol_handler dependency
19+
- Remove protocol_handler dependency
1620

1721
## 0.1.0
1822

19-
* First release.
23+
- First release.

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
[pub-image]: https://img.shields.io/pub/v/uni_links_desktop.svg
66
[pub-url]: https://pub.dev/packages/uni_links_desktop
7-
87
[discord-image]: https://img.shields.io/discord/884679008049037342.svg
98
[discord-url]: https://discord.gg/zPa6EZ2jqb
109

11-
A desktop (supports macOS and Windows) implementation of [uni_links](https://github.com/leanflutter/uni_links_desktop) plugin.
10+
A desktop (supports macOS and Windows) implementation of [uni_links](https://pub.dev/packages/uni_links) plugin.
1211

1312
---
1413

@@ -20,8 +19,8 @@ A desktop (supports macOS and Windows) implementation of [uni_links](https://git
2019
- [Quick Start](#quick-start)
2120
- [Installation](#installation)
2221
- [Usage](#usage)
23-
- [macOS](#macos)
24-
- [Windows](#windows)
22+
- [macOS](#macos)
23+
- [Windows](#windows)
2524
- [Who's using it?](#whos-using-it)
2625
- [License](#license)
2726

@@ -31,7 +30,7 @@ A desktop (supports macOS and Windows) implementation of [uni_links](https://git
3130

3231
| Linux | macOS | Windows |
3332
| :---: | :---: | :-----: |
34-
| | ✔️ | ✔️ |
33+
|| ✔️ | ✔️ |
3534

3635
## Quick Start
3736

@@ -41,7 +40,7 @@ Add this to your package's pubspec.yaml file:
4140

4241
```yaml
4342
dependencies:
44-
uni_links_desktop: ^0.1.6
43+
uni_links_desktop: ^0.1.7
4544
```
4645
4746
Or

macos/Classes/UniLinksDesktopPlugin.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import FlutterMacOS
55
let kMessagesChannel = "uni_links/messages"
66
let kEventsChannel = "uni_links/events"
77

8-
public class UniLinksDesktopPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
8+
public class UniLinksDesktopPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, FlutterAppLifecycleDelegate {
99
private static var _instance: UniLinksDesktopPlugin?
1010

1111
private var _eventSink: FlutterEventSink?;
@@ -17,11 +17,6 @@ public class UniLinksDesktopPlugin: NSObject, FlutterPlugin, FlutterStreamHandle
1717
}
1818
}
1919

20-
override init(){
21-
super.init();
22-
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleURLEvent(_:with:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
23-
}
24-
2520
public static func register(with registrar: FlutterPluginRegistrar) {
2621
let instance = UniLinksDesktopPlugin()
2722

@@ -31,18 +26,24 @@ public class UniLinksDesktopPlugin: NSObject, FlutterPlugin, FlutterStreamHandle
3126
let chargingChannel = FlutterEventChannel(name: kEventsChannel, binaryMessenger: registrar.messenger);
3227
chargingChannel.setStreamHandler(instance);
3328

29+
registrar.addApplicationDelegate(instance);
30+
3431
_instance = instance
3532
}
3633

37-
@objc
38-
public func handleURLEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
39-
guard let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue else { return }
40-
if (_initialUrl == nil) {
41-
_initialUrl = urlString
42-
}
43-
if (_eventSink != nil) {
44-
_eventSink!(urlString)
34+
public func handleOpen(_ urls: [URL]) -> Bool {
35+
for url in urls {
36+
let urlString = url.absoluteString;
37+
if (_initialUrl == nil) {
38+
_initialUrl = urlString
39+
}
40+
if (_eventSink != nil) {
41+
_eventSink!(urlString)
42+
}
4543
}
44+
45+
// mark all urls as consumed
46+
return true;
4647
}
4748

4849
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: uni_links_desktop
22
description: A desktop (supports macOS and Windows) implementation of uni_links plugin.
3-
version: 0.1.6
3+
version: 0.1.7
44
homepage: https://github.com/leanflutter/uni_links_desktop
55

66
platforms:
@@ -9,7 +9,7 @@ platforms:
99

1010
environment:
1111
sdk: ">=2.12.0 <3.0.0"
12-
flutter: ">=2.5.0"
12+
flutter: ">=3.16.0"
1313

1414
dependencies:
1515
flutter:

0 commit comments

Comments
 (0)