mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-10-07 14:19:13 +00:00
1. Watch enabled successfully.
2. Reloading electron after build.
This commit is contained in:
@@ -3,6 +3,7 @@ const path = require('path');
|
||||
const windows: Electron.BrowserWindow[] = [];
|
||||
let readyToShowWindowsIds: number[] = [];
|
||||
let window, lastOptions, electronSocket;
|
||||
let mainWindowId;
|
||||
|
||||
export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
@@ -199,6 +200,23 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true } };
|
||||
}
|
||||
|
||||
// lets not recreate the same window if its already open
|
||||
let nWindow = null;
|
||||
|
||||
if (app.commandLine.hasSwitch('watch')) {
|
||||
(app as any).on('hot-reload', (id) => {
|
||||
mainWindowId = id;
|
||||
nWindow = getWindowById(mainWindowId);
|
||||
if (nWindow) {
|
||||
nWindow.reload();
|
||||
if (loadUrl) {
|
||||
nWindow.loadURL(loadUrl);
|
||||
}
|
||||
return;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
window = new BrowserWindow(options);
|
||||
window.on('ready-to-show', () => {
|
||||
if (readyToShowWindowsIds.includes(window.id)) {
|
||||
@@ -245,6 +263,12 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
console.log('auto clear-cache active for new window.');
|
||||
}
|
||||
|
||||
// set main window id
|
||||
if (mainWindowId == undefined) {
|
||||
mainWindowId = window.id;
|
||||
app.emit("mainWindow", mainWindowId);
|
||||
}
|
||||
|
||||
windows.push(window);
|
||||
electronSocket.emit('BrowserWindowCreated', window.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user