Skip to content

Commit 2e56aa5

Browse files
committed
Fix update from creating desktop shortcut
1 parent 31b0bc1 commit 2e56aa5

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

src/squirrelhooks.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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";
20+
import fs, { promises as fsProm } from "fs";
2121

2222
function runUpdateExe(args: string[]): Promise<void> {
2323
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
@@ -33,43 +33,22 @@ function runUpdateExe(args: string[]): Promise<void> {
3333
});
3434
}
3535

36+
function createShortcuts() {
37+
const target = path.basename(process.execPath);
38+
return runUpdateExe(['--createShortcut=' + target]);
39+
}
40+
3641
function checkSquirrelHooks(): boolean {
3742
if (process.platform !== 'win32') return false;
38-
3943
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-
});
44+
if (cmd === '--squirrel-install') {
45+
createShortcuts().then(() => app.quit());
46+
return true;
47+
} else if (cmd === '--squirrel-updated') {
48+
app.quit();
7149
return true;
7250
} else if (cmd === '--squirrel-uninstall') {
51+
const target = path.basename(process.execPath);
7352
runUpdateExe(['--removeShortcut=' + target]).then(() => {
7453
app.quit();
7554
});

0 commit comments

Comments
 (0)