diff --git a/src/main/index.ts b/src/main/index.ts index 7d9ca9b..b294823 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,4 +1,4 @@ -import { electronApp, is, optimizer } from "@electron-toolkit/utils"; +import { is, optimizer } from "@electron-toolkit/utils"; import Sentry from "@sentry/electron/main"; import { app, @@ -20,7 +20,6 @@ import { import ipcTypes from "../util/ipcTypes.json"; import ImportJob from "./decoder/decoder"; import LocalServer from "./http-server/http-server"; -import { TestQB } from "./quickbooks-desktop/quickbooks-desktop"; import store from "./store/store"; import { GetAllEnvFiles } from "./watcher/watcher"; @@ -30,7 +29,7 @@ Sentry.init({ log.initialize(); const isMac: boolean = process.platform === "darwin"; -const protocol: string = "shopprt"; +const protocol: string = "imexmedia"; let isAppQuitting = false; //Needed on Mac as an override to allow us to fully quit the app. // Initialize the server const localServer = new LocalServer(); @@ -147,18 +146,74 @@ function createWindow(): void { }, }, { - label: "Connect to Test", - checked: store.get("app.isTest") as boolean, - visible: false, - type: "checkbox", - id: "toggleTest", - click: (): void => { - const currentSetting = store.get("app.isTest") as boolean; - store.set("app.isTest", !currentSetting); - log.info("Setting isTest to: ", !currentSetting); - app.relaunch(); // Relaunch the app - app.exit(0); // Exit the current instance - }, + label: "Development", + id: "development", + visible: import.meta.env.DEV, + submenu: [ + { + label: "Connect to Test", + checked: store.get("app.isTest") as boolean, + visible: false, + type: "checkbox", + id: "toggleTest", + click: (): void => { + const currentSetting = store.get("app.isTest") as boolean; + store.set("app.isTest", !currentSetting); + log.info("Setting isTest to: ", !currentSetting); + app.relaunch(); // Relaunch the app + app.exit(0); // Exit the current instance + }, + }, + { + label: "Check for updates", + click: (): void => { + autoUpdater.checkForUpdates(); + }, + }, + { + label: "Open Log File", + click: (): void => { + /* action for item 1 */ + shell.openPath(log.transports.file.getFile().path); + }, + }, + { + label: "Clear Log", + click: (): void => { + log.transports.file.getFile().clear(); + }, + }, + { + label: "Open Config Folder", + click: (): void => { + shell.openPath(path.dirname(store.path)); + }, + }, + { + label: "Log the Store", + click: (): void => { + log.debug( + "Store Contents" + JSON.stringify(store.store, null, 4), + ); + }, + }, + { + type: "separator", + }, + + // { + // label: "Decode Hardcoded Estimate", + // click: (): void => { + // ImportJob(`C:\\EMS\\CCC\\9ee762f4.ENV`); + // }, + // }, + { + label: "Add All Estimates in watched directories", + click: (): void => { + GetAllEnvFiles().forEach((file) => ImportJob(file)); + }, + }, + ], }, ], }, @@ -178,64 +233,6 @@ function createWindow(): void { : [{ role: "close" }]), ], }, - - { - label: "Development", - submenu: [ - { - label: "Check for updates", - click: (): void => { - autoUpdater.checkForUpdates(); - }, - }, - { - label: "Open Log Folder", - click: (): void => { - /* action for item 1 */ - shell.openPath(log.transports.file.getFile().path); - }, - }, - { - label: "Clear Log", - click: (): void => { - log.transports.file.getFile().clear(); - }, - }, - { - label: "Open Config", - click: (): void => { - shell.openPath(path.dirname(store.path)); - }, - }, - { - label: "Log the Store", - click: (): void => { - log.debug("Store Contents" + JSON.stringify(store.store, null, 4)); - }, - }, - { - type: "separator", - }, - { - label: "Temp Test Action", - click: (): void => { - TestQB(); - }, - }, - { - label: "Decode Hardcoded Estimate", - click: (): void => { - ImportJob(`C:\\EMS\\CCC\\9ee762f4.ENV`); - }, - }, - { - label: "Add All Estimes in watched directories", - click: (): void => { - GetAllEnvFiles().forEach((file) => ImportJob(file)); - }, - }, - ], - }, ]; const menu: Electron.Menu = Menu.buildFromTemplate(template); @@ -249,8 +246,10 @@ function createWindow(): void { // Find the menu item dynamically by its id const fileMenu = template.find((item) => item.label === "Application"); const hiddenItem = fileMenu?.submenu?.find( - (item) => item.id === "toggleTest", + (item) => item.id === "development", ); + //Adjust the development menu as well. + if (hiddenItem) { hiddenItem.visible = true; // Update the visibility dynamically const menu: Electron.Menu = Menu.buildFromTemplate(template); @@ -311,9 +310,6 @@ if (!gotTheLock) { // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(async () => { - // Set app user model id for windows - electronApp.setAppUserModelId("com.convenient-brands.partner"); - // 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 @@ -334,8 +330,7 @@ app.whenReady().then(async () => { openMainWindow(); const url = argv.find((arg) => arg.startsWith(`${protocol}://`)); if (url) { - console.log("App launched with URL:", url); - // Handle the URL. Not doing anything for now. + openInExplorer(url); } }); @@ -419,15 +414,11 @@ app.whenReady().then(async () => { }); }); -app.on( - "open-url", - ( - event: Electron.Event, //, _url: string - ) => { - event.preventDefault(); - //Don't do anythign for now. We just want to open the app. - }, -); +app.on("open-url", (event: Electron.Event, url: string) => { + event.preventDefault(); + //Don't do anything for now. We just want to open the app. + openInExplorer(url); +}); // 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 @@ -461,3 +452,9 @@ function openMainWindow(): void { createWindow(); } } + +function openInExplorer(url: string): void { + const folderPath: string = decodeURIComponent(url.split(`${protocol}://`)[1]); + log.info("Opening folder in explorer", path.dirname(folderPath)); + shell.openPath(path.dirname(folderPath)); +}