Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions scripts/patches/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,72 @@ function patchLinuxMultiInstanceBootstrap(extractedDir) {
return { changed: true };
}

const unguardedOwlFeatureLookup =
"function Qe(){let e=process._linkedBinding;if(typeof e!=`function`)throw Error(`Owl feature binding is unavailable`);return Ge.parse(e.call(process,`electron_common_owl_features`))}";
const guardedOwlFeatureLookup =
"function Qe(){let e=process._linkedBinding;if(typeof e!=`function`)return{isOwlFeatureEnabled:()=>false};try{return Ge.parse(e.call(process,`electron_common_owl_features`))}catch(t){return{isOwlFeatureEnabled:()=>false}}}";

function applyLinuxOwlFeatureGuardPatch(currentSource) {
if (currentSource.includes(guardedOwlFeatureLookup)) {
return currentSource;
}
if (currentSource.includes(unguardedOwlFeatureLookup)) {
return currentSource.replace(unguardedOwlFeatureLookup, guardedOwlFeatureLookup);
}

if (currentSource.includes("electron_common_owl_features")) {
console.warn(
"WARN: Could not find bootstrap Owl feature binding lookup in expected shape — skipping Linux Owl feature guard patch",
);
}
return currentSource;
}

function findFileContaining(dir, needle) {
if (!fs.existsSync(dir)) {
return null;
}
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const found = findFileContaining(entryPath, needle);
if (found != null) {
return found;
}
} else if (entry.isFile() && entry.name.endsWith(".js")) {
if (fs.readFileSync(entryPath, "utf8").includes(needle)) {
return entryPath;
}
}
}
return null;
}

function patchLinuxOwlFeatureGuard(extractedDir) {
// The Owl feature-binding lookup lives in whichever chunk the main bundle
// pulls it into (content-hashed filename, not a fixed path), so locate it
// by content instead of assuming it's in bootstrap.js.
const target = findFileContaining(
path.join(extractedDir, ".vite", "build"),
"electron_common_owl_features",
);
if (target == null) {
return { changed: false, reason: "owl feature binding lookup not found" };
}

const source = fs.readFileSync(target, "utf8");
const patched = applyLinuxOwlFeatureGuardPatch(source);
if (patched === source) {
return { changed: false };
}

fs.writeFileSync(target, patched, "utf8");
return { changed: true, target };
}

module.exports = {
applyLinuxMultiInstanceBootstrapPatch,
patchLinuxMultiInstanceBootstrap,
applyLinuxOwlFeatureGuardPatch,
patchLinuxOwlFeatureGuard,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

const {
patchLinuxOwlFeatureGuard,
} = require("../../../../bootstrap.js");

module.exports = {
id: "linux-owl-feature-guard",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the descriptor to the expected core-patch list

Adding this discovered descriptor without updating expectedIds makes node --test scripts/patch-linux-window-ui.test.js fail in default core patch descriptors are grouped and unique, because the actual list now contains linux-owl-feature-guard while the expected list does not. This leaves the repository's documented patcher test suite—and the local core CI job that invokes it—failing for every run.

AGENTS.md reference: AGENTS.md:L70-L71

Useful? React with 👍 / 👎.

phase: "extracted-app",
order: 130,
ciPolicy: "optional",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make the startup guard a required upstream patch

When an upstream bundle still references electron_common_owl_features but minifier drift prevents the exact replacement, the patch emits a warning and is recorded as skipped-optional; because this descriptor is optional, upstream validation still succeeds and can package an app that aborts every Linux launch on stock Electron. Since absence of this guard makes the application unusable, mark it required so bundle drift blocks the upstream build.

AGENTS.md reference: AGENTS.md:L198-L199

Useful? React with 👍 / 👎.

apply: patchLinuxOwlFeatureGuard,
};
Loading