Using Electron to rebuild a pre-existing web app, the main.js file in electron is kept simple:
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1600,
height: 900
})
// and load the index.html of the app.
mainWindow.loadFile('dist/mysite/index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
When running the app using 'electron .', everything works fine except for the line concerning location. The issue lies within the login submit form action. After logging in, the line 'location.reload()' does not work as intended:
this.http.post(this.url + ':8000/' + 'auth/jwt/create/', this.validateForm.value)
.subscribe((res: any) => {
localStorage.setItem('token', res.token);
// This LINE NOT WORK
location.reload();
// //////
// this.router.navigate([this.router.url]);
// this.router.navigate(['./']);
console.log(location);
}, (err: any) => {
if (err.status === 400) {
this.msg = err.error.non_field_errors[0];
console.log(err);
} else {
this.msg = err;
console.log(err);
}
this.isVisible = true;
});
Attempts have been made to get the web page to navigate to the target URL, but methods such as location.reload(), location.replace, and router.navigate have all failed. Interestingly, when using 'ng serve' and opening the site in Chrome, 'location.reload()' works without any issues. What could be causing this inconsistency? Any guidance or suggestions would be greatly appreciated.
EDIT:
Upon execution of location.reload(), the page goes blank. Additionally, when console.log(location)
is performed, the href reads chrome-error://chromewebdata/
console.log(location)
Location {replace: ƒ, assign: ƒ, href: "chrome-error://chromewebdata/", ancestorOrigins: DOMStringList, origin: "null", …}