theseus/settings-preload.js
Local Dev 1d2faf64f3 Theseus: shield green polish, picker→Search section, toggle-vs-remove
Three follow-up asks from the previous ship:

1. Shield "secure" colour bumped from #4fd1a5 (mint) to #3fb950 — the
   GitHub-style saturated green, matches the +N/-N diff colour the user
   pointed at as reference.

2. Engine-picker "Search settings…" now opens the Search section
   directly instead of General. New IPC channel `focus-section` fires
   from main after picker-open-settings, carried through
   settings-preload as `onFocusSection`, and the settings.html sidebar
   handler exposes showSection(sec) so any section can be focused
   programmatically. Works for both a fresh settings tab (fires on
   did-finish-load) and an already-open one (fires immediately).

3. Toggle no longer removes an engine from the list. Two-tier state:
   INSTALLED (visible in the Settings list) and ENABLED (toggled on in
   the toolbar dropdown). Toggling off keeps the row visible with an
   .off class (dimmed 55%). Right-click any row → new context menu with
   "Remove from list" is what actually removes an engine (built-ins go
   back to the catalog, customs are dropped entirely).

Model changes:
- New settings.installedEngines persistent array (defaults to
  DEFAULT_ENABLED). enabledEngines becomes a subset of installedEngines.
- isInstalled(id) helper; allEngines() carries `installed: bool` alongside
  `enabled`.
- New IPC `remove-from-list` (right-click action); exposed as
  removeFromList in settings-preload.
- set-engine-enabled now also INSTALLS when enabling (the catalog "+ Add"
  flow), preserves installed state when disabling.
- add-engine (custom URL) auto-adds the new id to enabledEngines too.
- remove-engine (custom delete) prunes from enabledEngines as well.
- Never-empty invariant kept: enabledEngines falls back to ["duckduckgo"]
  if everything gets removed.

Settings UI:
- Enabled list shows all INSTALLED engines (was: only enabled), rendered
  with toggle reflecting enabled state; rows carry data-builtin so the
  context menu picks the right remove IPC.
- Catalog panel and Discover-more pane filter on !installed instead of
  !enabled — a toggled-off engine stays in the enabled list, not here.
- Ctxmenu is a floating .ctxmenu div; closes on outside click / Escape.
- .eng.off dims the row and mutes the name colour.

Preview harness stubs updated to include the `installed` field on every
engine + `removeFromList` and `onFocusSection` no-op stubs so
_settings-preview.html renders the new UI accurately.
2026-08-06 01:41:31 +02:00

18 lines
1.1 KiB
JavaScript

const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("cfg", {
get: () => ipcRenderer.invoke("settings-get"),
set: (key, value) => ipcRenderer.invoke("settings-set", key, value),
engines: () => ipcRenderer.invoke("search-engines"),
addEngine: (eng) => ipcRenderer.invoke("add-engine", eng),
removeEngine: (id) => ipcRenderer.invoke("remove-engine", id),
setEngineEnabled: (id, on) => ipcRenderer.invoke("set-engine-enabled", id, on),
setEngineOrder: (ids) => ipcRenderer.invoke("set-engine-order", ids),
removeFromList: (id) => ipcRenderer.invoke("remove-from-list", id),
// Main asks settings to jump to a specific sidebar section (e.g. from the
// engine picker's "Search settings…" click). Emits the section id string.
onFocusSection: (cb) => ipcRenderer.on("focus-section", (_e, section) => cb(section)),
// Collision-mode: BCNR/ICANN policy + per-name/per-TLD overrides
collisionState: () => ipcRenderer.invoke("collision-state"),
setCollisionPolicy: (p) => ipcRenderer.invoke("collision-set-policy", p),
resetCollisions: () => ipcRenderer.invoke("collision-reset"),
});