Minor app fixes and improvements.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user