From 6674f33be956803074aa631741c4acce4874cb25 Mon Sep 17 00:00:00 2001 From: Patrick FIc Date: Mon, 20 Oct 2025 21:29:48 -0700 Subject: [PATCH] Minor refactor. --- package-lock.json | 4 ++-- package.json | 2 +- src/main/index.ts | 49 +++++++++++++++++++++++++------------------- src/util/memUsage.ts | 4 ++-- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b53140..ad9a3e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bodyshop-desktop", - "version": "1.0.6-alpha.1", + "version": "1.0.7-alpha.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bodyshop-desktop", - "version": "1.0.6-alpha.1", + "version": "1.0.7-alpha.1", "hasInstallScript": true, "dependencies": { "@apollo/client": "^3.13.6", diff --git a/package.json b/package.json index 7aa79bb..9525b20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bodyshop-desktop", - "version": "1.0.7-alpha.1", + "version": "1.0.7-alpha.2", "description": "Shop Management System Partner", "main": "./out/main/index.js", "author": "Convenient Brands, LLC", diff --git a/src/main/index.ts b/src/main/index.ts index ec3b11d..02286ea 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -54,6 +54,13 @@ let isKeepAliveLaunch = false; // Track if launched via keep-alive const localServer = new LocalServer(); const gotTheLock = app.requestSingleInstanceLock(); +if (!gotTheLock) { + log.warn( + "Another instance is already running and could not obtain mutex lock. Exiting this instance.", + ); + app.quit(); // Quit the app if another instance is already running +} + function createWindow(): void { // Create the browser window. const { width, height, x, y } = store.get("app.windowBounds") as { @@ -451,9 +458,6 @@ 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. @@ -461,6 +465,8 @@ app.whenReady().then(async () => { // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils + log.debug("App is ready, initializing shortcuts and protocol handlers."); + if (platform.isWindows) { app.setAppUserModelId("Shop Partner"); } @@ -492,22 +498,6 @@ app.whenReady().then(async () => { log.warn("Failed to register protocol handler."); } - // Add this event handler for second instance - app.on("second-instance", (_event: Electron.Event, argv: string[]) => { - const url = argv.find((arg) => arg.startsWith(`${protocol}://`)); - if (url) { - if (url.startsWith(`${protocol}://keep-alive`)) { - log.info("Keep-alive protocol received, app is already running."); - // Do nothing if already running - return; - } else { - log.info("Received Media URL: ", url); - openInExplorer(url); - } - } - // No action taken if no URL is provided - }); - //Dynamically load ipcMain handlers once ready. try { const { initializeCronTasks } = await import("./ipc/ipcMainConfig"); @@ -619,6 +609,24 @@ app.on("open-url", (event: Electron.Event, url: string) => { } }); +// Add this event handler for second instance +app.on("second-instance", (_event: Electron.Event, argv: string[]) => { + const url = argv.find((arg) => arg.startsWith(`${protocol}://`)); + if (url) { + if (url.startsWith(`${protocol}://keep-alive`)) { + log.info( + "Keep-alive protocol received, app is already running. Nothing to do.", + ); + // Do nothing if already running + return; + } else { + log.info("Received Media URL: ", url); + openInExplorer(url); + } + } + // No action taken if no URL is provided +}); + // 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. @@ -628,8 +636,7 @@ app.on("window-all-closed", () => { } }); -app.on("before-quit", (props) => { - console.log(props); +app.on("before-quit", () => { preQuitMethods(); }); diff --git a/src/util/memUsage.ts b/src/util/memUsage.ts index 44146d7..c206a54 100644 --- a/src/util/memUsage.ts +++ b/src/util/memUsage.ts @@ -297,8 +297,8 @@ function ongoingMemoryDump() { log.warn("Unexpected error while writing memory stats log", err); } }, - 60 * 60 * 1000, - ); // every 60 minutes + 15 * 60 * 1000, + ); // every 15 minutes } export default ongoingMemoryDump;