git ssb

5+

Matt McKegg / ferment



Tree: ce8c9a23510ffcaae086aac41d0d04be17ab0af0

Files: ce8c9a23510ffcaae086aac41d0d04be17ab0af0 / lib / background-ipc.js

1422 bytesRaw
1var electron = require('electron')
2
3module.exports = function setupIpc (windows) {
4 var messageQueueMainToBackground = []
5
6 electron.ipcMain.once('ipcBackgroundReady', function (e) {
7 electron.app.ipcBackgroundReady = true
8 messageQueueMainToBackground.forEach(function (message) {
9 windows.background.send(message.name, ...message.args)
10 })
11 })
12
13 electron.ipcMain.once('background-log', function (e, ...args) {
14 console.log(...args)
15 })
16
17 var oldEmit = electron.ipcMain.emit
18 electron.ipcMain.emit = function (name, e, ...args) {
19 // Relay messages between the main window and the background window
20 if (name.startsWith('bg-') && !electron.app.isQuitting) {
21 if (e.sender.browserWindowOptions.title === 'ferment-background-window') {
22 // Send message to main window
23 if (windows.main) {
24 windows.main.send(name, ...args)
25 }
26
27 windows.dialogs.forEach(window => window.send(name, ...args))
28 } else if (electron.app.ipcBackgroundReady) {
29 // Send message to webtorrent window
30 windows.background.send(name, ...args)
31 } else {
32 // Queue message for background window, it hasn't finished loading yet
33 messageQueueMainToBackground.push({
34 name: name,
35 args: args
36 })
37 }
38 return
39 }
40
41 // Emit all other events normally
42 oldEmit.call(electron.ipcMain, name, e, ...args)
43 }
44}
45

Built with git-ssb-web