theseus/addon-tab-preload.js

17 lines
999 B
JavaScript
Raw Normal View History

// 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");
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); }),
});