Files
FlClash/lib/common/protocol.dart
T

59 lines
1.2 KiB
Dart
Raw Normal View History

2024-04-30 23:38:49 +08:00
import 'dart:io';
import 'package:win32_registry/win32_registry.dart';
2026-05-27 15:16:51 +08:00
class ProtocolRegistrationPlan {
final String scheme;
final String executable;
const ProtocolRegistrationPlan({
required this.scheme,
required this.executable,
});
String get protocolKey => 'Software\\Classes\\$scheme';
String get commandKey => 'shell\\open\\command';
String get protocolValueName => 'URL Protocol';
String get protocolValue => '';
String get command => '"$executable" "%1"';
}
2024-04-30 23:38:49 +08:00
class Protocol {
static Protocol? _instance;
Protocol._internal();
factory Protocol() {
_instance ??= Protocol._internal();
return _instance!;
}
void register(String scheme) {
2026-05-27 15:16:51 +08:00
final plan = ProtocolRegistrationPlan(
scheme: scheme,
executable: Platform.resolvedExecutable,
2024-04-30 23:38:49 +08:00
);
2026-05-27 15:16:51 +08:00
final regKey = CURRENT_USER.create(plan.protocolKey);
try {
regKey.setValue(
plan.protocolValueName,
RegistryValue.string(plan.protocolValue),
);
final commandKey = regKey.create(plan.commandKey);
try {
commandKey.setValue('', RegistryValue.string(plan.command));
} finally {
commandKey.close();
}
} finally {
regKey.close();
}
2024-04-30 23:38:49 +08:00
}
}
2025-03-12 17:15:31 +08:00
final protocol = Protocol();