@@ -17,7 +17,7 @@ limitations under the License.
17
17
import path from "path" ;
18
18
import { spawn } from "child_process" ;
19
19
import { app } from "electron" ;
20
- import { promises as fsProm } from "fs" ;
20
+ import fs , { promises as fsProm } from "fs" ;
21
21
22
22
function runUpdateExe ( args : string [ ] ) : Promise < void > {
23
23
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
@@ -33,43 +33,22 @@ function runUpdateExe(args: string[]): Promise<void> {
33
33
} ) ;
34
34
}
35
35
36
+ function createShortcuts ( ) {
37
+ const target = path . basename ( process . execPath ) ;
38
+ return runUpdateExe ( [ '--createShortcut=' + target ] ) ;
39
+ }
40
+
36
41
function checkSquirrelHooks ( ) : boolean {
37
42
if ( process . platform !== 'win32' ) return false ;
38
-
39
43
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 ( ) ;
71
49
return true ;
72
50
} else if ( cmd === '--squirrel-uninstall' ) {
51
+ const target = path . basename ( process . execPath ) ;
73
52
runUpdateExe ( [ '--removeShortcut=' + target ] ) . then ( ( ) => {
74
53
app . quit ( ) ;
75
54
} ) ;
0 commit comments