forked from dfmcphee/simple-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (69 loc) · 1.96 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
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
'use strict';
const app = require('app');
const BrowserWindow = require('browser-window');
const NativeImage = require('native-image');
const gh_releases = require('electron-gh-releases');
const ip = require('ip');
// report crashes to the Electron project
//require('crash-reporter').start();
// adds debug features like hotkeys for triggering dev tools and reload
// require('electron-debug')();
let setup = require('proxy');
let http = require('http');
let ipc = require('ipc');
let dns = require('dns');
let menubar = require('menubar');
let server;
const icons = {
active: app.getAppPath() + '/IconTemplate.png',
subdued: app.getAppPath() + '/IconSubduedTemplate.png'
}
let mb = menubar({
preloadWindow: true,
width: 400,
height: 180,
icon: icons.subdued
});
mb.on('ready', function ready () {
console.log('app is ready')
//mb.window.openDevTools();
});
mb.on('show', function() {
mb.window.webContents.send('set-ip', ip.address());
});
ipc.on('connect', function(event) {
event.sender.send('set-ip', ip.address());
});
ipc.on('start-proxy', function(event, port) {
server = setup(http.createServer());
server.listen(port, function() {
mb.tray.setImage(icons.active);
var port = server.address().port;
console.log('HTTP(s) proxy server listening on port %d', port);
});
});
ipc.on('stop-proxy', function(event, port) {
server.close(function() {
mb.tray.setImage(icons.subdued);
console.log('proxy stopped')
});
});
let options = {
repo: 'dfmcphee/simple-proxy',
currentVersion: app.getVersion()
};
let update = new gh_releases(options, function(auto_updater) {
// Auto updater event listener
auto_updater.on('update-downloaded', function(e, rNotes, rName, rDate, uUrl, quitAndUpdate) {
// Install the update
console.log('Update downloaded.');
quitAndUpdate()
})
});
// Check for updates
update.check(function (err, status) {
if (!err && status) {
console.log('Update downloading.');
update.download()
}
});