@@ -11,6 +11,7 @@ import 'package:go_router/go_router.dart';
11
11
import 'package:logger/logger.dart' ;
12
12
import 'package:permission_handler/permission_handler.dart' ;
13
13
import 'package:renderers/renderers.dart' ;
14
+ import 'package:win32_registry/win32_registry.dart' ;
14
15
15
16
import 'core/core.dart' ;
16
17
@@ -64,17 +65,20 @@ class _SplashScreenState extends State<SplashScreen> {
64
65
Future <void > _init (GoRouter router) async {
65
66
await GetIt .I .reset ();
66
67
68
+ final logger = Logger (printer: SimplePrinter (colors: false ));
69
+ GetIt .I .registerSingleton (logger);
70
+ GetIt .I .registerSingleton <AbstractUrlLauncher >(UrlLauncher ());
71
+
67
72
// TODO(jkoenig134): we should probably ask for permission when we need it
68
- await Permission .camera.request ();
73
+ final cameraStatus = await Permission .camera.request ();
74
+ if (! cameraStatus.isGranted) {
75
+ logger.w ('Camera permission is (permanently) denied' );
76
+ }
69
77
70
78
if (Platform .isAndroid && kDebugMode) {
71
79
await InAppWebViewController .setWebContentsDebuggingEnabled (true );
72
80
}
73
81
74
- final logger = Logger (printer: SimplePrinter (colors: false ));
75
- GetIt .I .registerSingleton (logger);
76
- GetIt .I .registerSingleton <AbstractUrlLauncher >(UrlLauncher ());
77
-
78
82
final runtime = EnmeshedRuntime (
79
83
logger: logger,
80
84
runtimeConfig: (
@@ -87,6 +91,7 @@ class _SplashScreenState extends State<SplashScreen> {
87
91
),
88
92
);
89
93
GetIt .I .registerSingletonAsync <EnmeshedRuntime >(() async => runtime.run ());
94
+
90
95
await GetIt .I .allReady ();
91
96
92
97
await setupPush (runtime);
@@ -101,10 +106,10 @@ class _SplashScreenState extends State<SplashScreen> {
101
106
102
107
await runtime.registerUIBridge (AppUIBridge (logger: logger, router: router));
103
108
109
+ await _registerWindowsSchemeForDebugMode ('nmshd-dev' );
110
+
104
111
final appLinks = AppLinks ();
105
- appLinks.uriLinkStream.listen ((Uri ? uri) {
106
- if (uri != null ) GetIt .I .get <EnmeshedRuntime >().stringProcessor.processURL (url: uri.toString ());
107
- });
112
+ appLinks.uriLinkStream.listen (_processUri);
108
113
109
114
final accounts = await runtime.accountServices.getAccounts ();
110
115
final accountsNotInDeletion = await runtime.accountServices.getAccountsNotInDeletion ();
@@ -123,8 +128,33 @@ class _SplashScreenState extends State<SplashScreen> {
123
128
}
124
129
125
130
final initialAppLink = await appLinks.getInitialLink ();
126
- if (initialAppLink != null ) {
127
- await GetIt .I .get <EnmeshedRuntime >().stringProcessor.processURL (url: initialAppLink.toString ());
131
+ await _processUri (initialAppLink);
132
+ }
133
+
134
+ Future <void > _processUri (Uri ? uri) async {
135
+ if (uri == null ) return ;
136
+
137
+ final uriString = uri.toString ().replaceAll ('nmshd-dev://' , 'nmshd://' ).replaceAll ('qr/#' , 'qr#' );
138
+ GetIt .I .get <Logger >().i ("Processing URL '$uriString '" );
139
+
140
+ final result = await GetIt .I .get <EnmeshedRuntime >().stringProcessor.processURL (url: uriString);
141
+ if (result.isError) {
142
+ GetIt .I .get <Logger >().e ("Processing URL '$uriString ' failed with code '${result .error .code }' and message '${result .error .message }'" );
128
143
}
129
144
}
130
145
}
146
+
147
+ Future <void > _registerWindowsSchemeForDebugMode (String scheme) async {
148
+ if (! Platform .isWindows || ! kDebugMode) return ;
149
+
150
+ final appPath = Platform .resolvedExecutable;
151
+
152
+ final protocolRegKey = 'Software\\ Classes\\ $scheme ' ;
153
+ const protocolRegValue = RegistryValue ('URL Protocol' , RegistryValueType .string, '' );
154
+ const protocolCmdRegKey = r'shell\open\command' ;
155
+ final protocolCmdRegValue = RegistryValue ('' , RegistryValueType .string, '"$appPath " "%1"' );
156
+
157
+ Registry .currentUser.createKey (protocolRegKey)
158
+ ..createValue (protocolRegValue)
159
+ ..createKey (protocolCmdRegKey).createValue (protocolCmdRegValue);
160
+ }
0 commit comments