|
|
@@ -2,9 +2,13 @@ const { app, BrowserWindow, dialog, ipcMain, shell } = require('electron'); |
|
|
|
const path = require('path'); |
|
|
|
const url = require('url'); |
|
|
|
const { initialStorageEvents, storage } = require('./storage'); |
|
|
|
const { initialWebsocketEvents } = require('./socket'); |
|
|
|
const { Subject } = require('./tool'); |
|
|
|
|
|
|
|
let mainWindow; |
|
|
|
|
|
|
|
const socketMsgSubject = new Subject(); |
|
|
|
|
|
|
|
function createWindow() { |
|
|
|
//创建窗口 |
|
|
|
mainWindow = new BrowserWindow({ |
|
|
@@ -44,12 +48,18 @@ function createWindow() { |
|
|
|
}), |
|
|
|
); |
|
|
|
} |
|
|
|
// 加载初始localStorage数据 |
|
|
|
const onMessageReceive = (message) => { |
|
|
|
mainWindow.webContents.send('socket:on-message', message); |
|
|
|
}; |
|
|
|
|
|
|
|
mainWindow.webContents.on('did-finish-load', () => { |
|
|
|
// 加载初始localStorage数据 |
|
|
|
mainWindow.webContents.send('initialStorageData', storage.getAllItem()); |
|
|
|
socketMsgSubject.add(onMessageReceive); |
|
|
|
}); |
|
|
|
mainWindow.on('closed', () => { |
|
|
|
mainWindow = null; |
|
|
|
socketMsgSubject.remove(onMessageReceive); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@@ -106,3 +116,7 @@ app.on('window-all-closed', () => { |
|
|
|
app.quit(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
initialWebsocketEvents(function onMessage(message) { |
|
|
|
socketMsgSubject.notify(message); |
|
|
|
}); |