Minor refactor.

This commit is contained in:
Patrick FIc
2025-10-20 21:29:48 -07:00
parent 7742d6f89f
commit 6674f33be9
4 changed files with 33 additions and 26 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bodyshop-desktop", "name": "bodyshop-desktop",
"version": "1.0.6-alpha.1", "version": "1.0.7-alpha.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bodyshop-desktop", "name": "bodyshop-desktop",
"version": "1.0.6-alpha.1", "version": "1.0.7-alpha.1",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@apollo/client": "^3.13.6", "@apollo/client": "^3.13.6",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bodyshop-desktop", "name": "bodyshop-desktop",
"version": "1.0.7-alpha.1", "version": "1.0.7-alpha.2",
"description": "Shop Management System Partner", "description": "Shop Management System Partner",
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": "Convenient Brands, LLC", "author": "Convenient Brands, LLC",

View File

@@ -54,6 +54,13 @@ let isKeepAliveLaunch = false; // Track if launched via keep-alive
const localServer = new LocalServer(); const localServer = new LocalServer();
const gotTheLock = app.requestSingleInstanceLock(); 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 { function createWindow(): void {
// Create the browser window. // Create the browser window.
const { width, height, x, y } = store.get("app.windowBounds") as { 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 // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // 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 // Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production. // and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
log.debug("App is ready, initializing shortcuts and protocol handlers.");
if (platform.isWindows) { if (platform.isWindows) {
app.setAppUserModelId("Shop Partner"); app.setAppUserModelId("Shop Partner");
} }
@@ -492,22 +498,6 @@ app.whenReady().then(async () => {
log.warn("Failed to register protocol handler."); 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. //Dynamically load ipcMain handlers once ready.
try { try {
const { initializeCronTasks } = await import("./ipc/ipcMainConfig"); 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 // 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 // for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q. // explicitly with Cmd + Q.
@@ -628,8 +636,7 @@ app.on("window-all-closed", () => {
} }
}); });
app.on("before-quit", (props) => { app.on("before-quit", () => {
console.log(props);
preQuitMethods(); preQuitMethods();
}); });

View File

@@ -297,8 +297,8 @@ function ongoingMemoryDump() {
log.warn("Unexpected error while writing memory stats log", err); log.warn("Unexpected error while writing memory stats log", err);
} }
}, },
60 * 60 * 1000, 15 * 60 * 1000,
); // every 60 minutes ); // every 15 minutes
} }
export default ongoingMemoryDump; export default ongoingMemoryDump;