From fa50f97e6fe6a06c36d7eded162014d4ae7916da Mon Sep 17 00:00:00 2001 From: Silent Mode Date: Sat, 3 Oct 2026 21:33:16 +0200 Subject: [PATCH] Theseus: language picker is a floating overlay now, not a native menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The globe-chip menu was a native Electron menu — square corners, system font, no theming beyond the OS's own context-menu paint. Replaces it with a floating overlay WebContentsView (lang-picker.html + preload), following the same pattern the engine picker and the popover already use: rounded 12px surface, acid-tint accents on the current pin, soft shadow, dark + light scheme, flush under the chip's bottom-right. The content is organised around the user's intent — translate first, pick a language second. The "Translate this page" row sits at the top when it is actionable (web tab + supported source + supported target), with the detected source and the target under the label so the user can tell what the backend will do before they click. Once a page is translated, that row flips to "Show original ()". Below the action strip is Automatic + the six supported languages, each with a two-letter code chip in the left slot and a ✓ on the current pin. Unsupported languages are hidden by default inside a collapsible "More languages (translator coming later)" group — click to expand, click to collapse; a pinned-unsupported auto-expands so its ✓ stays visible. Plumbing matches engine-picker: deferred-load WebContentsView, closeOnClickAway, setBounds anchored under the chip, picker renderer reports its own content height after each render so the overlay contracts and expands with the "More languages" toggle. State pushes come from emitTranslateState (so the Translate / Show-original row updates when a page finishes auto-translating with the picker open) and from broadcastSettings (so a Settings-side language change re-paints the ✓). Verified end-to-end: picker loads, shows Automatic + 6 supported in the default list and 18 greyed in the "More" group, repaints to "⟲ Show original (Spanish)" after an auto-translate completes. --- chrome.html | 8 ++- lang-picker-preload.js | 10 +++ lang-picker.html | 157 +++++++++++++++++++++++++++++++++++++++++ main.js | 157 ++++++++++++++++++++++++++--------------- package.json | 2 + 5 files changed, 276 insertions(+), 58 deletions(-) create mode 100644 lang-picker-preload.js create mode 100644 lang-picker.html diff --git a/chrome.html b/chrome.html index 6118f399..b96af37b 100644 --- a/chrome.html +++ b/chrome.html @@ -757,7 +757,13 @@ } langBtn.onclick = () => { const r = langBtn.getBoundingClientRect(); - T.websiteLanguageMenu && T.websiteLanguageMenu({ x: Math.round(r.left), y: Math.round(r.bottom + 4) }); + // Pass the chip's full rect — main anchors the dropdown's TOP-RIGHT + // under the chip's bottom-right, so x+width is where we want the + // picker's right edge to land, and y+height sets its top. + T.websiteLanguageMenu && T.websiteLanguageMenu({ + x: Math.round(r.left), y: Math.round(r.top), + width: Math.round(r.width), height: Math.round(r.height), + }); }; // Locale is optional (older main.js won't expose it) — render on settings // either way so the chip works even without it. diff --git a/lang-picker-preload.js b/lang-picker-preload.js new file mode 100644 index 00000000..13252843 --- /dev/null +++ b/lang-picker-preload.js @@ -0,0 +1,10 @@ +const { contextBridge, ipcRenderer } = require("electron"); +contextBridge.exposeInMainWorld("langpicker", { + onState: (cb) => ipcRenderer.on("lang-picker-state", (_e, d) => cb(d)), + pick: (tag) => ipcRenderer.invoke("lp-pick", String(tag || "")), + translate: () => ipcRenderer.invoke("lp-translate"), + revert: () => ipcRenderer.invoke("lp-revert"), + openSettings: () => ipcRenderer.invoke("lp-open-settings"), + close: () => ipcRenderer.invoke("lp-close"), + resize: (h, w) => ipcRenderer.invoke("lp-resize", h, w), +}); diff --git a/lang-picker.html b/lang-picker.html new file mode 100644 index 00000000..b21372fe --- /dev/null +++ b/lang-picker.html @@ -0,0 +1,157 @@ + + + + + + + diff --git a/main.js b/main.js index 0c7f2d29..e1bfb565 100644 --- a/main.js +++ b/main.js @@ -2103,6 +2103,12 @@ const POP_W = 360; let popH = 210; // popH is updated to fit the popover's conte // engine favicons, like Firefox — a native