1. Watch enabled successfully.

2. Reloading electron after build.
This commit is contained in:
Syed Adeel Hassan Rizvi
2020-05-01 17:29:56 +10:00
parent 2987e3143d
commit 00eb9869dc
7 changed files with 77 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ const path = require('path');
const windows = [];
let readyToShowWindowsIds = [];
let window, lastOptions, electronSocket;
let mainWindowId;
module.exports = (socket, app) => {
electronSocket = socket;
socket.on('register-browserWindow-ready-to-show', (id) => {
@@ -168,6 +169,21 @@ module.exports = (socket, app) => {
else if (!options.webPreferences) {
options = { ...options, webPreferences: { nodeIntegration: true } };
}
// lets not recreate the same window if its already open
let nWindow = null;
if (app.commandLine.hasSwitch('watch')) {
app.on('hot-reload', (id) => {
mainWindowId = id;
nWindow = getWindowById(mainWindowId);
if (nWindow) {
nWindow.reload();
if (loadUrl) {
nWindow.loadURL(loadUrl);
}
return;
}
});
}
window = new electron_1.BrowserWindow(options);
window.on('ready-to-show', () => {
if (readyToShowWindowsIds.includes(window.id)) {
@@ -209,6 +225,11 @@ module.exports = (socket, app) => {
window.webContents.session.clearCache();
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);
});