Minor app fixes and improvements.
This commit is contained in:
@@ -26,6 +26,8 @@ const isMac = process.platform === "darwin";
|
||||
let isAppQuitting = false; //Needed on Mac as an override to allow us to fully quit the app.
|
||||
// Initialize the server
|
||||
const localServer = new LocalServer();
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
|
||||
function createWindow(): void {
|
||||
// Create the browser window.
|
||||
const { width, height, x, y } = store.get("app.windowBounds") as {
|
||||
@@ -45,6 +47,7 @@ function createWindow(): void {
|
||||
minHeight: 400,
|
||||
//autoHideMenuBar: true,
|
||||
...(process.platform === "linux" ? { icon } : {}),
|
||||
title: "Shop Partner",
|
||||
webPreferences: {
|
||||
preload: join(__dirname, "../preload/index.js"),
|
||||
sandbox: false,
|
||||
@@ -260,6 +263,9 @@ function createWindow(): void {
|
||||
}
|
||||
}
|
||||
|
||||
if (!gotTheLock) {
|
||||
app.quit(); // Quit the app if another instance is already running
|
||||
}
|
||||
// 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.
|
||||
@@ -274,6 +280,12 @@ app.whenReady().then(async () => {
|
||||
optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
|
||||
// Add this event handler for second instance
|
||||
app.on("second-instance", () => {
|
||||
// Someone tried to run a second instance, we should focus our window
|
||||
openMainWindow();
|
||||
});
|
||||
|
||||
//Dynamically load ipcMain handlers once ready.
|
||||
try {
|
||||
// Replace 'path/to/your/file' with the actual path to your file
|
||||
@@ -365,6 +377,14 @@ app.on("window-all-closed", () => {
|
||||
|
||||
app.on("before-quit", () => {
|
||||
localServer.stop();
|
||||
const currentSetting = store.get("app.openOnStartup") as boolean;
|
||||
store.set("app.openOnStartup", !currentSetting);
|
||||
log.info("Open on startup set to", !currentSetting);
|
||||
app.setLoginItemSettings({
|
||||
enabled: true, //This is a windows only command. Updates the task manager and registry.
|
||||
openAtLogin: !currentSetting,
|
||||
});
|
||||
|
||||
isAppQuitting = true;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user