@@ -2,53 +2,107 @@ import { app } from 'electron';
2
2
import fs from 'fs' ;
3
3
import path from 'path' ;
4
4
5
- let appPaths : Record < keyof InstalledApps , string [ ] > ;
6
- let terminalPaths : Record < 'iterm' , string [ ] > ;
5
+ type PlatformPaths = {
6
+ [ K in keyof InstalledApps | keyof InstalledTerminals ] : string [ ] ;
7
+ } ;
7
8
8
- if ( process . platform === 'darwin' ) {
9
- const systemApplications = '/Applications' ;
10
- const userApplications = path . join ( app . getPath ( 'home' ) , 'Applications' ) ;
9
+ function getProgramFilesPath ( ) : string {
10
+ if ( process . platform !== 'win32' ) {
11
+ return 'C:\\Program Files' ;
12
+ }
13
+
14
+ // This env var dinamically points to the Program Files path
15
+ // See https://stackoverflow.com/a/9608782
16
+ const programFiles = process . env . ProgramFiles ;
17
+ if ( programFiles ) {
18
+ return programFiles ;
19
+ }
11
20
12
- appPaths = {
21
+ // Fallback to default path if environment variable is not available
22
+ return 'C:\\Program Files' ;
23
+ }
24
+
25
+ // Define installation paths for each IDE by platform
26
+ const installationPaths : Record < string , PlatformPaths > = {
27
+ darwin : {
28
+ vscode : [ 'Visual Studio Code.app' ] ,
29
+ phpstorm : [ 'PhpStorm.app' ] ,
30
+ cursor : [ 'Cursor.app' ] ,
31
+ windsurf : [ 'Windsurf.app' ] ,
32
+ webstorm : [ 'WebStorm.app' ] ,
33
+ iterm : [ 'iTerm.app' ] ,
34
+ terminal : [ 'Terminal.app' ] ,
35
+ } ,
36
+ linux : {
37
+ vscode : [ '/usr/bin/code' ] ,
38
+ phpstorm : [ '/usr/bin/phpstorm' ] ,
39
+ cursor : [ '/usr/bin/cursor' ] ,
40
+ windsurf : [ '/usr/bin/windsurf' ] ,
41
+ webstorm : [ '/usr/bin/webstorm' ] ,
42
+ iterm : [ ] ,
43
+ terminal : [ ] ,
44
+ } ,
45
+ win32 : {
13
46
vscode : [
14
- path . join ( systemApplications , 'Visual Studio Code.app ' ) ,
15
- path . join ( userApplications , 'Visual Studio Code.app ' ) ,
47
+ path . win32 . join ( getProgramFilesPath ( ) , 'Microsoft VS Code' ) ,
48
+ path . win32 . join ( app . getPath ( 'appData' ) , 'Local\\Programs\\Microsoft VS Code' ) ,
16
49
] ,
17
50
phpstorm : [
18
- path . join ( systemApplications , 'PhpStorm.app ' ) ,
19
- path . join ( userApplications , 'PhpStorm.app ' ) ,
51
+ path . win32 . join ( getProgramFilesPath ( ) , 'JetBrains\\ PhpStorm' ) ,
52
+ path . win32 . join ( app . getPath ( 'appData' ) , 'JetBrains\\ PhpStorm' ) ,
20
53
] ,
21
- } ;
22
-
23
- terminalPaths = {
24
- iterm : [
25
- path . join ( systemApplications , 'iTerm.app' ) ,
26
- path . join ( userApplications , 'iTerm.app' ) ,
54
+ cursor : [
55
+ path . win32 . join ( getProgramFilesPath ( ) , 'Cursor' ) ,
56
+ path . win32 . join ( app . getPath ( 'appData' ) , 'Local\\Programs\\Cursor' ) ,
27
57
] ,
28
- } ;
29
- } else if ( process . platform === 'linux' ) {
30
- appPaths = {
31
- vscode : [ '/usr/bin/code' ] ,
32
- phpstorm : [ '/usr/bin/phpstorm' ] ,
33
- } ;
34
- terminalPaths = {
35
- iterm : [ ] , // iTerm is macOS only
36
- } ;
58
+ windsurf : [
59
+ path . win32 . join ( getProgramFilesPath ( ) , 'Windsurf' ) ,
60
+ path . win32 . join ( app . getPath ( 'appData' ) , 'Windsurf' ) ,
61
+ ] ,
62
+ webstorm : [
63
+ path . win32 . join ( getProgramFilesPath ( ) , 'JetBrains\\WebStorm' ) ,
64
+ path . win32 . join ( app . getPath ( 'appData' ) , 'JetBrains\\WebStorm' ) ,
65
+ ] ,
66
+ iterm : [ ] ,
67
+ terminal : [ ] ,
68
+ } ,
69
+ } ;
70
+
71
+ if ( process . platform === 'darwin' ) {
72
+ const systemApplications = '/Applications' ;
73
+ const userApplications = path . join ( app . getPath ( 'home' ) , 'Applications' ) ;
74
+
75
+ Object . keys ( installationPaths . darwin ) . forEach ( ( ide ) => {
76
+ const appName = installationPaths . darwin [ ide as keyof InstalledApps ] [ 0 ] ;
77
+ if ( appName ) {
78
+ installationPaths . darwin [ ide as keyof InstalledApps ] = [
79
+ path . join ( systemApplications , appName ) ,
80
+ path . join ( userApplications , appName ) ,
81
+ ] ;
82
+ }
83
+ } ) ;
37
84
} else if ( process . platform === 'win32' ) {
38
- appPaths = {
39
- vscode : [ path . join ( app . getPath ( 'appData' ) , 'Code' ) ] ,
40
- phpstorm : [ '' ] , // Disable phpStorm for Windows
41
- } ;
42
- terminalPaths = {
43
- iterm : [ ] , // iTerm is macOS only
44
- } ;
85
+ // For JetBrains IDEs, check for version-specific folders
86
+ [ 'phpstorm' , 'webstorm' ] . forEach ( ( ide ) => {
87
+ const basePaths = installationPaths . win32 [ ide as keyof InstalledApps ] ;
88
+ const jetbrainsDir = path . win32 . join ( getProgramFilesPath ( ) , 'JetBrains' ) ;
89
+
90
+ if ( fs . existsSync ( jetbrainsDir ) ) {
91
+ const entries = fs . readdirSync ( jetbrainsDir ) ;
92
+
93
+ entries . forEach ( ( entry ) => {
94
+ if ( entry . toLowerCase ( ) . includes ( ide ) ) {
95
+ basePaths . push ( path . win32 . join ( jetbrainsDir , entry ) ) ;
96
+ }
97
+ } ) ;
98
+ }
99
+ } ) ;
45
100
}
46
101
47
- export function isInstalled ( key : keyof typeof appPaths | keyof typeof terminalPaths ) : boolean {
48
- const paths =
49
- appPaths [ key as keyof typeof appPaths ] || terminalPaths [ key as keyof typeof terminalPaths ] ;
50
- if ( ! paths ) {
51
- return false ;
52
- }
53
- return paths . some ( ( path : string ) => path && fs . existsSync ( path ) ) ;
102
+ export function isInstalled ( key : keyof InstalledApps | keyof InstalledTerminals ) : boolean {
103
+ const platform = process . platform ;
104
+ const paths = installationPaths [ platform ] ?. [ key ] ;
105
+
106
+ // Return true if any of the possible paths exist
107
+ return paths . some ( ( pathStr : string ) => pathStr && fs . existsSync ( pathStr ) ) ;
54
108
}
0 commit comments