Initial commit

This commit is contained in:
wgh19
2024-05-13 09:36:23 +08:00
commit b095643cbc
160 changed files with 9956 additions and 0 deletions

41
lib/utils/app_links.dart Normal file
View File

@@ -0,0 +1,41 @@
import 'dart:io';
import 'package:app_links/app_links.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/log.dart';
import 'package:win32_registry/win32_registry.dart';
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);
}
bool Function(Uri uri)? onLink;
void handleLinks() async {
if (App.isWindows) {
await _register("pixiv");
}
AppLinks().uriLinkStream.listen((uri) {
Log.info("App Link", uri.toString());
if (onLink?.call(uri) == true) {
return;
}
});
}