-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.36 KB
/
index.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
class ProxySettings {
constructor() {
try {
const binary = require('@mapbox/node-pre-gyp');
const path = require('path');
const binding_path = binary.find(path.resolve(path.join(__dirname, './package.json')));
this.impl = require(binding_path);
} catch (ex) {
console.log('unable to initialize desktop-proxy-settings:' + ex);
}
}
read(url) {
if (!this.impl) {
return undefined;
}
return this.impl.read(url);
}
dump(url) {
if (!this.impl) {
return undefined;
}
return this.impl.dump(url);
}
openSystemSettings() {
if (process.platform === 'darwin') {
if (!this.impl || !this.impl.openSystemSettings()) {
const script = "/usr/bin/osascript -e 'tell application \"System Preferences\"' -e 'activate' \
-e 'set current pane to pane \"com.apple.preference.network\"' \
-e 'reveal anchor \"Proxies\" of pane \"com.apple.preference.network\"' -e 'end tell'";
require('child_process').exec(script);
}
} else {
if (parseInt(require('os').release().split(".")[0]) > 7) {
require('child_process').exec('START "" "ms-settings:network-proxy"');
} else {
require('child_process').exec('rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,4');
}
}
}
}
const proxySettings = new ProxySettings();
module.exports = proxySettings;