diff --git a/.circleci/config.yml b/.circleci/config.yml index 183997f..d159db4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -60,7 +60,6 @@ workflows: deploy_and_build: jobs: - partner-win-build - # - partner-mac-build: - # filters: - # branches: - # only: main + filters: + branches: + only: main diff --git a/src/main/http-server/http-server.ts b/src/main/http-server/http-server.ts index f4513c5..64bfcc9 100644 --- a/src/main/http-server/http-server.ts +++ b/src/main/http-server/http-server.ts @@ -148,17 +148,23 @@ export default class LocalServer { public start(): void { try { - this.server = this.app.listen(this.PORT, (error: Error | undefined) => { - if (error) { + this.server = http.createServer(this.app); + + this.server.on("error", (error: NodeJS.ErrnoException) => { + if (error.code === "EADDRINUSE") { log.error( - `[HTTP Server] Error starting server: ${errorTypeCheck(error)}`, + `[HTTP Server] Port ${this.PORT} is already in use. Please use a different port.`, ); } else { - log.info( - `[HTTP Server] Local HTTP server running on port ${this.PORT}`, - ); + log.error(`[HTTP Server] Server error: ${error.message}`); } }); + + this.server.listen(this.PORT, () => { + log.info( + `[HTTP Server] Local HTTP server running on port ${this.PORT}`, + ); + }); } catch (error: unknown) { log.error("[HTTP Server] Error starting server", errorTypeCheck(error)); } diff --git a/src/main/index.ts b/src/main/index.ts index 73fc1e8..465ae04 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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; }); diff --git a/src/main/ipc/ipcMainHandler.user.ts b/src/main/ipc/ipcMainHandler.user.ts index 4a00f4a..f53ff5c 100644 --- a/src/main/ipc/ipcMainHandler.user.ts +++ b/src/main/ipc/ipcMainHandler.user.ts @@ -45,8 +45,10 @@ const ipcMainHandleAuthStateChanged = async ( const convCo = activeBodyshop.bodyshops[0].convenient_company; if (convCo === "alpha") { autoUpdater.channel = "alpha"; + log.debug("Setting update channel to ALPHA channel."); } else if (convCo === "beta") { autoUpdater.channel = "beta"; + log.debug("Setting update channel to BETA channel."); } } catch (error) { log.error( diff --git a/src/renderer/index.html b/src/renderer/index.html index 027e508..05d34b0 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -2,7 +2,7 @@
-