summarylogtreecommitdiffstats
path: root/fix-argv.diff
blob: cad8f55ede6cb527756393c2130b0300738d98e4 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
diff --git a/packages/compass-preferences-model/src/global-config.ts b/packages/compass-preferences-model/src/global-config.ts
index 179ccc2e3..09b82244b 100644
--- a/packages/compass-preferences-model/src/global-config.ts
+++ b/packages/compass-preferences-model/src/global-config.ts
@@ -195,8 +195,6 @@ export interface ParsedGlobalPreferencesResult {
   preferenceParseErrors: string[];
 }
 
-// See https://github.com/electron/electron/issues/4690
-const argvStartIndex = process.versions.electron && !process.defaultApp ? 1 : 2;
 export async function parseAndValidateGlobalPreferences(
   sources: GlobalPreferenceSources = {}
 ): Promise<ParsedGlobalPreferencesResult> {
@@ -205,6 +203,16 @@ export async function parseAndValidateGlobalPreferences(
   );
   let argv = sources.argv;
   if (!argv) {
+    let argvStartIndex = 0;
+
+    for (const arg of process.argv) {
+      argvStartIndex++;
+
+      if (arg.includes('app.asar') === true) {
+        break;
+      }
+    }
+
     argv = process.argv.slice(argvStartIndex);
   }
   const cliPreferences = parseCliArgs(argv);
@@ -294,11 +302,17 @@ export function getHelpText(): string {
     text += `  ${path}\n`;
   }
   if (globalConfigPaths.length > 0) {
+    let binaryName = '';
+
+    for (const arg of process.argv) {
+      if (arg.includes('app.asar') === true) {
+        binaryName = arg.replace('/usr/lib/', '').replace('/app.asar', '');
+        break;
+      }
+    }
+
     text += '\nIf no global configuration file exists, running Compass as\n';
-    text += `  ${escapeShell(process.execPath)}${
-      argvStartIndex >= 2 ? ' ' + escapeShell(process.argv[1]) : ''
-    } `;
-    text += `--show-example-config > ${escapeShell(globalConfigPaths[0])}\n`;
+    text += `  ${binaryName} --show-example-config > ${escapeShell(globalConfigPaths[0])}\n`;
     text += 'can be used to install one.\n';
   }
   text += '\nSee the MongoDB Compass documentation for more details.\n';
diff --git a/packages/compass/src/main/protocol-handling.ts b/packages/compass/src/main/protocol-handling.ts
index 827c4f18d..615b32a62 100644
--- a/packages/compass/src/main/protocol-handling.ts
+++ b/packages/compass/src/main/protocol-handling.ts
@@ -13,9 +13,15 @@ async function appProtocolsConfig(): Promise<ProtocolsList> {
   return (await import('../../package.json')).config.hadron.protocols;
 }
 
-const commandArgv = process.defaultApp
-  ? [process.execPath, path.resolve(process.argv[1]), '--']
-  : [process.execPath, '--'];
+let commandArgv = [];
+
+for (const arg of process.argv) {
+  if (arg.includes('app.asar') === true) {
+    commandArgv[0] = arg.replace('/usr/lib/', '').replace('/app.asar', '');
+    commandArgv[1] = '--';
+    break;
+  }
+}
 
 export async function setupProtocolHandlers(
   action: 'install' | 'uninstall',