feature/IO-3205-Paint-Scale-Integrations: Pre Protocol Handler Keep ALive.

This commit is contained in:
Dave Richer
2025-04-29 20:41:15 -04:00
parent 122f4194f5
commit 7933a8965c
4 changed files with 62 additions and 57 deletions

View File

@@ -26,7 +26,7 @@ nsis:
shortcutName: ${productName}
uninstallDisplayName: ${productName}
createDesktopShortcut: always
requestExecutionLevel: admin # Ensure elevated privileges
perMachine: true # Ensure elevated privileges
include: "scripts/installer.nsh" # Reference NSIS script from scripts directory
mac:
entitlementsInherit: build/entitlements.mac.plist
@@ -59,10 +59,6 @@ linux:
category: Utility
desktop:
MimeType: x-scheme-handler/imexmedia;
afterInstall: |
# Install .desktop file for protocol handling
cp scripts/imex-shop-partner.desktop $HOME/.local/share/applications/
update-desktop-database $HOME/.local/share/applications/
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false

View File

@@ -26,7 +26,7 @@ nsis:
shortcutName: ${productName}
uninstallDisplayName: ${productName}
createDesktopShortcut: always
requestExecutionLevel: admin # Ensure elevated privileges
perMachine: true # Ensure elevated privileges
include: "scripts/installer.nsh" # Reference NSIS script from scripts directory
mac:
entitlementsInherit: build/entitlements.mac.plist
@@ -59,10 +59,6 @@ linux:
category: Utility
desktop:
MimeType: x-scheme-handler/imexmedia;
afterInstall: |
# Install .desktop file for protocol handling
cp scripts/rome-shop-partner.desktop $HOME/.local/share/applications/
update-desktop-database $HOME/.local/share/applications/
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false

View File

@@ -251,12 +251,16 @@ function createWindow(): void {
click: async (): Promise<void> => {
try {
if (platform.isWindows) {
log.debug("Creating Windows keep-alive task");
await setupKeepAliveTask();
log.info("Successfully installed Windows keep-alive task");
} else if (platform.isMacOS) {
log.debug("Creating macOS keep-alive agent");
await setupKeepAliveAgent();
log.info("Successfully installed macOS keep-alive agent");
}
// Wait to ensure task/agent is registered
await new Promise((resolve) => setTimeout(resolve, 1500));
// Rebuild menu and update enabled state
await updateKeepAliveMenuItem();
} catch (error) {
@@ -397,11 +401,13 @@ function createWindow(): void {
// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]).catch(error => {
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]).catch((error) => {
log.error("Failed to load URL:", errorTypeCheck(error));
});
} else {
mainWindow.loadFile(join(__dirname, "../renderer/index.html")).catch(error => {
mainWindow
.loadFile(join(__dirname, "../renderer/index.html"))
.catch((error) => {
log.error("Failed to load file:", errorTypeCheck(error));
});
}
@@ -453,16 +459,18 @@ app.whenReady().then(async () => {
// Add this event handler for second instance
app.on("second-instance", (_event: Electron.Event, argv: string[]) => {
// Someone tried to run a second instance, we should focus our window
openMainWindow();
const url = argv.find((arg) => arg.startsWith(`${protocol}://`));
if (url) {
if (url.startsWith(`${protocol}://keep-alive`)) {
log.info("Keep-alive protocol received, app is already running.");
// Do nothing if already running
return; // Skip openMainWindow to avoid focusing the window
} else {
openInExplorer(url);
openMainWindow(); // Focus window for non-keep-alive URLs
}
} else {
openMainWindow(); // Focus window if no URL
}
});
@@ -564,10 +572,15 @@ app.on("open-url", (event: Electron.Event, url: string) => {
//Don't do anything for now. We just want to open the app.
if (url.startsWith(`${protocol}://keep-alive`)) {
log.info("Keep-alive protocol received.");
if (BrowserWindow.getAllWindows().length === 0) {
isKeepAliveLaunch = true;
openMainWindow();
openMainWindow(); // Launch app if not running
}
// Do nothing if already running
return; // Skip openMainWindow to avoid focusing the window
} else {
openInExplorer(url);
openMainWindow(); // Focus window for non-keep-alive URLs
}
});

View File

@@ -7,8 +7,8 @@ const execPromise = promisify(exec);
export async function setupKeepAliveTask(): Promise<void> {
const taskName = "ImEXShopPartnerKeepAlive";
const protocolUrl = "imexmedia://keep-alive";
// Use PowerShell with -ExecutionPolicy Bypass to open the URL
const command = `powershell.exe -ExecutionPolicy Bypass -Command "Start-Process '${protocolUrl}'"`;
// Use rundll32.exe to silently open the URL as a protocol
const command = `rundll32.exe url.dll,OpenURL "${protocolUrl}"`;
// Escape quotes for schtasks /tr parameter
const escapedCommand = command.replace(/"/g, '\\"');