Skip to content

Commit 8b359f6

Browse files
committed
Remove protocol_handler dependency
1 parent 566f39a commit 8b359f6

15 files changed

+182
-108
lines changed

example/lib/main.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ import 'package:uni_links_desktop/uni_links_desktop.dart';
99

1010
bool _initialUriIsHandled = false;
1111

12-
void main() {
13-
if (Platform.isMacOS || Platform.isWindows) {
14-
enableUniLinksDesktop();
15-
if (Platform.isWindows) {
16-
registerProtocol('unilinks');
17-
}
12+
Future<void> main() async {
13+
WidgetsFlutterBinding.ensureInitialized();
14+
15+
if (Platform.isWindows) {
16+
registerProtocol('unilinks');
1817
}
19-
runApp(MaterialApp(home: MyApp()));
18+
19+
runApp(const MaterialApp(
20+
home: MyApp(),
21+
));
2022
}
2123

2224
class MyApp extends StatefulWidget {
25+
const MyApp({Key? key}) : super(key: key);
26+
2327
@override
2428
_MyAppState createState() => _MyAppState();
2529
}

example/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import FlutterMacOS
66
import Foundation
77

8-
import protocol_handler
8+
import uni_links_desktop
99

1010
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
11-
ProtocolHandlerPlugin.register(with: registry.registrar(forPlugin: "ProtocolHandlerPlugin"))
11+
UniLinksDesktopPlugin.register(with: registry.registrar(forPlugin: "UniLinksDesktopPlugin"))
1212
}

example/macos/Podfile.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
PODS:
22
- FlutterMacOS (1.0.0)
3-
- protocol_handler (0.0.1):
4-
- FlutterMacOS
53
- uni_links_desktop (0.0.1):
64
- FlutterMacOS
75

86
DEPENDENCIES:
97
- FlutterMacOS (from `Flutter/ephemeral`)
10-
- protocol_handler (from `Flutter/ephemeral/.symlinks/plugins/protocol_handler/macos`)
118
- uni_links_desktop (from `Flutter/ephemeral/.symlinks/plugins/uni_links_desktop/macos`)
129

1310
EXTERNAL SOURCES:
1411
FlutterMacOS:
1512
:path: Flutter/ephemeral
16-
protocol_handler:
17-
:path: Flutter/ephemeral/.symlinks/plugins/protocol_handler/macos
1813
uni_links_desktop:
1914
:path: Flutter/ephemeral/.symlinks/plugins/uni_links_desktop/macos
2015

2116
SPEC CHECKSUMS:
2217
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
23-
protocol_handler: 587e1caf6c0b92ce351ab14081968dae49cb8cc6
2418
uni_links_desktop: 45900fb319df48fcdea2df0756e9c2626696b026
2519

2620
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
2721

28-
COCOAPODS: 1.11.2
22+
COCOAPODS: 1.11.3

example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
33CC10EB2044A3C60003C045 /* Resources */,
185185
33CC110E2044A8840003C045 /* Bundle Framework */,
186186
3399D490228B24CF009A79C7 /* ShellScript */,
187-
9327C696DA82EBFDE0EA972C /* [CP] Embed Pods Frameworks */,
187+
AA95A035C75B05C1C0C54340 /* [CP] Embed Pods Frameworks */,
188188
);
189189
buildRules = (
190190
);
@@ -291,7 +291,7 @@
291291
shellPath = /bin/sh;
292292
shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire";
293293
};
294-
9327C696DA82EBFDE0EA972C /* [CP] Embed Pods Frameworks */ = {
294+
AA95A035C75B05C1C0C54340 /* [CP] Embed Pods Frameworks */ = {
295295
isa = PBXShellScriptBuildPhase;
296296
buildActionMask = 2147483647;
297297
files = (

example/pubspec.lock

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ packages:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0"
45+
version: "1.16.0"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
4949
name: cupertino_icons
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.0.4"
52+
version: "1.0.5"
5353
fake_async:
5454
dependency: transitive
5555
description:
5656
name: fake_async
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "1.2.0"
59+
version: "1.3.0"
6060
ffi:
6161
dependency: transitive
6262
description:
6363
name: ffi
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "1.1.2"
66+
version: "2.0.1"
6767
flutter:
6868
dependency: "direct main"
6969
description: flutter
@@ -92,7 +92,7 @@ packages:
9292
name: js
9393
url: "https://pub.dartlang.org"
9494
source: hosted
95-
version: "0.6.3"
95+
version: "0.6.4"
9696
lints:
9797
dependency: transitive
9898
description:
@@ -113,7 +113,7 @@ packages:
113113
name: material_color_utilities
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "0.1.3"
116+
version: "0.1.4"
117117
meta:
118118
dependency: transitive
119119
description:
@@ -127,21 +127,14 @@ packages:
127127
name: path
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "1.8.0"
130+
version: "1.8.1"
131131
plugin_platform_interface:
132132
dependency: transitive
133133
description:
134134
name: plugin_platform_interface
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137137
version: "2.1.2"
138-
protocol_handler:
139-
dependency: transitive
140-
description:
141-
name: protocol_handler
142-
url: "https://pub.dartlang.org"
143-
source: hosted
144-
version: "0.1.2"
145138
sky_engine:
146139
dependency: transitive
147140
description: flutter
@@ -153,7 +146,7 @@ packages:
153146
name: source_span
154147
url: "https://pub.dartlang.org"
155148
source: hosted
156-
version: "1.8.1"
149+
version: "1.8.2"
157150
stack_trace:
158151
dependency: transitive
159152
description:
@@ -188,14 +181,7 @@ packages:
188181
name: test_api
189182
url: "https://pub.dartlang.org"
190183
source: hosted
191-
version: "0.4.8"
192-
typed_data:
193-
dependency: transitive
194-
description:
195-
name: typed_data
196-
url: "https://pub.dartlang.org"
197-
source: hosted
198-
version: "1.3.0"
184+
version: "0.4.9"
199185
uni_links:
200186
dependency: "direct main"
201187
description:
@@ -230,21 +216,21 @@ packages:
230216
name: vector_math
231217
url: "https://pub.dartlang.org"
232218
source: hosted
233-
version: "2.1.1"
219+
version: "2.1.2"
234220
win32:
235221
dependency: transitive
236222
description:
237223
name: win32
238224
url: "https://pub.dartlang.org"
239225
source: hosted
240-
version: "2.4.2"
226+
version: "2.7.0"
241227
win32_registry:
242228
dependency: transitive
243229
description:
244230
name: win32_registry
245231
url: "https://pub.dartlang.org"
246232
source: hosted
247-
version: "0.1.2"
233+
version: "1.0.2"
248234
sdks:
249-
dart: ">=2.16.1 <3.0.0"
250-
flutter: ">=2.8.0"
235+
dart: ">=2.17.0 <3.0.0"
236+
flutter: ">=2.5.0"

example/windows/flutter/generated_plugin_registrant.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
#include "generated_plugin_registrant.h"
88

9-
#include <protocol_handler/protocol_handler_plugin.h>
9+
#include <uni_links_desktop/uni_links_desktop_plugin.h>
1010

1111
void RegisterPlugins(flutter::PluginRegistry* registry) {
12-
ProtocolHandlerPluginRegisterWithRegistrar(
13-
registry->GetRegistrarForPlugin("ProtocolHandlerPlugin"));
12+
UniLinksDesktopPluginRegisterWithRegistrar(
13+
registry->GetRegistrarForPlugin("UniLinksDesktopPlugin"));
1414
}

example/windows/flutter/generated_plugins.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6-
protocol_handler
6+
uni_links_desktop
7+
)
8+
9+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
710
)
811

912
set(PLUGIN_BUNDLED_LIBRARIES)
@@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
1417
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
1518
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
1619
endforeach(plugin)
20+
21+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
23+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24+
endforeach(ffi_plugin)

lib/src/protocol_registrar.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:io';
2+
3+
import 'protocol_registrar_impl_macos.dart';
4+
import 'protocol_registrar_impl_windows.dart';
5+
6+
class ProtocolRegistrar {
7+
/// The shared instance of [ProtocolRegistrar].
8+
static ProtocolRegistrar get instance {
9+
if (Platform.isMacOS) return ProtocolRegistrarImplMacOS.instance;
10+
if (Platform.isWindows) return ProtocolRegistrarImplWindows.instance;
11+
return ProtocolRegistrar();
12+
}
13+
14+
Future<void> register(String scheme) async {
15+
throw UnimplementedError();
16+
}
17+
}
18+
19+
final protocolRegistrar = ProtocolRegistrar.instance;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'protocol_registrar.dart';
2+
3+
class ProtocolRegistrarImplMacOS extends ProtocolRegistrar {
4+
ProtocolRegistrarImplMacOS._();
5+
6+
/// The shared instance of [ProtocolRegistrarImplMacOS].
7+
static final ProtocolRegistrarImplMacOS instance =
8+
ProtocolRegistrarImplMacOS._();
9+
10+
@override
11+
Future<void> register(String protocol) async {
12+
// Skip
13+
}
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'dart:io';
2+
3+
import 'package:win32_registry/win32_registry.dart';
4+
5+
import 'protocol_registrar.dart';
6+
7+
class ProtocolRegistrarImplWindows extends ProtocolRegistrar {
8+
ProtocolRegistrarImplWindows._();
9+
10+
/// The shared instance of [ProtocolRegistrarImplWindows].
11+
static final ProtocolRegistrarImplWindows instance =
12+
ProtocolRegistrarImplWindows._();
13+
14+
@override
15+
Future<void> register(String scheme) async {
16+
String appPath = Platform.resolvedExecutable;
17+
18+
String protocolRegKey = 'Software\\Classes\\$scheme';
19+
RegistryValue protocolRegValue = const RegistryValue(
20+
'URL Protocol',
21+
RegistryValueType.string,
22+
'',
23+
);
24+
String protocolCmdRegKey = 'shell\\open\\command';
25+
RegistryValue protocolCmdRegValue = RegistryValue(
26+
'',
27+
RegistryValueType.string,
28+
'$appPath "%1"',
29+
);
30+
31+
final regKey = Registry.currentUser.createKey(protocolRegKey);
32+
regKey.createValue(protocolRegValue);
33+
regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue);
34+
}
35+
}

0 commit comments

Comments
 (0)