@@ -3,7 +3,6 @@ import 'dart:io';
3
3
4
4
import 'package:flutter/services.dart' ;
5
5
import 'package:path/path.dart' as path;
6
- import 'package:path_provider/path_provider.dart' ;
7
6
import 'package:win32_registry/win32_registry.dart' ;
8
7
9
8
import '../../win32.dart' ;
@@ -27,8 +26,7 @@ const _firefoxNativeHostsKey = r'Software\Mozilla\NativeMessagingHosts';
27
26
28
27
/// Install host binary for browser extension
29
28
Future <void > doInstallHost () async {
30
- final hostPath =
31
- path.join ((await getApplicationSupportDirectory ()).path, _hostExecName);
29
+ final hostPath = _joinExePath (_hostExecName);
32
30
33
31
Future <List <int >> getHostAssetData () async {
34
32
final hostAsset = await rootBundle.load ('assets/host/$_hostExecName ' );
@@ -102,7 +100,7 @@ Future<bool> doCheckManifestInstalled(Browser browser) async {
102
100
}
103
101
104
102
final existingContent = await File (manifestPath).readAsString ();
105
- final expectedContent = await _getManifestContent ();
103
+ final expectedContent = await _getManifestContent (browser );
106
104
return existingContent == expectedContent;
107
105
}
108
106
@@ -112,7 +110,7 @@ Future<void> doInstallManifest(Browser browser) async {
112
110
if (await checkManifestInstalled (browser)) return ;
113
111
114
112
final manifestPath = _getManifestPath (browser)! ;
115
- final manifestContent = await _getManifestContent ();
113
+ final manifestContent = await _getManifestContent (browser );
116
114
final manifestDir = path.dirname (manifestPath);
117
115
await Directory (manifestDir).create (recursive: true );
118
116
await File (manifestPath).writeAsString (manifestContent);
@@ -235,10 +233,10 @@ List<String> _getUnixExecutablePaths(Browser browser) {
235
233
}
236
234
237
235
String ? _getManifestPath (Browser browser) {
236
+ final manifestName =
237
+ browser == Browser .firefox ? '$_hostName .moz.json' : '$_hostName .json' ;
238
238
if (Platform .isWindows) {
239
- final execPath = Platform .resolvedExecutable;
240
- final execDir = path.dirname (execPath);
241
- return path.join (execDir, '$_hostName .json' );
239
+ return _joinExePath (manifestName);
242
240
}
243
241
244
242
final home =
@@ -249,25 +247,25 @@ String? _getManifestPath(Browser browser) {
249
247
switch (browser) {
250
248
case Browser .chrome:
251
249
return path.join (home, 'Library' , 'Application Support' , 'Google' ,
252
- 'Chrome' , 'NativeMessagingHosts' , '$ _hostName .json' );
250
+ 'Chrome' , 'NativeMessagingHosts' , manifestName );
253
251
case Browser .edge:
254
252
return path.join (home, 'Library' , 'Application Support' ,
255
- 'Microsoft Edge' , 'NativeMessagingHosts' , '$ _hostName .json' );
253
+ 'Microsoft Edge' , 'NativeMessagingHosts' , manifestName );
256
254
case Browser .firefox:
257
255
return path.join (home, 'Library' , 'Application Support' , 'Mozilla' ,
258
- 'NativeMessagingHosts' , '$ _hostName .json' );
256
+ 'NativeMessagingHosts' , manifestName );
259
257
}
260
258
} else if (Platform .isLinux) {
261
259
switch (browser) {
262
260
case Browser .chrome:
263
261
return path.join (home, '.config' , 'google-chrome' ,
264
- 'NativeMessagingHosts' , '$ _hostName .json' );
262
+ 'NativeMessagingHosts' , manifestName );
265
263
case Browser .edge:
266
264
return path.join (home, '.config' , 'microsoft-edge' ,
267
- 'NativeMessagingHosts' , '$ _hostName .json' );
265
+ 'NativeMessagingHosts' , manifestName );
268
266
case Browser .firefox:
269
267
return path.join (
270
- home, '.mozilla' , 'native-messaging-hosts' , '$ _hostName .json' );
268
+ home, '.mozilla' , 'native-messaging-hosts' , manifestName );
271
269
}
272
270
}
273
271
return null ;
@@ -283,20 +281,20 @@ Future<bool> _checkWindowsRegistry(String keyPath) async {
283
281
}
284
282
}
285
283
286
- Future <String > _getManifestContent () async {
287
- final hostPath =
288
- path.join ((await getApplicationSupportDirectory ()).path, _hostExecName);
284
+ Future <String > _getManifestContent (Browser browser) async {
285
+ final hostPath = _joinExePath (_hostExecName);
289
286
final manifest = {
290
287
'name' : _hostName,
291
288
'description' : 'Gopeed browser extension host' ,
292
289
'path' : hostPath,
293
290
'type' : 'stdio' ,
294
- 'allowed_origins' : [
295
- 'chrome-extension://$_chromeExtensionId /' ,
296
- 'chrome-extension://$_edgeExtensionId /' ,
297
- ..._debugExtensionIds.map ((id) => 'chrome-extension://$id /' ),
298
- ],
299
- 'allowed_extensions' : [_firefoxExtensionId],
291
+ if (browser != Browser .firefox)
292
+ 'allowed_origins' : [
293
+ 'chrome-extension://$_chromeExtensionId /' ,
294
+ 'chrome-extension://$_edgeExtensionId /' ,
295
+ ..._debugExtensionIds.map ((id) => 'chrome-extension://$id /' ),
296
+ ],
297
+ if (browser == Browser .firefox) 'allowed_extensions' : [_firefoxExtensionId],
300
298
};
301
299
return const JsonEncoder .withIndent (' ' ).convert (manifest);
302
300
}
@@ -311,3 +309,9 @@ String _getWindowsRegistryKey(Browser browser) {
311
309
return _firefoxNativeHostsKey;
312
310
}
313
311
}
312
+
313
+ String _joinExePath (String fileName) {
314
+ final execPath = Platform .resolvedExecutable;
315
+ final execDir = path.dirname (execPath);
316
+ return path.join (execDir, fileName);
317
+ }
0 commit comments