Skip to content

Commit 613ff6a

Browse files
committed
Also fix the shortcut that's made by squirrel
1 parent 0f8c56e commit 613ff6a

File tree

6 files changed

+83
-61
lines changed

6 files changed

+83
-61
lines changed

package-lock.json

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@
251251
"electron-devtools-installer": "^3.2.0",
252252
"electron-dl": "^3.5.0",
253253
"electron-mocha": "^12.2.0",
254-
"electron-squirrel-startup": "^1.0.1",
255254
"ensure-error": "^3.0.1",
256255
"glob": "^10.2.5",
257256
"local-links": "^1.4.0",

packages/compass/src/main/application.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
extractProxySecrets,
4040
translateToElectronProxyConfig,
4141
} from '@mongodb-js/devtools-proxy-support';
42+
import { handleSquirrelWindowsStartup } from './squirrel-startup';
4243

4344
const { debug, log, mongoLogId } = createLogger('COMPASS-MAIN');
4445
const track = createIpcTrack();
@@ -121,8 +122,8 @@ class CompassApplication {
121122
);
122123

123124
// needs to happen after setupProtocolHandlers
124-
if ((await import('electron-squirrel-startup')).default) {
125-
debug('electron-squirrel-startup event handled sucessfully\n');
125+
if (await handleSquirrelWindowsStartup()) {
126+
app.quit();
126127
return;
127128
}
128129

packages/compass/src/main/electron-squirrel-startup.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import path from 'path';
2+
import { spawn } from 'child_process';
3+
import { createLogger } from '@mongodb-js/compass-logging';
4+
const { debug } = createLogger('SQUIRREL-STARTUP');
5+
6+
function runUpdateExe(args: string[]): Promise<void> {
7+
return new Promise<void>(function (resolve) {
8+
const updateExe = path.resolve(
9+
path.dirname(process.execPath),
10+
'..',
11+
'Update.exe'
12+
);
13+
debug('Spawning `%s` with args `%s`', updateExe, args.join(' '));
14+
spawn(updateExe, args, {
15+
detached: true,
16+
}).on('close', () => resolve());
17+
});
18+
}
19+
20+
function getShortcutName() {
21+
// The shortcut name is the app name plus the channel name if it is not
22+
// stable. ie. "MongoDB Compass Readonly Beta"
23+
24+
const parts: string[] = [process.env.HADRON_PRODUCT_NAME];
25+
if (process.env.HADRON_CHANNEL !== 'stable') {
26+
parts.push(
27+
process.env.HADRON_CHANNEL.charAt(0).toUpperCase() +
28+
process.env.HADRON_CHANNEL.slice(1)
29+
);
30+
}
31+
return parts.join(' ');
32+
}
33+
34+
/*
35+
Squirrel will spawn Compass with command line flags on first run, updates, and
36+
uninstalls. It is very important that we handle these events as early as
37+
possible, and quit immediately after handling them. Squirrel gives apps a short
38+
amount of time (~15sec) to apply these operations and quit.
39+
*/
40+
export async function handleSquirrelWindowsStartup(): Promise<boolean> {
41+
if (process.platform !== 'win32') {
42+
return false;
43+
}
44+
45+
const shortcutName = getShortcutName();
46+
47+
const cmd = process.argv[1];
48+
debug('processing squirrel command `%s`', cmd);
49+
50+
/*
51+
For more detailed info on these commands, so Electron and Squirrel Windows'
52+
documentation:
53+
54+
https://github.com/electron-archive/grunt-electron-installer?tab=readme-ov-file#handling-squirrel-events
55+
https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/custom-squirrel-events-non-cs.md
56+
https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/install-process.md
57+
https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/update-process.md#update-process
58+
*/
59+
switch (cmd) {
60+
case '--squirrel-install':
61+
case '--squirrel-updated':
62+
await runUpdateExe([`--createShortcut=${shortcutName}`]);
63+
debug(`${cmd} handled sucessfully`);
64+
return true;
65+
66+
case '--squirrel-uninstall':
67+
await runUpdateExe([`--removeShortcut=${shortcutName}`]);
68+
debug(`${cmd} handled sucessfully`);
69+
return true;
70+
71+
case '--squirrel-obsolete':
72+
debug(`${cmd} handled sucessfully`);
73+
return true;
74+
75+
default:
76+
debug(`Unknown squirrel command: ${cmd}. Continuing on.`);
77+
}
78+
79+
return false;
80+
}

packages/hadron-build/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ And then finally
213213

214214
- User's launch application via a desktop shortcut `${productName}`
215215
- Installing into `C:\\Program Files\` would require Administrator
216-
- Desktop shortcut managed for you automatically if you use https://github.com/mongodb-js/electron-squirrel-startup
217216
- Shortcut Target: `C:\Users\${username}\AppData\Local\${_.titlecase(productName)}\Update.exe --processStart ${_.titlecase(productName)}.exe`
218217
- Shortcut Start In: `C:\Users\${username}\AppData\Local\${_.titlecase(productName)}\app-${version}`
219218

@@ -267,7 +266,6 @@ Which assets are generated depends on the target platform.
267266

268267
### Windows
269268

270-
- `electron-squirrel-startup`: https://github.com/mongodb-js/electron-squirrel-startup
271269
- [Update process explained step by step](https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/update-process.md#update-process)
272270

273271
### Linux

0 commit comments

Comments
 (0)