diff --git a/docs/i18n-inventory.md b/docs/i18n-inventory.md index 738f237d..4e1e1a49 100644 --- a/docs/i18n-inventory.md +++ b/docs/i18n-inventory.md @@ -1,6 +1,6 @@ # i18n inventory (egdev6/quorb#66) -Generated by `node scripts/i18n-inventory.mjs` from the source trees `src/` = `87a618afd56fd64dcf0e329e20991f3808ff0a37` and `src-tauri/src/` = `210ed4f47e1041f3ef18253a37b170d8beb5efa8`. +Generated by `node scripts/i18n-inventory.mjs` from the source trees `src/` = `05b01b4feeeb521badf668c9de79d17f70137c44` and `src-tauri/src/` = `210ed4f47e1041f3ef18253a37b170d8beb5efa8`. Any commit whose `git rev-parse :src` and `:src-tauri/src` match has these exact lines. Do not edit by hand: regenerate, or verify with `node scripts/i18n-inventory.mjs --check`. @@ -995,24 +995,24 @@ look like text. | Line | Text | |---:|---| -| 260 | ${…}: sesión caducada | -| 260 | Pulsa «Renovar sesión» en su panel. Quorb se actualiza solo en cuanto se renueve. | -| 408 | Quorb ${…} disponible | -| 408 | Pulsa el icono de descarga de la tira para actualizar. | -| 430 | No se pudo actualizar Quorb | -| 487 | Widget surface is not mounted | -| 688 | .orb[data-id="${…}"] | -| 907 | Quorb | -| 933 | Reintentar mostrar Quorb | -| 933 | Mostrar Quorb | -| 963 | Arrastrar: se pega al borde más cercano | -| 992 | Reintentar | -| 994 | Cargando… | -| 998 | Configurar | -| 1011 | Actualizando a ${…}${…} | -| 1012 | Actualizar a Quorb ${…} | -| 1018 | Actualizar ahora | -| 1021 | Ajustes | +| 266 | ${…}: sesión caducada | +| 266 | Pulsa «Renovar sesión» en su panel. Quorb se actualiza solo en cuanto se renueve. | +| 414 | Quorb ${…} disponible | +| 414 | Pulsa el icono de descarga de la tira para actualizar. | +| 436 | No se pudo actualizar Quorb | +| 493 | Widget surface is not mounted | +| 697 | .orb[data-id="${…}"] | +| 941 | Quorb | +| 967 | Reintentar mostrar Quorb | +| 967 | Mostrar Quorb | +| 997 | Arrastrar: se pega al borde más cercano | +| 1026 | Reintentar | +| 1028 | Cargando… | +| 1032 | Configurar | +| 1045 | Actualizando a ${…}${…} | +| 1046 | Actualizar a Quorb ${…} | +| 1052 | Actualizar ahora | +| 1055 | Ajustes | ## src/components/CodexInstall.tsx diff --git a/src/Widget.tsx b/src/Widget.tsx index 6a51fcb8..4464287f 100644 --- a/src/Widget.tsx +++ b/src/Widget.tsx @@ -15,9 +15,10 @@ import { useUpdaterMode } from './lib/useUpdater'; import { retryWithBackoff, STARTUP_RETRY, USAGE_RETRY } from './lib/startup'; import { createSessionMonitor } from './lib/session-monitor'; import { needsRefresh } from './lib/widget-refresh'; -import { createWidgetRecovery } from './lib/widget-recovery'; +import { createWidgetRecovery, shouldAuditNativePosition } from './lib/widget-recovery'; import { createLatestQueue, physicalPanelBounds, samePhysical, DETAIL_EVENTS, DETAIL_WINDOW, isCurrentDetailInteraction, panelWidthFor, type DetailInteraction, type DetailState, type PhysicalBounds } from './lib/detail-panel'; -import { createDetailPresence, presenceFromPoint } from './lib/detail-presence'; +import { createDetailPresence, presenceFromPoint, shouldSampleNativePresence } from './lib/detail-presence'; +import { openDelayForOs, osFromUA } from './lib/os-detect'; import { ProviderGauge } from './components/ProviderGauge'; import { accountTags } from './lib/accounts'; import { clipSurfaceSafely, measureSurfaceClip } from './lib/surface-clip'; @@ -25,7 +26,12 @@ import { peekRect, usesPeekWindow, waitForViewport, watchPreparation } from './l import { useDockReveal } from './lib/useDockReveal'; const CLOSE_DELAY = 280; -const OPEN_DELAY = 90; +/** + * Platform-scoped, not global: Linux needs the long delay because nothing else + * contains an accidental sweep there, while Windows and macOS keep the original + * 90 ms. The rationale and the per-platform values live in `openDelayForOs()`. + */ +const OPEN_DELAY = openDelayForOs(osFromUA(navigator.userAgent)); const HIDE_DELAY = 900; /** Tras un aviso, la tira se muestra este tiempo aunque esté en auto-ocultar. */ const REVEAL_MS = 6000; @@ -514,6 +520,9 @@ export function Widget() { useEffect(() => { let disposed = false; const win = getCurrentWindow(); + // Windows DWM recovery (#147/#148): on Wayland/Linux, outerPosition() returns (0,0) + // and GTK window sizing differs, causing infinite false-positive recovery loops. + if (!shouldAuditNativePosition(osFromUA(navigator.userAgent))) return; const allowed = () => !disposed && !drag.current && !placementInFlight.current && (phase === 'open' || phase === 'hidden') && shown.current && widgetBounds.current !== null; const check = createWidgetRecovery({ @@ -708,6 +717,9 @@ export function Widget() { // alimenta el tracker. Falla en silencio (Wayland puede no exponer la // posición): el muestreo degrada, nunca adivina. useEffect(() => { + // Solo aplica en macOS (donde WebKit pierde eventos mouseleave en ventanas transparentes). + // En Linux/Wayland, cursorPosition() devuelve (0,0) y causa falsos cierres del popup. + if (!shouldSampleNativePresence(osFromUA(navigator.userAgent))) return; if (!hovered) { presenceRef.reset(); return; @@ -779,13 +791,25 @@ export function Widget() { cancelTimers(); setHovered(null); setDragging(true); - const d = { sx: e.screenX, sy: e.screenY, start: null as PhysicalPosition | null, sf: geo.sf, raf: 0, pointerId: e.pointerId, ending: false }; + // `widgetBounds.current` es la verdad incluso cuando el compositor no + // reporta posición: el caché lo escribe el propio `setWidgetBounds` que + // colocó la ventana, no una lectura de `outerPosition()`. Por eso sirve + // como origen síncrono del arrastre en xdg-shell, donde `outerPosition()` + // devuelve (0, 0) por diseño y no puede arrancar la aritmética por delta. + const initialStart = widgetBounds.current + ? new PhysicalPosition(widgetBounds.current.x, widgetBounds.current.y) + : null; + const d = { sx: e.screenX, sy: e.screenY, start: initialStart, sf: geo.sf, raf: 0, pointerId: e.pointerId, ending: false }; drag.current = d; const current = () => dragMounted.current && drag.current === d; enqueueDrag(async () => { if (!current()) return; const position = await getCurrentWindow().outerPosition(); - if (current()) d.start = position; + // Un (0, 0) real es una esquina legítima; solo se descarta cuando ya + // tenemos un origen creíble del caché. + if (current() && (position.x !== 0 || position.y !== 0 || !d.start)) { + d.start = position; + } }).catch((err) => { if (!current()) return; setError(String(err)); @@ -827,10 +851,20 @@ export function Widget() { if (!current()) return; const [wpos, mons] = await Promise.all([getCurrentWindow().outerPosition(), availableMonitors()]); if (!current()) return; - // El imán usa el punto donde sueltas el asa (no el centro de la tira): - // así, al llevarla a un lateral, se pega a ese lateral aunque sea horizontal. - const cx = wpos.x + (grip ? grip.left + grip.width / 2 : 0) * d.sf; - const cy = wpos.y + (grip ? grip.top + grip.height / 2 : 0) * d.sf; + // `wpos` manda cuando el compositor informa algo: es la posición real. + // Si informa (0,0) con un origen en caché, se toma la rama por delta + // (caso de la esquina superior izquierda, reportado en #168). Como + // `start` sale del mismo caché que escribió `setWidgetBounds`, la + // desviación solo puede ser redondeo del compositor; si algún día se + // reporta el orbe imantado en esa esquina, revisar primero el redondeo. + const posX = (wpos.x !== 0 || wpos.y !== 0) + ? wpos.x + : (d.start?.x ?? 0) + (e.screenX - d.sx) * d.sf; + const posY = (wpos.x !== 0 || wpos.y !== 0) + ? wpos.y + : (d.start?.y ?? 0) + (e.screenY - d.sy) * d.sf; + const cx = posX + (grip ? grip.left + grip.width / 2 : 0) * d.sf; + const cy = posY + (grip ? grip.top + grip.height / 2 : 0) * d.sf; const mon = mons.find((m) => contains({ x: m.position.x, y: m.position.y, w: m.size.width, h: m.size.height }, cx, cy)) ?? (await currentMonitor()); diff --git a/src/lib/detail-presence.test.ts b/src/lib/detail-presence.test.ts index d0e6e233..a7fad3ca 100644 --- a/src/lib/detail-presence.test.ts +++ b/src/lib/detail-presence.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { createDetailPresence, pointInBounds, presenceFromPoint } from './detail-presence'; +import { createDetailPresence, pointInBounds, presenceFromPoint, shouldSampleNativePresence } from './detail-presence'; /** * Deterministic tracker whose close bookkeeping records the ORDER of @@ -186,3 +186,24 @@ describe('presenceFromPoint', () => { expect(presenceFromPoint({ x: 50, y: 250 }, null, null)).toEqual({ widget: false, detail: false }); }); }); + +describe('shouldSampleNativePresence', () => { + it('solo macOS: en Linux cursorPosition() devuelve (0,0) y cerraria el popup de golpe', () => { + // El muestreo nativo solo aporta algo donde el Webview pierde el mouseleave + // del DOM (#154). En Linux/WebKitGTK devuelve (0,0) en vez de fallar, asi que + // compararlo contra los bounds lee «fuera» y dispara el cierre cada 400 ms. + expect(shouldSampleNativePresence('macos')).toBe(true); + expect(shouldSampleNativePresence('windows')).toBe(false); + expect(shouldSampleNativePresence('linux')).toBe(false); + }); + + it('preserva exactamente el gate que sustituye: /Macintosh|Mac OS X/.test(ua)', () => { + const MAC_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15'; + const WINDOWS_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'; + const LINUX_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15'; + const legacy = (ua: string) => /Macintosh|Mac OS X/.test(ua); + expect(shouldSampleNativePresence('macos')).toBe(legacy(MAC_UA)); + expect(shouldSampleNativePresence('windows')).toBe(legacy(WINDOWS_UA)); + expect(shouldSampleNativePresence('linux')).toBe(legacy(LINUX_UA)); + }); +}); diff --git a/src/lib/detail-presence.ts b/src/lib/detail-presence.ts index 77bf1f25..75f2dbb7 100644 --- a/src/lib/detail-presence.ts +++ b/src/lib/detail-presence.ts @@ -10,8 +10,23 @@ * using the same close timer, independently of stale DOM presence flags. */ +import type { Os } from './os-detect'; + export type PresenceSurface = 'widget' | 'detail'; +/** + * Does native presence sampling belong to this platform at all? + * + * Only where the DOM stops delivering the signal it is meant to supplement: + * a transparent, non-activating macOS Webview can drop `mouseleave` (#154). + * WebKitGTK does not fail there — `cursorPosition()` answers (0,0) — so the + * sample reads "outside", and every 400 ms tick closes the popup the user + * just opened. The DOM handlers stay the close path everywhere else. + */ +export function shouldSampleNativePresence(os: Os): boolean { + return os === 'macos'; +} + export interface DetailPresenceHooks { /** Popup currently open (a detail state is showing). */ isOpen(): boolean; diff --git a/src/lib/os-detect.test.ts b/src/lib/os-detect.test.ts new file mode 100644 index 00000000..608051cf --- /dev/null +++ b/src/lib/os-detect.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from 'vitest'; +import { openDelayForOs, osFromUA } from './os-detect'; + +const WINDOWS = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0'; +const MAC_SAFARI = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15'; +const MAC_WEBKIT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)'; +const LINUX_X11 = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15'; +const LINUX_WAYLAND = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) wv'; + +describe('osFromUA', () => { + it('reconoce las tres plataformas en las que se distribuye Quorb', () => { + expect(osFromUA(WINDOWS)).toBe('windows'); + expect(osFromUA(MAC_SAFARI)).toBe('macos'); + expect(osFromUA(MAC_WEBKIT)).toBe('macos'); + expect(osFromUA(LINUX_X11)).toBe('linux'); + expect(osFromUA(LINUX_WAYLAND)).toBe('linux'); + }); + + it('funciona igual con X11 y con Wayland en Linux: la UA no los distingue', () => { + // Ni /Macintosh/ ni /Windows/ aparecen en ninguno de los dos: el compositor + // no llega a la UA, por eso el backend (#128) y no el frontend decide. + expect(osFromUA(LINUX_X11)).toBe(osFromUA(LINUX_WAYLAND)); + }); + + it('prioriza Windows cuando la UA menciona ambas plataformas', () => { + // El orden de las comprobaciones es parte del contrato: /Windows/ gana. + expect(osFromUA('Mozilla/5.0 (Windows NT 10.0; Mac OS X 10_15_7)')).toBe('windows'); + }); + + it('deja en «linux» todo lo que no es Windows ni macOS, sin adivinar', () => { + // Android también cae aquí: es el bucket «resto». Quien necesita la + // distinción (excluir Android) usa su propio /Linux/ && !/Android/, como + // showDesktopCompat() en desktop-compat.ts. + expect(osFromUA('Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36')).toBe('linux'); + expect(osFromUA('Mozilla/5.0 (X11; FreeBSD amd64)')).toBe('linux'); + // Sin UA (headless, tests): nunca se asumirá Windows ni macOS. + expect(osFromUA('')).toBe('linux'); + }); +}); + +describe('openDelayForOs', () => { + it('mantiene los 90 ms de Windows y macOS y los 350 ms de Linux', () => { + expect(openDelayForOs('windows')).toBe(90); + expect(openDelayForOs('macos')).toBe(90); + expect(openDelayForOs('linux')).toBe(350); + }); + + it('es el mismo delay que el gate de UA que sustituye', () => { + // Regresión sobre OPEN_DELAY: los dos call sites tenían /Windows|Macintosh|Mac OS X/. + const legacyDelay = (ua: string) => (/Windows|Macintosh|Mac OS X/.test(ua) ? 90 : 350); + for (const ua of [WINDOWS, MAC_SAFARI, MAC_WEBKIT, LINUX_X11, LINUX_WAYLAND, '']) { + expect(openDelayForOs(osFromUA(ua))).toBe(legacyDelay(ua)); + } + }); +}); \ No newline at end of file diff --git a/src/lib/os-detect.ts b/src/lib/os-detect.ts new file mode 100644 index 00000000..b61f8ef2 --- /dev/null +++ b/src/lib/os-detect.ts @@ -0,0 +1,42 @@ +/** + * Which of the three platforms Quorb ships for is serving this webview. + * + * The UA is the only platform signal the frontend has, and it is injected so + * the gates stay testable. It deliberately says nothing about the compositor: + * X11 and Wayland are indistinguishable here, which is why the desktop-surface + * decision comes from the backend (`get_wm_info` → `wm_compat.rs`, #128). + * + * One helper, one order. The three inline regexes this replaces disagreed on + * edge cases, and the gates they feed (`OPEN_DELAY`, the DWM recovery loop of + * #148, the cursor presence sampling of #154) are each platform-scoped for a + * different reason — so a divergence between them is a silent behavior change. + */ + +/** Windows, macOS, or everything else (Linux, and its mobile/other variants). */ +export type Os = 'windows' | 'macos' | 'linux'; + +/** + * `linux` is the honest "the rest" bucket, not a claim about the kernel. + * Callers that must exclude Android (mobile UAs also say `Linux`) keep their own + * `/Linux/ && !/Android/` test — see `showDesktopCompat()` in desktop-compat.ts. + * `Windows` is checked first on purpose: a UA naming both platforms must land on + * Windows, and that order is part of the contract. + */ +export function osFromUA(ua: string): Os { + if (/Windows/.test(ua)) return 'windows'; + if (/Macintosh|Mac OS X/.test(ua)) return 'macos'; + return 'linux'; +} + +/** + * How long a pointer sweep must rest on another orb before it opens the popup. + * + * Windows and macOS keep the original 90 ms: there the compositor and #164 + * already contain accidental opens, and a long delay is perceptible. Linux has + * no containment net — the native presence sampling of #154 exists only on + * macOS — so an accidental sweep reaches the other orb and 350 ms keeps the + * popup legible instead of closing it under the pointer. + */ +export function openDelayForOs(os: Os): number { + return os === 'windows' || os === 'macos' ? 90 : 350; +} \ No newline at end of file diff --git a/src/lib/widget-recovery.test.ts b/src/lib/widget-recovery.test.ts index 8ed50e98..525177b9 100644 --- a/src/lib/widget-recovery.test.ts +++ b/src/lib/widget-recovery.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import { createWidgetRecovery, type RecoverySnapshot } from './widget-recovery'; +import { createWidgetRecovery, shouldAuditNativePosition, type RecoverySnapshot } from './widget-recovery'; const primary = { x: 0, y: 0, w: 4096, h: 1152 }; function snapshot(over: Partial = {}): RecoverySnapshot { @@ -114,3 +114,23 @@ describe('widget off-screen recovery', () => { expect(s.recover).toHaveBeenCalledTimes(2); }); }); + +describe('shouldAuditNativePosition', () => { + const WINDOWS_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'; + const MAC_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15'; + const LINUX_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15'; + + it('solo audita en Windows: en Linux el recovery seria un falso positivo estructural', () => { + // Wayland xdg-shell devuelve outerPosition() === (0,0) por diseño y GTK + // dimensiona distinto, asi que cada tick «corregiria» una ventana sana (#148). + expect(shouldAuditNativePosition('windows')).toBe(true); + expect(shouldAuditNativePosition('macos')).toBe(false); + expect(shouldAuditNativePosition('linux')).toBe(false); + }); + + it('preserva exactamente el gate que sustituye: /Windows/.test(ua)', () => { + expect(shouldAuditNativePosition('windows')).toBe(/Windows/.test(WINDOWS_UA)); + expect(shouldAuditNativePosition('macos')).toBe(/Windows/.test(MAC_UA)); + expect(shouldAuditNativePosition('linux')).toBe(/Windows/.test(LINUX_UA)); + }); +}); diff --git a/src/lib/widget-recovery.ts b/src/lib/widget-recovery.ts index 8f45ac0c..f1cace53 100644 --- a/src/lib/widget-recovery.ts +++ b/src/lib/widget-recovery.ts @@ -1,4 +1,5 @@ import { samePhysical, type PhysicalBounds } from './detail-panel'; +import type { Os } from './os-detect'; export interface RecoverySnapshot { bounds: PhysicalBounds; @@ -25,6 +26,20 @@ function overlaps(a: PhysicalBounds, b: PhysicalBounds): boolean { && a.y < b.y + b.h && a.y + a.h > b.y; } +/** + * Does auditing native reality belong to this platform at all? + * + * Only Windows displaces or resizes a normal window without the monitor + * geometry or our cached target changing (#147/#148). On xdg-shell + * `outerPosition()` is (0,0) by design and GTK sizing differs, so auditing + * there reads a healthy window as displaced and re-places it every tick — + * the flicker and disappearing widget of #168. Named and tested so the gate + * keeps its reason instead of surviving as an inline condition. + */ +export function shouldAuditNativePosition(os: Os): boolean { + return os === 'windows'; +} + /** Check native reality, not the last successfully requested rectangle. * Hidden/minimized windows belong to the user; incomplete monitor reads are not * evidence of displacement. Never overlap ticks or revive stale drag/unmount work. diff --git a/src/styles.css b/src/styles.css index bc50a4f6..d725e660 100644 --- a/src/styles.css +++ b/src/styles.css @@ -35,11 +35,20 @@ code { font-family: var(--font-mono); font-size: 0.92em; color: var(--pink); } a { color: var(--red-hover); } /* ───────── widget (ventana transparente) ───────── */ -html[data-window='widget'], html[data-window='widget'] body, -html[data-window='detail'], html[data-window='detail'] body { background: transparent; overflow: hidden; user-select: none; } +/* Los `!important` de este bloque y de `.dock` son los tres primeros + candidatos a eliminar si algún día se refactoriza el cascade: hacen falta + porque WebKitGTK no respeta la transparencia si `#root` o `.dock` heredan + un fondo opaco, y el sintoma (rectángulo negro) es indistinguible de un + fallo de WM. Antes de borrarlos, comprobar X11 y Wayland. */ +html[data-window='widget'], html[data-window='widget'] body, html[data-window='widget'] #root, +html[data-window='detail'], html[data-window='detail'] body, html[data-window='detail'] #root { + background: transparent !important; + overflow: hidden; + user-select: none; +} /* Cada ventana mide sólo su contenido: la tira y el detalle no comparten geometría. */ -.dock { position: fixed; inset: 0; } +.dock { position: fixed; inset: 0; background: transparent !important; } .dock > .strip, .dock > .panel { position: absolute; } /* La ventana ya aparece colocada: no trasladar su contenido al abrirla. */ .detail-dock .panel { animation: none; }