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