Skip to content

Commit 624c097

Browse files
committed
Fix update from creating desktop shortcut
1 parent 31b0bc1 commit 624c097

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

src/squirrelhooks.ts

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
import path from "path";
1818
import { spawn } from "child_process";
1919
import { app } from "electron";
20-
import { promises as fsProm } from "fs";
2120

2221
function runUpdateExe(args: string[]): Promise<void> {
2322
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
@@ -33,43 +32,22 @@ function runUpdateExe(args: string[]): Promise<void> {
3332
});
3433
}
3534

35+
function createShortcuts() {
36+
const target = path.basename(process.execPath);
37+
return runUpdateExe(['--createShortcut=' + target]);
38+
}
39+
3640
function checkSquirrelHooks(): boolean {
3741
if (process.platform !== 'win32') return false;
38-
3942
const cmd = process.argv[1];
40-
const target = path.basename(process.execPath);
41-
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
42-
runUpdateExe(['--createShortcut=' + target]).then(() => {
43-
// remove the old 'Riot' shortcuts, if they exist (update.exe --removeShortcut doesn't work
44-
// because it always uses the name of the product as the name of the shortcut: the only variable
45-
// is what executable you're linking to)
46-
const appDataDir = process.env.APPDATA;
47-
if (!appDataDir) return;
48-
const startMenuDir = path.join(
49-
appDataDir, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'New Vector Ltd',
50-
);
51-
return fsProm.rmdir(startMenuDir, { recursive: true });
52-
}).then(() => {
53-
// same for 'Element (Riot) which is old now too (we have to try to delete both because
54-
// we don't know what version we're updating from, but of course we do know this version
55-
// is 'Element' so the two old ones are all safe to delete).
56-
const appDataDir = process.env.APPDATA;
57-
if (!appDataDir) return;
58-
const oldStartMenuLink = path.join(
59-
appDataDir, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Element', 'Element (Riot).lnk',
60-
);
61-
return fsProm.unlink(oldStartMenuLink).catch(() => {});
62-
}).then(() => {
63-
const oldDesktopShortcut = path.join(app.getPath('desktop'), 'Element (Riot).lnk');
64-
return fsProm.unlink(oldDesktopShortcut).catch(() => {});
65-
}).then(() => {
66-
const oldDesktopShortcut = path.join(app.getPath('desktop'), 'Riot.lnk');
67-
return fsProm.unlink(oldDesktopShortcut).catch(() => {});
68-
}).then(() => {
69-
app.quit();
70-
});
43+
if (cmd === '--squirrel-install') {
44+
createShortcuts().then(() => app.quit());
45+
return true;
46+
} else if (cmd === '--squirrel-updated') {
47+
app.quit();
7148
return true;
7249
} else if (cmd === '--squirrel-uninstall') {
50+
const target = path.basename(process.execPath);
7351
runUpdateExe(['--removeShortcut=' + target]).then(() => {
7452
app.quit();
7553
});

0 commit comments

Comments
 (0)