From 2e7d255b20028884fcf7cc5521e32817948e3e20 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 3 Aug 2026 01:14:06 +0100 Subject: [PATCH] Refactor patch-windows-binaries script to improve error handling and target specific executables - Replaced the dynamic executable discovery with a predefined set of target executables (`launcher.exe`, `deeplink.exe`) for clarity. - Added checks to skip missing executables and improved error handling during the patching process, enhancing robustness and user feedback. --- scripts/patch-windows-binaries.mjs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/patch-windows-binaries.mjs b/scripts/patch-windows-binaries.mjs index 4926639..41085bc 100644 --- a/scripts/patch-windows-binaries.mjs +++ b/scripts/patch-windows-binaries.mjs @@ -1,9 +1,9 @@ -import { existsSync, readdirSync } from 'node:fs' +import { existsSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' import rcedit from 'rcedit' -const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') +const PATCH_TARGETS = new Set(['launcher.exe', 'deeplink.exe']) export async function patchWindowsBinaries(appDir) { if (process.platform !== 'win32') { @@ -15,16 +15,24 @@ export async function patchWindowsBinaries(appDir) { throw new Error(`patch-windows-binaries: bin directory not found at ${binDir}`) } - const executables = readdirSync(binDir).filter((name) => - name.toLowerCase().endsWith('.exe') - ) - - for (const executable of executables) { + for (const executable of PATCH_TARGETS) { const executablePath = path.join(binDir, executable) - await rcedit(executablePath, { - 'requested-execution-level': 'asInvoker' - }) - console.log(`patch-windows-binaries: set asInvoker on ${executablePath}`) + if (!existsSync(executablePath)) { + console.warn(`patch-windows-binaries: skipping missing ${executablePath}`) + continue + } + + try { + await rcedit(executablePath, { + 'requested-execution-level': 'asInvoker' + }) + console.log(`patch-windows-binaries: set asInvoker on ${executablePath}`) + } catch (error) { + console.warn( + `patch-windows-binaries: failed to patch ${executablePath}:`, + error instanceof Error ? error.message : error + ) + } } }