Repository navigation
Closed as not planned
Description
Pre-flight checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project uses.
- I have searched the issue tracker for a bug that matches the one I want to file, without success.
Electron Forge version
6.0.4
Electron version
v21.2.3
Operating system
Windows 11 (22H2)
Last known working Electron Forge version
No response
Expected behavior
When server starts and windows appears it should load and render the react app.
Actual behavior
In my case it's not loading react app when starting the app and window appears. It loads the react after few seconds instead. I don't know what's happening. This happens only during development before packaging.
Steps to reproduce
const additionalData = { myKey: "My_KEY" };
const gotTheLock = app.requestSingleInstanceLock(additionalData);
// const controller = new AbortController();
let childMigrateProcess = {};
let childServer = {};
//main window object
let mainWindow = null;
//splash window object
let splashWindow = null;
try {
//setting app name for notification
if (process.platform === "win32") {
app.setAppUserModelId(app.name);
}
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require("electron-squirrel-startup")) {
app.quit();
}
//disabling h/w acceleration
app.disableHardwareAcceleration();
//for app icon in mac
if (process?.platform === "darwin") {
const image = nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIconMac.png")
);
app.dock.setIcon(image);
}
//got the lock
if (!gotTheLock) {
log.error("Unable to get the instance lock. Quitting App");
app?.exit();
} else {
app.on(
"second-instance",
(event, commandLine, workingDirectory, additionalData) => {
// Print out data received from the second instance.
// Someone tried to run a second instance, we should focus our window.
if (splashWindow) {
if (splashWindow?.isMinimized()) splashWindow?.restore();
splashWindow?.focus();
} else if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
}
);
// Create myWindow, load the rest of the app, etc...
//create splash window
const createSplashWindow = () => {
splashWindow = new BrowserWindow({
minWidth: 300,
minHeight: 168,
maxWidth: 500,
maxHeight: 281,
resizable: false,
frame: false,
center: true,
icon:
process.platform === "darwin"
? nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIconMac.png")
)
: nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIcon.png")
),
webPreferences: {
// nodeIntegration: true,
// contextIsolation: false,
// enableRemoteModule: true,
preload: SPLASH_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});
// Open the DevTools.
splashWindow.loadURL(SPLASH_WINDOW_WEBPACK_ENTRY, {
userAgent: "Chrome",
});
splashWindow.on("closed", function () {
splashWindow = null;
});
};
log.info("Inititalized the splash window");
// create main window
const createWindow = ({ width, height }) => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: width,
height: height,
// show: false,
frame: true,
title: "Test App",
icon:
process.platform === "darwin"
? nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIconMac.png")
)
: nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIcon.png")
),
webPreferences: {
// nodeIntegration: true,
nodeIntegrationInWorker: true,
contextIsolation: true,
// enableRemoteModule: true,
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
//attaching the preload script
// preload: path.join(__dirname, "preload.js"),
},
});
//for opening the urls in browsers
mainWindow.webContents.setWindowOpenHandler((edata) => {
shell.openExternal(edata.url);
return { action: "deny" };
});
// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY, { userAgent: "Chrome" });
mainWindow.menuBarVisible = false;
// Open the DevTools.
mainWindow.webContents.openDevTools();
//for close confirmations
mainWindow.on("close", function (e) {
let response = dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Yes", "No"],
title: "Test App",
message: "Are you sure you want to quit?",
icon:
process.platform === "darwin"
? nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIconMac.png")
)
: nativeImage.createFromPath(
path.join(__dirname, "./assets/app_icon/AppIcon.png")
),
});
if (response == 1) e.preventDefault();
});
mainWindow.on("closed", function () {
mainWindow = null;
});
};
log.info("Inititalized the main window");
app.on("ready", () => {
const area = screen.getPrimaryDisplay().workAreaSize;
//creates the splash window
createSplashWindow();
log.info("Created the splash window");
setTimeout(() => {
splashWindow.close();
createWindow({ ...area });
log.info("Created the main window");
}, 5000);
});
}
app.on("browser-window-blur", function () {
globalShortcut.unregisterAll([
"CommandOrControl+R",
"F5",
"CommandOrControl+Alt+I",
"CommandOrControl+Alt+D+T",
"CommandOrControl+Shift+I",
"CommandOrControl+Alt+D+T",
]);
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", async () => {
//close all node child process
try {
//kill the server process
childProcessPromisify(killProcessCommand(), {})
.then((args) => {
log.info("App Closed Successfully");
//server process killed
app.quit();
})
.catch((error) => {
log.warning(`App Closed with error ${error?.message}`);
//any error on killing server process
app.quit();
});
} catch (error) {
log.warning(`App Closed with error ${error?.message}`);
//any error in performing above action
app.quit();
}
});
app.on("activate", () => {
// On OS X 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 (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
My Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>My App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Additional information
It looks like this.
Metadata
Metadata
Assignees
Labels
No labels

Activity
erickzhao commentedon Aug 3, 2023
I'm not really sure I understand what's happening. Is your splash window showing too early before its contents load? You might want to follow the Electron BrowserWindow docs but this doesn't really seem to be a Forge bug to me.
https://www.electronjs.org/docs/latest/api/browser-window#showing-the-window-gracefully
navdeepm20 commentedon Aug 8, 2023
@erickzhao Sorry for my mistake and Thanks for help.