17 lines
936 B
JavaScript
17 lines
936 B
JavaScript
|
|
// Preload shared by every add-on sidebar panel. Exposes a small, safe
|
||
|
|
// surface to the add-on's HTML. Main-side handlers derive the add-on
|
||
|
|
// identity from the sender's URL (the panel is always loaded from
|
||
|
|
// somewhere inside <userData>/addons/<id>/), so a random page that
|
||
|
|
// happens to see the API shape can't touch another add-on's storage.
|
||
|
|
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"),
|
||
|
|
},
|
||
|
|
// Ask main which panel is currently visible — panels may want to
|
||
|
|
// suspend expensive work when hidden.
|
||
|
|
onVisibility: (cb) => ipcRenderer.on("sidebar-visibility", (_e, visible) => cb(!!visible)),
|
||
|
|
});
|