-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathwindows.js
123 lines (117 loc) · 3.68 KB
/
windows.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var os = require('os');
var fs = require('fs');
var path = require('path');
//Windows 64bits "Program Files"
//Windows 32bits "Program Files x86"
var programFiles = os.arch() === "x64" ? process.env.ProgramFiles : ( process.env["ProgramFiles(x86)"] || process.env.ProgramFiles );
var cwd = path.normalize(programFiles);
var appData = appData || process.env.APPDATA;
module.exports = {
chrome: {
defaultLocation: altPaths('Google', 'Chrome', 'Application', 'chrome.exe') ,
pathQuery: 'dir /s /b chrome.exe',
cwd: cwd,
opensTab: true
},
canary: {
defaultLocation: altPaths('Google', 'Chrome SxS', 'Application', 'chrome.exe')
},
firefox: {
defaultLocation: path.join(programFiles, 'Mozilla Firefox', 'firefox.exe'),
pathQuery: 'dir /s /b firefox.exe',
cwd: cwd,
opensTab: true
},
aurora: {
defaultLocation: path.join(programFiles, 'firefox.exe'),
opensTab: true
},
opera: {
defaultLocation: path.join(programFiles, 'Opera', 'launcher.exe'),
pathQuery: 'dir /s /b opera.exe',
cwd: cwd,
imageName: 'opera.exe',
opensTab: true
},
ie: {
defaultLocation: path.join(programFiles, 'Internet Explorer', 'iexplore.exe'),
pathQuery: 'dir /s /b iexplore.exe',
cwd: cwd
},
edge: {
defaultLocation: path.join(getEdgeDirectory() || programFiles, 'MicrosoftEdge.exe'),
getCommand: function(browser, url) {
return 'start /wait microsoft-edge:' + url;
},
opensTab: true,
cwd: cwd
},
electron: {
defaultLocation: path.join(process.cwd(), 'node_modules', '.bin', 'electron.cmd'),
pathQuery: 'dir /s /b electron.exe',
imageName: 'electron.exe',
args: [path.join(__dirname, '..', '..', '..', 'resources', 'electron.js')],
multi: true,
subshell: true,
forceKill: true,
cwd: cwd
},
phantom: {
defaultLocation: [
path.join(process.cwd(), 'node_modules', '.bin', 'phantomjs'),
path.join(programFiles, 'phantomjs', 'phantomjs.exe')
],
imageName: 'phantomjs.exe',
args: [path.join(__dirname, '..', '..', '..', 'resources', 'phantom.js')],
pathQuery: 'dir /s /b phantomjs.exe',
multi: true,
subshell: true,
forceKill: true,
cwd: cwd
},
nodeWebkit: {
pathQuery: 'dir /s /b nw.exe',
multi: true,
cwd: cwd,
imageName: 'nw.exe',
getCommand: function(browser, url) {
var app = process.cwd();
return '"' + browser.command + '" ' + app + ' --url="' + url + '"';
}
}
};
function altPaths() {
var args = Array.prototype.slice.call(arguments);
var paths = [
path.join.apply(path, [programFiles].concat(args)),
path.join.apply(path, [appData].concat(args))
];
//chrome installed under "Program Files x86"
//even for x64 architecture at least for Win10
//the installer could be x32?
if (os.arch() === "x64") {
paths.push(path.join.apply(path, [process.env["ProgramFiles(x86)"]].concat(args)));
}
return paths;
}
function getEdgeDirectory() {
var windowsDirectory = process.env.winDir;
var systemApps = path.join(windowsDirectory, 'SystemApps');
try {
var edgeFolders = fs.readdirSync(systemApps).filter(function(folder) {
// Windows 10 has Microsoft.MicrosoftEdge_*** and Microsoft.MicrosoftEdgeDevToolsClient_***
// see: https://docs.microsoft.com/en-us/windows/application-management/apps-in-windows-10
if (folder.indexOf("Microsoft.MicrosoftEdge") === 0) {
var edgePath = path.join(systemApps, folder, "MicrosoftEdge.exe");
if (fs.existsSync(edgePath)) {
return folder;
}
}
}).map(function(folder) {
return path.join(systemApps, folder);
});
return edgeFolders[0] || systemApps;
} catch(ex) {
return systemApps;
}
}