-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
63 lines (53 loc) · 1.47 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
const Browser = require('browser-window')
const HubServer = require('signalhub/server')
const signalhub = require('signalhub')
const querystring = require('querystring')
const app = require('app')
const ipc = require('ipc')
app.once('ready', appReady)
function appReady () {
var hubClient
var hubServer = HubServer({
maxBroadcasts: 100
}).on('subscribe', function (channel) {
console.log('subscribe: %s', channel)
hubClient.broadcast('fresh', channel)
}).on('publish', function (channel, message) {
console.log('publish: %s (%s)', channel, message)
}).listen(function (err) {
if (err) throw err
const port = this.address().port
const uri = `http://localhost:${port}`
hubClient = signalhub('lazurite-client', [ uri ])
hubReady(port)
})
}
function settings () {
return {
'web-security': false,
'show': false
}
}
function hubReady (hubPort) {
var control = new Browser(settings())
var display
const qs = '?' + querystring.stringify({
hub: hubPort
})
control.loadUrl('file://' + require.resolve('./index.html') + qs)
control.maximize()
setTimeout(function () {
control.show()
}, 150)
ipc.on('app-main-open-preview', function () {
if (display) {
display.close()
}
var me = display = new Browser(settings())
display.loadUrl('file://' + require.resolve('./display.html') + qs)
display.show()
display.once('closed', function () {
if (display === me) display = null
})
})
}