theseus/addon-tab-preload.js
Local Dev 94cfb98770 Theseus 0.3.124 (cont'd): sidebar auto-close on click now fires in Settings and add-on tabs too
The overlay sidebar closes when the page is clicked — but only for web
tabs, because only home-preload reported the pointerdown. Settings and
full-tab add-on pages use their own preloads, so clicking inside them
left the overlay panel sitting on top. Added the same pointerdown
reporter to settings-preload and addon-tab-preload. Push-mode behaviour
is unchanged (main gates on sidebarPanelMode).
2026-10-27 21:55:45 +02:00

27 lines
1.7 KiB
JavaScript

// Preload for full-tab pages opened by api.openTab("<file>", {query}) — the
// "open-tab" capability. Same window.silentmode surface as the sidebar
// preload (storage / invoke / on) but WITHOUT the sidebar's picker strip and
// resize grip, which have no place in a normal tab. Main derives the add-on
// identity from the sender's file:// URL, so a page hosted anywhere else
// gets nothing back from these handlers.
const { contextBridge, ipcRenderer } = require("electron");
// Clicks in an add-on tab close an overlay sidebar panel the same way clicks
// in a web tab or Settings do (see home-preload / settings-preload). Push
// mode is unaffected — main gates on sidebarPanelMode.
window.addEventListener("pointerdown", () => { ipcRenderer.send("tab-pointerdown"); }, true);
contextBridge.exposeInMainWorld("silentmode", {
storage: {
get: (key, fallback = null) => ipcRenderer.invoke("addon-storage-get", key, fallback),
set: (key, value) => ipcRenderer.invoke("addon-storage-set", key, value),
all: () => ipcRenderer.invoke("addon-storage-all"),
},
invoke: (msg, payload) => ipcRenderer.invoke("addon-msg", String(msg), payload),
on: (msg, cb) => ipcRenderer.on("addon-event", (_e, name, payload) => { if (name === msg) cb(payload); }),
// Close the tab this page lives in. Used by editor "Discard" and by
// Escape. Main derives the tab from the sender's webContents id so an
// add-on page can only close its own tab, never anyone else's.
closeTab: () => ipcRenderer.invoke("addon-tab-close"),
// Bring this page's own tab to the front. Main derives the tab from the
// sender, so a page can only front itself.
focusTab: () => ipcRenderer.invoke("addon-tab-focus"),
});