From f5a32f2304be854f51ed35c589d2a422c4b4e745 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 29 May 2026 15:25:36 -0400 Subject: [PATCH] ESDP - List Parser - Notification fixes 0.0.6 --- package.json | 2 +- src/main/index.ts | 27 +++++++++++++++--- src/main/ipc/ipcMainHandler.settings.ts | 4 +-- src/main/watcher/watcher.ts | 38 +++++++++++++++++-------- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index cfd4e77..f423a89 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esdp", "productName": "EMS Uploader", - "version": "0.0.5", + "version": "0.0.6", "description": "EMS Uploader", "main": "./out/main/index.js", "author": "ImEX Systems Inc.", diff --git a/src/main/index.ts b/src/main/index.ts index 4b3b7f7..e7ec2f7 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -471,6 +471,10 @@ function createWindow(): BrowserWindow { // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(async () => { + if (!gotTheLock) { + return; + } + // 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 @@ -478,7 +482,6 @@ app.whenReady().then(async () => { if (platform.isWindows) { app.setAppUserModelId(appId); - await repairWindowsProtocolRegistration(); } app.on("browser-window-created", (_, window) => { @@ -510,6 +513,10 @@ app.whenReady().then(async () => { log.warn("Failed to register protocol handler."); } + if (platform.isWindows) { + await repairWindowsProtocolRegistration(); + } + //Dynamically load ipcMain handlers once ready. try { await import("./ipc/ipcMainConfig"); @@ -705,7 +712,12 @@ function runRegCommand(args: string[]): Promise { } function getProtocolLaunchArgs(): string[] | null { - if (!is.dev && !process.defaultApp) { + const isRunningElectronBinary = + path.basename(process.execPath).toLowerCase() === "electron.exe"; + const isDevelopmentRuntime = + is.dev || process.defaultApp || !app.isPackaged || isRunningElectronBinary; + + if (!isDevelopmentRuntime) { return null; } @@ -714,12 +726,19 @@ function getProtocolLaunchArgs(): string[] | null { .filter((arg) => !arg.startsWith(`${protocol}://`)); if (launchArgs.length === 0) { - return null; + return [app.getAppPath()]; } - return launchArgs.map((arg) => + const normalizedLaunchArgs = launchArgs.map((arg) => arg.startsWith("-") ? arg : path.resolve(arg), ); + const hasAppPathArg = normalizedLaunchArgs.some( + (arg) => !arg.startsWith("-"), + ); + + return hasAppPathArg + ? normalizedLaunchArgs + : [app.getAppPath(), ...normalizedLaunchArgs]; } function quoteCommandArg(arg: string): string { diff --git a/src/main/ipc/ipcMainHandler.settings.ts b/src/main/ipc/ipcMainHandler.settings.ts index f9dddbf..90b0ae3 100644 --- a/src/main/ipc/ipcMainHandler.settings.ts +++ b/src/main/ipc/ipcMainHandler.settings.ts @@ -87,8 +87,8 @@ const SettingsWatcherPollingSet = async ( const { enabled, interval } = pollingSettings; Store.set("settings.polling", { enabled, interval }); - await StopWatcher(); - await StartWatcher(); + await StopWatcher({ notifyOnStopped: false }); + await StartWatcher({ notifyOnStarted: false }); return { enabled, interval }; }; diff --git a/src/main/watcher/watcher.ts b/src/main/watcher/watcher.ts index c42689c..40ee31b 100644 --- a/src/main/watcher/watcher.ts +++ b/src/main/watcher/watcher.ts @@ -14,6 +14,11 @@ let watcherReady = false; type StartWatcherOptions = { notifyOnNoPaths?: boolean; + notifyOnStarted?: boolean; +}; + +type StopWatcherOptions = { + notifyOnStopped?: boolean; }; function getValidWatcherPaths(filePaths: string[]): string[] { @@ -30,7 +35,7 @@ function getValidWatcherPaths(filePaths: string[]): string[] { async function StartWatcher( options: StartWatcherOptions = {}, ): Promise { - const { notifyOnNoPaths = true } = options; + const { notifyOnNoPaths = true, notifyOnStarted = true } = options; const configuredFilePaths: string[] = store.get("settings.filepaths") || []; const filePaths = getValidWatcherPaths(configuredFilePaths); @@ -116,7 +121,7 @@ async function StartWatcher( // errorTypeCheck(error) // ); }) - .on("ready", onWatcherReady); + .on("ready", () => onWatcherReady({ notifyOnStarted })); // .on("raw", function (event, path, details) { // // This event should be triggered everytime something happens. // // console.log("Raw event info:", event, path, details); @@ -139,21 +144,28 @@ function addWatcherPath(path: string | string[]): void { } } -function onWatcherReady(): void { +function onWatcherReady({ + notifyOnStarted, +}: { + notifyOnStarted: boolean; +}): void { if (watcher) { const mainWindow = getMainWindow(); watcherReady = true; - showNotification({ - title: "Watcher Started", - body: "Newly exported estimates will be automatically uploaded.", - }); + if (notifyOnStarted) { + showNotification({ + title: "Watcher Started", + body: "Newly exported estimates will be automatically uploaded.", + }); + } log.info("Confirmed watched paths:", watcher.getWatched()); setWatcherTrayStatus(true); mainWindow?.webContents.send(ipcTypes.toRenderer.watcher.started); } } -async function StopWatcher(): Promise { +async function StopWatcher(options: StopWatcherOptions = {}): Promise { + const { notifyOnStopped = true } = options; const mainWindow = getMainWindow(); if (watcher) { @@ -164,10 +176,12 @@ async function StopWatcher(): Promise { setWatcherTrayStatus(false); mainWindow?.webContents.send(ipcTypes.toRenderer.watcher.stopped); - showNotification({ - title: "Watcher Stopped", - body: "Estimates will not be automatically uploaded.", - }); + if (notifyOnStopped) { + showNotification({ + title: "Watcher Stopped", + body: "Estimates will not be automatically uploaded.", + }); + } return true; } return false;