-
Notifications
You must be signed in to change notification settings - Fork 367
/
electron.js
79 lines (62 loc) · 1.79 KB
/
electron.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
var path = require('path')
var menubar = require('menubar')
var BrowserWindow = require('browser-window')
var ipc = require('ipc')
var icons = {
connected: path.join(__dirname, 'img', 'IconRed.png'),
disconnected: path.join(__dirname, 'img', 'Icon.png')
}
var mb = menubar({
width: 700,
height: 300,
index: 'file://' + path.join(__dirname, 'app.html'),
icon: 'file://' + icons.disconnected
})
var win
mb.app.commandLine.appendSwitch('disable-renderer-backgrounding')
mb.on('ready', function ready () {
console.log('ready')
})
ipc.on('icon', function (ev, key) {
mb.tray.setImage(icons[key])
})
mb.app.on('open-url', function (e, lnk) {
e.preventDefault()
if (mb.window) mb.window.webContents.send('open-url', lnk)
})
ipc.on('terminate', function terminate (ev) {
mb.app.terminate()
})
ipc.on('resize', function resize (ev, data) {
mb.window.setSize(data.width, data.height)
})
ipc.on('error', function error (ev, err) {
console.error(new Error(err.message))
})
ipc.on('create-window', function (ev, config) {
console.log('create-window', [config])
mb.app.dock.show()
win = new BrowserWindow({width: 720, height: 445})
win.loadUrl('file://' + path.join(__dirname, 'screen.html'))
win.on('closed', function () {
mb.app.dock.hide()
mb.window.webContents.send('disconnected', true)
})
ipc.once('window-ready', function () {
// win.webContents.openDevTools()
win.webContents.send('peer-config', config)
})
ipc.on('connected', function () {
mb.window.webContents.send('connected', true)
})
ipc.on('disconnected', function () {
mb.window.webContents.send('disconnected', true)
})
ipc.on('show-window', function () {
win.show()
})
ipc.on('stop-viewing', function () {
win.close()
mb.window.webContents.send('disconnected', true)
})
})