diff --git a/packages/protocol_handler_windows/lib/protocol_handler_windows.dart b/packages/protocol_handler_windows/lib/protocol_handler_windows.dart index a1c6c06..c3b4d34 100644 --- a/packages/protocol_handler_windows/lib/protocol_handler_windows.dart +++ b/packages/protocol_handler_windows/lib/protocol_handler_windows.dart @@ -1,3 +1,3 @@ library protocol_handler_windows; -export 'src/protocol_handler_windows.dart'; +export 'src/protocol_handler_helper.dart'; diff --git a/packages/protocol_handler_windows/lib/src/protocol_handler_helper.dart b/packages/protocol_handler_windows/lib/src/protocol_handler_helper.dart new file mode 100644 index 0000000..baa6425 --- /dev/null +++ b/packages/protocol_handler_windows/lib/src/protocol_handler_helper.dart @@ -0,0 +1,3 @@ +export 'protocol_handler_helper.dart' + if (dart.library.ffi) 'protocol_handler_helpter_ffi.dart' + if (dart.library.html) 'protocol_handler_helper_web.dart'; diff --git a/packages/protocol_handler_windows/lib/src/protocol_handler_helper_web.dart b/packages/protocol_handler_windows/lib/src/protocol_handler_helper_web.dart new file mode 100644 index 0000000..3f34bde --- /dev/null +++ b/packages/protocol_handler_windows/lib/src/protocol_handler_helper_web.dart @@ -0,0 +1,14 @@ +import 'package:protocol_handler_platform_interface/protocol_handler_platform_interface.dart'; + +class ProtocolHandlerWindows extends MethodChannelProtocolHandler { + /// The [ProtocolHandlerWindows] constructor. + ProtocolHandlerWindows() : super(); + + static void registerWith() { + ProtocolHandlerPlatform.instance = ProtocolHandlerWindows(); + } + + Future register(String scheme, {String? friendlyAppName}) async { + // Web implementation does nothing. + } +} diff --git a/packages/protocol_handler_windows/lib/src/protocol_handler_windows.dart b/packages/protocol_handler_windows/lib/src/protocol_handler_helpter_ffi.dart similarity index 65% rename from packages/protocol_handler_windows/lib/src/protocol_handler_windows.dart rename to packages/protocol_handler_windows/lib/src/protocol_handler_helpter_ffi.dart index 609831c..2951388 100644 --- a/packages/protocol_handler_windows/lib/src/protocol_handler_windows.dart +++ b/packages/protocol_handler_windows/lib/src/protocol_handler_helpter_ffi.dart @@ -13,24 +13,31 @@ class ProtocolHandlerWindows extends MethodChannelProtocolHandler { } @override - Future register(String scheme) async { + Future register(String scheme, {String? friendlyAppName}) async { String appPath = Platform.resolvedExecutable; String protocolRegKey = 'Software\\Classes\\$scheme'; - RegistryValue protocolRegValue = const RegistryValue( + RegistryValue protocolRegValue = const RegistryValue.string( 'URL Protocol', - RegistryValueType.string, '', ); String protocolCmdRegKey = 'shell\\open\\command'; - RegistryValue protocolCmdRegValue = RegistryValue( + RegistryValue protocolCmdRegValue = RegistryValue.string( '', - RegistryValueType.string, '$appPath "%1"', ); final regKey = Registry.currentUser.createKey(protocolRegKey); regKey.createValue(protocolRegValue); regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue); + + if (friendlyAppName != null) { + String applicationRegKey = 'Application'; + RegistryValue friendlyAppNameRegValue = RegistryValue.string( + 'ApplicationName', + friendlyAppName, + ); + regKey.createKey(applicationRegKey).createValue(friendlyAppNameRegValue); + } } } diff --git a/packages/protocol_handler_windows/pubspec.yaml b/packages/protocol_handler_windows/pubspec.yaml index 4d1408f..db1bfc3 100644 --- a/packages/protocol_handler_windows/pubspec.yaml +++ b/packages/protocol_handler_windows/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter protocol_handler_platform_interface: ^0.2.0 - win32_registry: ^1.0.2 + win32_registry: ^2.1.0 dev_dependencies: flutter_test: