mirror of
https://github.com/felixrieseberg/windows95.git
synced 2026-05-09 00:24:09 +00:00
Update v86 to latest, replace string-match patches with stable shim
The previous build patched libv86.js by exact-string match against
Closure-mangled identifiers (k.load_file, H.exportSymbol, pa, qa),
which broke on every upstream rebuild.
Of the three old patches:
- exportSymbol order: now a one-line HTML shim copying module.exports.V86
to window after libv86 loads
- this.fetch binding: fixed upstream
- load_file XHR vs fs: replaced by patching await import('node:fs/promises')
to require('fs').promises - string literals survive Closure, fails loud
if absent
Also adds tools/update-v86.js to pull new builds from copy.sh, and exposes
the renderer DevTools protocol on localhost:9222 in dev.
This commit is contained in:
@@ -61,6 +61,12 @@ export function main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDevMode()) {
|
||||||
|
// Renderer DevTools Protocol — connect Chrome to chrome://inspect
|
||||||
|
// or attach a debugger to localhost:9222
|
||||||
|
app.commandLine.appendSwitch("remote-debugging-port", "9222");
|
||||||
|
}
|
||||||
|
|
||||||
// Set the app's name
|
// Set the app's name
|
||||||
app.setName("windows95");
|
app.setName("windows95");
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export function getOrCreateWindow(): BrowserWindow {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// mainWindow.webContents.toggleDevTools();
|
|
||||||
mainWindow.loadFile("./dist/static/index.html");
|
mainWindow.loadFile("./dist/static/index.html");
|
||||||
|
|
||||||
mainWindow.webContents.on("will-navigate", (event, url) =>
|
mainWindow.webContents.on("will-navigate", (event, url) =>
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -4,27 +4,35 @@ const Bundler = require('parcel-bundler')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
|
// libv86 checks `typeof module.exports` before `typeof window` when deciding
|
||||||
|
// where to export V86. In an Electron renderer with nodeIntegration both exist,
|
||||||
|
// so it ends up on module.exports instead of window. This shim copies it over.
|
||||||
|
const LIBV86_SHIM = `<script src="libv86.js"></script>
|
||||||
|
<script>if (typeof module !== "undefined" && module.exports && module.exports.V86) window.V86 = module.exports.V86;</script>`
|
||||||
|
|
||||||
|
// v86's node-path file loader uses `await import("node:fs/promises")`, but
|
||||||
|
// dynamic import of node: URLs doesn't work in an Electron renderer — only
|
||||||
|
// require() does. The string literal is stable across Closure builds.
|
||||||
|
const V86_FS_IMPORT = 'await import("node:fs/promises")'
|
||||||
|
const V86_FS_REQUIRE = 'require("fs").promises'
|
||||||
|
|
||||||
async function copyLib() {
|
async function copyLib() {
|
||||||
const target = path.join(__dirname, '../dist/static')
|
const target = path.join(__dirname, '../dist/static')
|
||||||
const lib = path.join(__dirname, '../src/renderer/lib')
|
const lib = path.join(__dirname, '../src/renderer/lib')
|
||||||
const index = path.join(target, 'index.html')
|
const index = path.join(target, 'index.html')
|
||||||
|
|
||||||
// Copy in lib
|
|
||||||
await fs.promises.cp(lib, target, { recursive: true });
|
await fs.promises.cp(lib, target, { recursive: true });
|
||||||
|
|
||||||
// Patch so that fs.read is used
|
|
||||||
const libv86path = path.join(target, 'libv86.js')
|
const libv86path = path.join(target, 'libv86.js')
|
||||||
const libv86 = fs.readFileSync(libv86path, 'utf-8')
|
const libv86 = fs.readFileSync(libv86path, 'utf-8')
|
||||||
|
const patched = libv86.split(V86_FS_IMPORT).join(V86_FS_REQUIRE)
|
||||||
|
if (patched === libv86) {
|
||||||
|
throw new Error(`libv86.js patch failed: \`${V86_FS_IMPORT}\` not found. Check src/lib.js in copy/v86.`)
|
||||||
|
}
|
||||||
|
fs.writeFileSync(libv86path, patched)
|
||||||
|
|
||||||
let patchedLibv86 = libv86.replace('k.load_file="undefined"===typeof XMLHttpRequest?pa:qa', 'k.load_file=pa')
|
|
||||||
patchedLibv86 = patchedLibv86.replace('H.exportSymbol=function(a,b){"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports[a]=b:"undefined"!==typeof window?window[a]=b:"function"===typeof importScripts&&(self[a]=b)}', 'H.exportSymbol=function(a,b){"undefined"!==typeof window?window[a]=b:"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports[a]=b:"function"===typeof importScripts&&(self[a]=b)}')
|
|
||||||
patchedLibv86 = patchedLibv86.replace('this.fetch=fetch;', 'this.fetch=(...args)=>fetch(...args);')
|
|
||||||
|
|
||||||
fs.writeFileSync(libv86path, patchedLibv86)
|
|
||||||
|
|
||||||
// Overwrite
|
|
||||||
const indexContents = fs.readFileSync(index, 'utf-8');
|
const indexContents = fs.readFileSync(index, 'utf-8');
|
||||||
const replacedContents = indexContents.replace('<!-- libv86 -->', '<script src="libv86.js"></script>')
|
const replacedContents = indexContents.replace('<!-- libv86 -->', LIBV86_SHIM)
|
||||||
fs.writeFileSync(index, replacedContents)
|
fs.writeFileSync(index, replacedContents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
tools/update-v86.js
Normal file
35
tools/update-v86.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
|
const LIB_DIR = path.join(__dirname, '../src/renderer/lib');
|
||||||
|
const FILES = [
|
||||||
|
{ url: 'https://copy.sh/v86/build/libv86.js', dest: path.join(LIB_DIR, 'libv86.js') },
|
||||||
|
{ url: 'https://copy.sh/v86/build/v86.wasm', dest: path.join(LIB_DIR, 'build/v86.wasm') },
|
||||||
|
];
|
||||||
|
|
||||||
|
function download(url, dest) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
https.get(url, (res) => {
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
return reject(new Error(`${url} → HTTP ${res.statusCode}`));
|
||||||
|
}
|
||||||
|
const chunks = [];
|
||||||
|
res.on('data', (c) => chunks.push(c));
|
||||||
|
res.on('end', () => {
|
||||||
|
const buf = Buffer.concat(chunks);
|
||||||
|
fs.writeFileSync(dest, buf);
|
||||||
|
console.log(`✓ ${path.relative(process.cwd(), dest)} (${(buf.length / 1024).toFixed(0)} KB)`);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
res.on('error', reject);
|
||||||
|
}).on('error', reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
for (const { url, dest } of FILES) {
|
||||||
|
await download(url, dest);
|
||||||
|
}
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user