-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.js
74 lines (67 loc) · 2 KB
/
main.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
const {
app,
Menu,
Tray,
Notification,
clipboard,
shell
} = require('electron');
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');
var appIcon = null;
app.on('ready', function(){
// Menu bar icon
appIcon = new Tray(path.join(__dirname, '/assets/images/iconTemplate.png'));
const contextMenu = Menu.buildFromTemplate([
{
label: 'Refresh MAC address...',
type: 'normal',
click: function(event) { renewMacAddress() }
},
{
label: 'Quit',
type: 'normal',
click: function(event) { app.quit(); }
}
]);
appIcon.setToolTip('Airpass');
appIcon.setContextMenu(contextMenu);
// Hide dock menu
app.dock.hide();
function renewMacAddress() {
let notification = new Notification({
title: 'Changing MAC adddress 🤖',
body: 'Please input your password when requested to make the necessary changes.',
silent: true
})
notification.show();
var sudo = require('sudo-prompt');
var options = {
name: 'Airpass'
};
sudo.exec("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport en0 -z && ifconfig en0 ether `openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`", options,
function(error, stdout, stderr) {
if (!error) {
let notification = new Notification({
title: 'MAC address changed 👌',
body: 'Connect to the network again to start a new session 📡',
silent: true
})
notification.show();
} else {
let issues_url = "https://github.com/alvesjtiago/airpass/issues"
let notification = new Notification({
title: 'Could not refresh MAC address',
body: 'Please check ' + issues_url + ' for help.',
silent: true
})
notification.show();
notification.on('click', function(event) {
shell.openExternal(issues_url)
})
}
}
);
}
});