-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (77 loc) · 2.26 KB
/
app.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
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
var server = require('http').createServer()
var io = require('socket.io')(server)
const sudo = require('sudo-prompt')
const exec = require('child_process').exec
let win
var start = function(socket, ssid, password) {
sudo.exec('netsh wlan set hostednetwork mode=allow ssid="' + ssid + '" key="'+ password + '" & netsh wlan start hostednetwork', {name: 'Windows Share Network'}, function(err, out) {
if(socket != undefined) {
(err == null) ? socket.emit('EndLoading', true) : socket.emit('EndLoading', false)
}
})
}
var stop = function(socket) {
exec('netsh wlan stop hostednetwork', function(err, out) {
if(socket != undefined) {
(err == null) ? socket.emit('EndLoading', false) : socket.emit('EndLoading', true)
}
})
}
function createWindow () {
win = new BrowserWindow({
width: 415,
height: 550,
backgroundColor: '#23252C',
center: true,
resizable: false,
title: 'Partage de connexion Windows',
frame: false
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// win.webContents.openDevTools()
stop()
win.on('closed', () => {
stop()
setTimeout(function() {
win = null
}, 500)
})
server.listen(7878);
function handler (req, res) {
res.writeHead(500, {"Content-Type": "text/plain"})
res.end('[[ Interdit ]]')
}
io.on('connection', function(socket) {
var debug = function(item) {
socket.emit('debug', item)
}
socket.on('NewWifi', function(wifi) {
start(socket, wifi.ssid, wifi.password)
})
socket.on('StopWifi', function(val) {
(val) ? stop(socket) : null
})
socket.on('Minimize', function(val) {
(val) ? win.minimize() : null;
})
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
stop()
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})