-
Notifications
You must be signed in to change notification settings - Fork 2
/
firebox.js
126 lines (107 loc) · 3.95 KB
/
firebox.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
124
125
126
"use strict";
var Winreg = require("winreg");
var os = require("os");
var Promise = require("es6-promise").Promise;
var spawn = require("child_process").spawn;
var path = require("path");
var readRegistry = function(key, field) {
return new Promise(function(resolve, reject) {
var registry = new Winreg({
hive: Winreg.HKLM,
key: key
});
registry.get(field, function(error, data) {
if (error) {
reject(error)
}
else {
resolve(data.value)
}
});
});
}
var guessWindowsAppPath = function(root, name) {
var programs = arch === "(64)" ? "ProgramFiles(x86)" :
"ProgramFiles";
return path.join(process.env[programs],
name,
"firefox.exe");
};
var resolveWindowsAppPath = function(id, arch) {
var root = arch === "(64)" ? "\\Software\\Wow6432Node\\Mozilla" :
"\\Software\\Mozilla\\";
var name = resolveWindowsAppPath.names[id] || id;
return readRegistry(path.join(root, appName),
"CurrentVersion").
then(function(version) {
return readRegistry(path.join(root, version, "Main"),
"PathToExe");
}).catch(guessWindowsAppPath.bind(null, name, arch));
};
resolveWindowsAppPath.names = {
// the default path in the beta installer is the same as the stable one
"beta": "Mozilla Firefox",
"devedition": "DeveloperEdition",
"dev": "DeveloperEdition",
"aurora": "DeveloperEdition",
"nightly": "Nightly",
"firefox": "Mozilla Firefox"
};
var resolveOSXAppPath = function(app, arch) {
var appPath = resolveOSXAppPath.paths[app.toLowerCase()] ||
app;
return path.extname(appPath) != ".app" ? appPath :
path.join(appPath, "Contents/MacOS/firefox-bin");
};
resolveOSXAppPath.paths = {
"firefox": "/Applications/Firefox.app/Contents/MacOS/firefox-bin",
"beta": "/Applications/FirefoxBeta.app/Contents/MacOS/firefox-bin",
"dev": "/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin",
"devedition": "/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin",
"dev-edition": "/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin",
"aurora": "/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin",
"nightly": "/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin",
}
var resolveLinuxAppPath = function(app, arch) {
var appName = resolveLinuxAppPath.names[app];
var libName = arg == "(64)" ? "lib64" : "lib";
return appName ? "/usr/" + libName + "/" + appName :
app;
};
resolveLinuxAppPath.names = {
"firefox": "firefox",
"aurora": "firefox-developeredition",
"dev-edition": "firefox-developeredition",
"devedition": "firefox-developeredition",
"dev": "firefox-developeredition",
"nightly": "firefox-nightly",
"beta": "firefox-beta"
};
var resolveAppPath = function(app, platform, arch) {
arch = arch || os.arch();
arch = /64/.test(arch) ? "(64)" : "";
platform = platform || process.platform;
platform = /darwin/i.test(platform) ? "osx" :
/win/i.test(platform) ? "windows" + arch :
/linux/i.test(platform) ? "linux" + arch :
platform;
var resolvePlatformAppPath = resolveAppPath[platform] ||
resolveAppPath[""];
return Promise.resolve(resolvePlatformAppPath(app, arch));
}
resolveAppPath["windows"] = resolveWindowsAppPath;
resolveAppPath["osx"] = resolveOSXAppPath;
resolveAppPath["linux"] = resolveLinuxAppPath;
resolveAppPath[""] = function(app) { return app };
exports.resolveAppPath = resolveAppPath;
var params = process.argv.slice(process.argv.indexOf(module.filename) + 1)
var app = params.indexOf("--binary") >= 0 ? params[params.indexOf("--binary") + 1] :
"nightly";
resolveAppPath(app).then(function(binary) {
var args = [
"-app",
require.resolve("./application.ini"),
path.resolve(params[0])
].concat(params.slice(1));
var task = spawn(binary, args, {stdio: "inherit"});
});