-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathprotocol_handler_windows.dart
More file actions
36 lines (30 loc) · 1.15 KB
/
protocol_handler_windows.dart
File metadata and controls
36 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'dart:io';
import 'package:protocol_handler_platform_interface/protocol_handler_platform_interface.dart';
import 'package:win32_registry/win32_registry.dart';
class ProtocolHandlerWindows extends MethodChannelProtocolHandler {
/// The [ProtocolHandlerWindows] constructor.
ProtocolHandlerWindows() : super();
/// Registers this class as the default instance of [ProtocolHandlerWindows].
static void registerWith() {
ProtocolHandlerPlatform.instance = ProtocolHandlerWindows();
}
@override
Future<void> register(String scheme) async {
String appPath = Platform.resolvedExecutable;
String protocolRegKey = 'Software\\Classes\\$scheme';
RegistryValue protocolRegValue = const RegistryValue(
'URL Protocol',
RegistryValueType.string,
'',
);
String protocolCmdRegKey = 'shell\\open\\command';
RegistryValue protocolCmdRegValue = RegistryValue(
'',
RegistryValueType.string,
'$appPath "%1"',
);
final regKey = Registry.currentUser.createKey(protocolRegKey);
regKey.createValue(protocolRegValue);
regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue);
}
}