mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-18 23:44:59 +01:00
Fix update from creating desktop shortcut (#333)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
a933331f82
commit
fba2709119
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import { promises as fsProm } from "fs";
|
|
||||||
|
|
||||||
function runUpdateExe(args: string[]): Promise<void> {
|
function runUpdateExe(args: string[]): Promise<void> {
|
||||||
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
|
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
|
||||||
@ -35,44 +34,16 @@ function runUpdateExe(args: string[]): Promise<void> {
|
|||||||
|
|
||||||
function checkSquirrelHooks(): boolean {
|
function checkSquirrelHooks(): boolean {
|
||||||
if (process.platform !== 'win32') return false;
|
if (process.platform !== 'win32') return false;
|
||||||
|
|
||||||
const cmd = process.argv[1];
|
const cmd = process.argv[1];
|
||||||
const target = path.basename(process.execPath);
|
const target = path.basename(process.execPath);
|
||||||
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
if (cmd === '--squirrel-install') {
|
||||||
runUpdateExe(['--createShortcut=' + target]).then(() => {
|
runUpdateExe(['--createShortcut=' + target]).then(() => app.quit());
|
||||||
// remove the old 'Riot' shortcuts, if they exist (update.exe --removeShortcut doesn't work
|
return true;
|
||||||
// because it always uses the name of the product as the name of the shortcut: the only variable
|
} else if (cmd === '--squirrel-updated') {
|
||||||
// is what executable you're linking to)
|
app.quit();
|
||||||
const appDataDir = process.env.APPDATA;
|
|
||||||
if (!appDataDir) return;
|
|
||||||
const startMenuDir = path.join(
|
|
||||||
appDataDir, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'New Vector Ltd',
|
|
||||||
);
|
|
||||||
return fsProm.rmdir(startMenuDir, { recursive: true });
|
|
||||||
}).then(() => {
|
|
||||||
// same for 'Element (Riot) which is old now too (we have to try to delete both because
|
|
||||||
// we don't know what version we're updating from, but of course we do know this version
|
|
||||||
// is 'Element' so the two old ones are all safe to delete).
|
|
||||||
const appDataDir = process.env.APPDATA;
|
|
||||||
if (!appDataDir) return;
|
|
||||||
const oldStartMenuLink = path.join(
|
|
||||||
appDataDir, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Element', 'Element (Riot).lnk',
|
|
||||||
);
|
|
||||||
return fsProm.unlink(oldStartMenuLink).catch(() => {});
|
|
||||||
}).then(() => {
|
|
||||||
const oldDesktopShortcut = path.join(app.getPath('desktop'), 'Element (Riot).lnk');
|
|
||||||
return fsProm.unlink(oldDesktopShortcut).catch(() => {});
|
|
||||||
}).then(() => {
|
|
||||||
const oldDesktopShortcut = path.join(app.getPath('desktop'), 'Riot.lnk');
|
|
||||||
return fsProm.unlink(oldDesktopShortcut).catch(() => {});
|
|
||||||
}).then(() => {
|
|
||||||
app.quit();
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
} else if (cmd === '--squirrel-uninstall') {
|
} else if (cmd === '--squirrel-uninstall') {
|
||||||
runUpdateExe(['--removeShortcut=' + target]).then(() => {
|
runUpdateExe(['--removeShortcut=' + target]).then(() => app.quit());
|
||||||
app.quit();
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
} else if (cmd === '--squirrel-obsolete') {
|
} else if (cmd === '--squirrel-obsolete') {
|
||||||
app.quit();
|
app.quit();
|
||||||
|
Loading…
Reference in New Issue
Block a user