Remove main window opening on imexmedia URL call.

This commit is contained in:
Patrick Fic
2025-05-02 09:55:47 -07:00
parent 29e0f0924b
commit 1935991631

View File

@@ -78,7 +78,7 @@ function createWindow(): void {
// { role: 'appMenu' } // { role: 'appMenu' }
// @ts-ignore // @ts-ignore
...(isMac ...(isMac
? [ ? [
{ {
label: app.name, label: app.name,
submenu: [ submenu: [
@@ -94,7 +94,7 @@ function createWindow(): void {
], ],
}, },
] ]
: []), : []),
// { role: 'fileMenu' } // { role: 'fileMenu' }
{ {
label: "File", label: "File",
@@ -117,7 +117,7 @@ function createWindow(): void {
{ role: "paste" }, { role: "paste" },
// @ts-ignore // @ts-ignore
...(isMac ...(isMac
? [ ? [
{ role: "pasteAndMatchStyle" }, { role: "pasteAndMatchStyle" },
{ role: "delete" }, { role: "delete" },
{ role: "selectAll" }, { role: "selectAll" },
@@ -127,7 +127,7 @@ function createWindow(): void {
submenu: [{ role: "startSpeaking" }, { role: "stopSpeaking" }], submenu: [{ role: "startSpeaking" }, { role: "stopSpeaking" }],
}, },
] ]
: [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]), : [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]),
], ],
}, },
// { role: 'viewMenu' } // { role: 'viewMenu' }
@@ -202,13 +202,13 @@ function createWindow(): void {
click: (): void => { click: (): void => {
/* action for item 1 */ /* action for item 1 */
shell shell
.openPath(log.transports.file.getFile().path) .openPath(log.transports.file.getFile().path)
.catch((error) => { .catch((error) => {
log.error( log.error(
"Failed to open log file:", "Failed to open log file:",
errorTypeCheck(error), errorTypeCheck(error),
); );
}); });
}, },
}, },
{ {
@@ -222,8 +222,8 @@ function createWindow(): void {
click: (): void => { click: (): void => {
shell.openPath(path.dirname(store.path)).catch((error) => { shell.openPath(path.dirname(store.path)).catch((error) => {
log.error( log.error(
"Failed to open config folder:", "Failed to open config folder:",
errorTypeCheck(error), errorTypeCheck(error),
); );
}); });
}, },
@@ -232,7 +232,7 @@ function createWindow(): void {
label: "Log the Store", label: "Log the Store",
click: (): void => { click: (): void => {
log.debug( log.debug(
"Store Contents" + JSON.stringify(store.store, null, 4), "Store Contents" + JSON.stringify(store.store, null, 4),
); );
}, },
}, },
@@ -265,7 +265,7 @@ function createWindow(): void {
await updateKeepAliveMenuItem(); await updateKeepAliveMenuItem();
} catch (error) { } catch (error) {
log.error( log.error(
`Failed to install keep-alive: ${error instanceof Error ? error.message : String(error)}`, `Failed to install keep-alive: ${error instanceof Error ? error.message : String(error)}`,
); );
// Optionally notify user (e.g., via dialog or log) // Optionally notify user (e.g., via dialog or log)
} }
@@ -289,13 +289,13 @@ function createWindow(): void {
{ role: "zoom" }, { role: "zoom" },
// @ts-ignore // @ts-ignore
...(isMac ...(isMac
? [ ? [
{ type: "separator" }, { type: "separator" },
{ role: "front" }, { role: "front" },
{ type: "separator" }, { type: "separator" },
{ role: "window" }, { role: "window" },
] ]
: [{ role: "close" }]), : [{ role: "close" }]),
], ],
}, },
]; ];
@@ -304,29 +304,29 @@ function createWindow(): void {
const updateKeepAliveMenuItem = async (): Promise<void> => { const updateKeepAliveMenuItem = async (): Promise<void> => {
try { try {
const isInstalled = platform.isWindows const isInstalled = platform.isWindows
? await isKeepAliveTaskInstalled() ? await isKeepAliveTaskInstalled()
: platform.isMacOS : platform.isMacOS
? await isKeepAliveAgentInstalled() ? await isKeepAliveAgentInstalled()
: false; : false;
const developmentMenu = template const developmentMenu = template
.find((item) => item.label === "Application") .find((item) => item.label === "Application")
// @ts-ignore // @ts-ignore
?.submenu?.find((item: { id: string }) => item.id === "development") ?.submenu?.find((item: { id: string }) => item.id === "development")
?.submenu as Electron.MenuItemConstructorOptions[]; ?.submenu as Electron.MenuItemConstructorOptions[];
const keepAliveItem = developmentMenu?.find( const keepAliveItem = developmentMenu?.find(
(item) => item.label === "Install Keep Alive", (item) => item.label === "Install Keep Alive",
); );
if (keepAliveItem) { if (keepAliveItem) {
keepAliveItem.enabled = !isInstalled; // Enable if not installed, disable if installed keepAliveItem.enabled = !isInstalled; // Enable if not installed, disable if installed
const menu = Menu.buildFromTemplate(template); const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu); Menu.setApplicationMenu(menu);
log.debug( log.debug(
`Updated Install Keep Alive menu item: enabled=${keepAliveItem.enabled}`, `Updated Install Keep Alive menu item: enabled=${keepAliveItem.enabled}`,
); );
} }
} catch (error) { } catch (error) {
log.error( log.error(
`Error updating Keep Alive menu item: ${error instanceof Error ? error.message : String(error)}`, `Error updating Keep Alive menu item: ${error instanceof Error ? error.message : String(error)}`,
); );
} }
}; };
@@ -336,7 +336,7 @@ function createWindow(): void {
// Update menu item enabled state on app start // Update menu item enabled state on app start
updateKeepAliveMenuItem().catch((error) => { updateKeepAliveMenuItem().catch((error) => {
log.error( log.error(
`Error updating Keep Alive menu item: ${error instanceof Error ? error.message : String(error)}`, `Error updating Keep Alive menu item: ${error instanceof Error ? error.message : String(error)}`,
); );
}); });
@@ -349,7 +349,7 @@ function createWindow(): void {
const fileMenu = template.find((item) => item.label === "Application"); const fileMenu = template.find((item) => item.label === "Application");
// @ts-ignore // @ts-ignore
const hiddenItem = fileMenu?.submenu?.find( const hiddenItem = fileMenu?.submenu?.find(
(item: { id: string }) => item.id === "development", (item: { id: string }) => item.id === "development",
); );
//Adjust the development menu as well. //Adjust the development menu as well.
@@ -406,10 +406,10 @@ function createWindow(): void {
}); });
} else { } else {
mainWindow mainWindow
.loadFile(join(__dirname, "../renderer/index.html")) .loadFile(join(__dirname, "../renderer/index.html"))
.catch((error) => { .catch((error) => {
log.error("Failed to load file:", errorTypeCheck(error)); log.error("Failed to load file:", errorTypeCheck(error));
}); });
} }
if (import.meta.env.DEV) { if (import.meta.env.DEV) {
mainWindow.webContents.openDevTools(); mainWindow.webContents.openDevTools();
@@ -444,9 +444,9 @@ app.whenReady().then(async () => {
// Set the path of electron.exe and your app. // Set the path of electron.exe and your app.
// These two additional parameters are only available on windows. // These two additional parameters are only available on windows.
isDefaultProtocolClient = app.setAsDefaultProtocolClient( isDefaultProtocolClient = app.setAsDefaultProtocolClient(
protocol, protocol,
process.execPath, process.execPath,
[path.resolve(process.argv[1])], [path.resolve(process.argv[1])],
); );
} else { } else {
isDefaultProtocolClient = app.setAsDefaultProtocolClient(protocol); isDefaultProtocolClient = app.setAsDefaultProtocolClient(protocol);
@@ -467,7 +467,6 @@ app.whenReady().then(async () => {
return; // Skip openMainWindow to avoid focusing the window return; // Skip openMainWindow to avoid focusing the window
} else { } else {
openInExplorer(url); openInExplorer(url);
openMainWindow(); // Focus window for non-keep-alive URLs
} }
} else { } else {
openMainWindow(); // Focus window if no URL openMainWindow(); // Focus window if no URL
@@ -543,8 +542,8 @@ app.whenReady().then(async () => {
log.info(`Total downloaded ${progress.transferred}/${progress.total}`); log.info(`Total downloaded ${progress.transferred}/${progress.total}`);
const mainWindow = BrowserWindow.getAllWindows()[0]; const mainWindow = BrowserWindow.getAllWindows()[0];
mainWindow?.webContents.send( mainWindow?.webContents.send(
ipcTypes.toRenderer.updates.downloading, ipcTypes.toRenderer.updates.downloading,
progress, progress,
); );
}); });
autoUpdater.on("update-downloaded", (info) => { autoUpdater.on("update-downloaded", (info) => {
@@ -580,7 +579,6 @@ app.on("open-url", (event: Electron.Event, url: string) => {
return; // Skip openMainWindow to avoid focusing the window return; // Skip openMainWindow to avoid focusing the window
} else { } else {
openInExplorer(url); openInExplorer(url);
openMainWindow(); // Focus window for non-keep-alive URLs
} }
}); });
@@ -638,4 +636,4 @@ function openInExplorer(url: string): void {
shell.openPath(folderPath).catch((error) => { shell.openPath(folderPath).catch((error) => {
log.error("Failed to open folder in explorer:", errorTypeCheck(error)); log.error("Failed to open folder in explorer:", errorTypeCheck(error));
}); });
} }