mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-10-01 11:22:53 +00:00
1. Watch enabled successfully.
2. Reloading electron after build.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ let appApi, menu, dialogApi, notification, tray, webContents;
|
||||
let globalShortcut, shellApi, screen, clipboard, autoUpdater;
|
||||
let commandLine, browserView;
|
||||
let splashScreen, hostHook;
|
||||
let mainWindowId;
|
||||
|
||||
let manifestJsonFileName = 'electron.manifest.json';
|
||||
let watchable = false;
|
||||
@@ -26,7 +27,6 @@ let manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);
|
||||
// if watch is enabled lets change the path
|
||||
if (watchable) {
|
||||
currentBinPath = path.join(__dirname, '../../'); // go to project directory
|
||||
currentBinPath = currentBinPath.substr(0, currentBinPath.length - 1);
|
||||
manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ app.on('ready', () => {
|
||||
|
||||
});
|
||||
|
||||
app.on("mainWindow", id => {
|
||||
mainWindowId = id;
|
||||
console.log(` Main Window ID = ${id}`);
|
||||
})
|
||||
|
||||
function isSplashScreenEnabled() {
|
||||
if (manifestJsonFile.hasOwnProperty('splashscreen')) {
|
||||
if (manifestJsonFile.splashscreen.hasOwnProperty('imageFile')) {
|
||||
@@ -131,6 +136,11 @@ function startSocketApiBridge(port) {
|
||||
global['electronsocket'].setMaxListeners(0);
|
||||
console.log('ASP.NET Core Application connected...', 'global.electronsocket', global['electronsocket'].id, new Date());
|
||||
|
||||
// send signal to reload
|
||||
if (mainWindowId != undefined) {
|
||||
app.emit("hot-reload", mainWindowId);
|
||||
}
|
||||
|
||||
appApi = require('./api/app')(socket, app);
|
||||
browserWindows = require('./api/browserWindows')(socket, app);
|
||||
commandLine = require('./api/commandLine')(socket, app);
|
||||
@@ -213,14 +223,12 @@ function startAspCoreBackendWithWatch(electronPort) {
|
||||
function startBackend(aspCoreBackendPort) {
|
||||
console.log('ASP.NET Core Watch Port: ' + aspCoreBackendPort);
|
||||
loadURL = `http://localhost:${aspCoreBackendPort}`;
|
||||
const parameters = ['watch','run', `--project ${currentBinPath}`, `/electronPort=${electronPort}`, `/electronWebPort=${aspCoreBackendPort}`];
|
||||
const parameters = ['watch', 'run', `/electronPort=${electronPort}`, `/electronWebPort=${aspCoreBackendPort}`];
|
||||
|
||||
console.log(currentBinPath);
|
||||
var options = {
|
||||
cwd: currentBinPath,
|
||||
env: {
|
||||
PATH: process.env.PATH
|
||||
}
|
||||
env: process.env,
|
||||
};
|
||||
apiProcess = cProcess('dotnet', parameters, options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user