Files
zh-grammar/webview.js
T
2026-03-23 22:26:30 +07:00

35 lines
1012 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { Webview } = require("webview-nodejs");
const { spawn } = require("child_process");
const PORT = 5173;
/**
* I don’t see an alternative: “DeprecationWarning: Passing args to a child process with shell option true …”
* https://github.com/nodejs/help/issues/5063
*/
const p = spawn("pnpm", ["vitepress", "dev", "--port", String(PORT), "docs"], {
shell: true,
stdio: "inherit",
});
const w = new Webview();
w.title(require("./package.json").name);
w.size(1920, 1280);
w.init(/* js */ `
document.addEventListener('click', (ev) => {
if (ev.target.matches('a')) {
const href = ev.target.href || '';
if (href.startsWith('https://resources.allsetlearning.com/chinese/')) ev.preventDefault();
}
})
`);
w.navigate(`http://localhost:${PORT}`);
w.show();
console.log(p.kill("SIGINT"));
/**
* node:child_process#spawn doesn't fire close event if app exits immediately after spawned app exits
* ??? https://github.com/oven-sh/bun/issues/3083
*/
require("kill-port")(PORT);