Update editor, themes, menus, backgrounds, and release tooling

This commit is contained in:
Knotty Wyvern
2026-10-14 16:19:51 -07:00
parent f6eaa52949
commit edef2520af
113 changed files with 5722 additions and 386 deletions
+33 -6
View File
@@ -18,6 +18,27 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
const runtimeId = randomUUID();
let revision = 0;
const tab = id => { const found = tabs.get(id); if (!found) throw new Error('Unknown browser tab.'); return found; };
const pageFocusStates = new WeakMap();
async function focusPage(wc, enabled) {
// Hidden offscreen windows cannot gain native focus. Chromium still needs it to paint the caret.
if (!wc.debugger.isAttached()) {
if (!enabled) return;
wc.debugger.attach('1.3');
pageFocusStates.delete(wc);
}
if (pageFocusStates.get(wc) === enabled) return;
await wc.debugger.sendCommand('Emulation.setFocusEmulationEnabled', { enabled });
pageFocusStates.set(wc, enabled);
if (enabled) wc.focus();
}
function emulateViewport(item) {
if (!item.viewport) return;
const { width, height } = item.viewport, scale = item.scale;
item.view.setContentSize(Math.round(width * scale), Math.round(height * scale));
item.view.webContents.enableDeviceEmulation({ screenPosition: 'desktop', screenSize: { width, height },
deviceScaleFactor: scale, viewPosition: { x: 0, y: 0 }, viewSize: { width, height }, scale });
item.view.webContents.invalidate();
}
const agent = new AgentController(tab);
const snapshot = () => ({
runtimeId, revision: ++revision,
@@ -134,6 +155,7 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
});
wc.on('destroyed', () => { item.iconRequest?.abort(); clearTimeout(item.settle); clearTimeout(item.retryFrame); });
wc.on('did-stop-loading', () => { changed(); void cosmetics(item); });
wc.on('did-finish-load', () => emulateViewport(item));
wc.on('did-fail-load', (_event, code, _description, _url, main) => { if (main && code !== -3) emit({ event: 'error', tabId: item.id, message: `Page load failed (${code}).` }); });
wc.on('paint', (_event, _dirty, image) => {
item.latestImage = image;
@@ -196,15 +218,20 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
const scale = Number(args.scale ?? 1);
if (!Number.isFinite(scale) || scale < 1 || scale > 3) throw new Error('Invalid browser scale.');
current.scale = scale;
current.view.setContentSize(Math.round(args.width * scale), Math.round(args.height * scale));
current.view.webContents.enableDeviceEmulation({ screenPosition: 'desktop', screenSize: { width: args.width, height: args.height },
deviceScaleFactor: scale, viewPosition: { x: 0, y: 0 }, viewSize: { width: args.width, height: args.height }, scale });
current.viewport = { width: args.width, height: args.height };
emulateViewport(current);
current.delivery.clear(); current.view.webContents.invalidate(); return null;
}
case 'visible': { const item = tab(args.tabId), wc = item.view.webContents; item.delivery.clear(); if (args.visible === true) { wc.startPainting(); wc.invalidate(); } else { wc.stopPainting(); clearTimeout(item.settle); clearTimeout(item.retryFrame); } return null; }
case 'visible': { const item = tab(args.tabId), wc = item.view.webContents; item.delivery.clear(); if (args.visible === true) { wc.startPainting(); wc.invalidate(); } else { await focusPage(wc, false); wc.stopPainting(); clearTimeout(item.settle); clearTimeout(item.retryFrame); } return null; }
case 'focus': {
if (typeof args.focused !== 'boolean') throw new Error('Invalid browser focus.');
await focusPage(tab(args.tabId).view.webContents, args.focused); return null;
}
case 'insertText': {
if (typeof args.text !== 'string' || args.text.length > 100000) throw new Error('Invalid browser text.');
await tab(args.tabId).view.webContents.insertText(args.text); return null;
const wc = tab(args.tabId).view.webContents;
await focusPage(wc, true);
await wc.insertText(args.text); return null;
}
case 'edit': {
const wc = tab(args.tabId).view.webContents;
@@ -244,7 +271,7 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
event = { type: input.type, keyCode: input.keyCode, modifiers };
}
// Pointer motion and wheel events must not repeatedly activate the native window.
if (input.type === 'mouseDown' || input.type === 'keyDown' || input.type === 'char') wc.focus();
if (input.type === 'mouseDown' || input.type === 'keyDown' || input.type === 'char') await focusPage(wc, true);
wc.sendInputEvent(event); return null;
}
case 'createProfile': store.createProfile(args.name); break;