Files
edgeever/scripts/native-update-instrumentation.mjs
edgeever-updater[bot] 507cb892ad chore: update EdgeEver from v2.19.0
EdgeEver-Upstream-Commit: a80d9bfda1aad846e20882813758a59fe27bf8ca
2026-11-04 09:13:22 +00:00

21 lines
2.3 KiB
JavaScript

export const instrumentNativeUpdateMain = (originalMain, runtimeConfigPath) => {
const replace = (source, from, to) => {
if (source.split(from).length !== 2) throw new Error(`Expected exactly one instrumentation site: ${from}`);
return source.replace(from, to);
};
let instrumented = `import { verifierLog, verifierWindowsMetadata, attachVerifier } from "./native-update-verifier.mjs";\n${originalMain}`;
instrumented = replace(instrumented, 'if (requestedUserDataDirectory) app.setPath("userData", requestedUserDataDirectory);', 'app.setPath("userData", process.env.EDGE_EVER_UPDATE_VERIFIER_PROFILE);');
instrumented = replace(instrumented, ' desktopUpdateController = createDesktopUpdateController({', ` autoUpdater.setFeedURL({ provider: "generic", url: process.env.EDGE_EVER_UPDATE_VERIFIER_FEED + "/feed" });\n autoUpdater.disableDifferentialDownload = true;\n desktopUpdateController = createDesktopUpdateController({`);
instrumented = replace(instrumented, 'fetchWindowsMetadata: (options) => fetchTrustedWindowsUpdate({ ...options, fetchImpl: net.fetch }),', 'fetchWindowsMetadata: verifierWindowsMetadata,');
instrumented = replace(instrumented, ' onDownloaded: (version) => {', ' onDownloaded: (version) => {\n verifierLog("ready", { version, runningVersion: app.getVersion() });\n return;');
instrumented = replace(instrumented, ' void checkForDesktopUpdate("startup", { force: true });', ' attachVerifier({ app, updater: autoUpdater, controller: desktopUpdateController });\n void checkForDesktopUpdate("startup", { force: true });');
instrumented = instrumented.replace(' await confirmMacInstallation();', ' // Verification bundle stays in its isolated runner directory.');
instrumented = instrumented.replace(' await ejectMountedMacInstallers();', ' // Verification does not eject unrelated volumes.');
if (runtimeConfigPath) {
instrumented = 'import { readFileSync as readVerifierConfig } from "node:fs";\n' + instrumented;
const bootstrap = `for (const [key, value] of Object.entries(JSON.parse(readVerifierConfig(${JSON.stringify(runtimeConfigPath)}, "utf8")))) process.env[key] = value;\n`;
instrumented = instrumented.replace('const { autoUpdater } = electronUpdater;', bootstrap + 'const { autoUpdater } = electronUpdater;');
}
return instrumented;
};