Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/i18n-inventory.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# i18n inventory (egdev6/quorb#66)

Generated by `node scripts/i18n-inventory.mjs` from the source trees `src/` = `82db1dfd8212733b638db35f84da395cbde06e1b` and `src-tauri/src/` = `4e040c3e38251119abf3e7d0de46376d82d9c885`.
Generated by `node scripts/i18n-inventory.mjs` from the source trees `src/` = `5a30dc2626849ac424c2d9f50028b10cb7b379bb` and `src-tauri/src/` = `4e040c3e38251119abf3e7d0de46376d82d9c885`.
Any commit whose `git rev-parse <commit>:src` and `<commit>:src-tauri/src` match has these exact texts.
Do not edit by hand: regenerate, or verify with `node scripts/i18n-inventory.mjs --check`.

Expand Down
4 changes: 4 additions & 0 deletions src/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ export function Widget() {

/** A pointer transition reported by one of the two surfaces. */
const applyHover = (event: HoverTransition) => {
// Entry between native samples ends shortcut grace, without feeding
// ordinary hover into the native presence tracker.
if (event.kind === 'enter') presenceRef.entryDuringShortcutGrace(event.surface);
const at = Date.now();
const previous = hoverPresence();
const next = nextPointerTarget(previous, { ...event, at });
Expand Down Expand Up @@ -1234,6 +1237,7 @@ export function Widget() {
cancelTimers();
setAnchorRel(relOf(el));
setPanel((current) => hoverPanel(current, top.id));
presenceRef.beginShortcut();
// Si no pasas el ratón por encima, se cierra solo (salvo que se anclara).
armClose(8000);
}, 80);
Expand Down
102 changes: 102 additions & 0 deletions src/lib/auto-hide.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { resetDragMode, setDragMode } from './drag-session';
import { contains, nearestEdge, panelHeightLimit, stripRect, type Edge } from './dock';
import { DETAIL_EVENTS, physicalPanelBounds } from './detail-panel';
import { POINTER_SURFACE_EVENT } from './hover-presence';
import type { DetailPresence } from './detail-presence';
import { NO_PANEL, type PanelState } from './anchor-panel';
import type { UsageReport } from './types';
import { SLOT, SKIP, WIDGET_REFS, WIDGET_STATE_COUNT, WIDGET_REF_COUNT, WIDGET_STATES } from './test-slots';
Expand Down Expand Up @@ -1811,6 +1812,107 @@ describe('hover presence wiring', () => {
vi.unstubAllGlobals();
});

const openShortcut = async () => {
const el = { getBoundingClientRect: () => ({ left: 0, top: 0, width: 40, height: 40 }) };
widgetEffects.refs[SLOT.orbsRef].current = { querySelector: () => el };
(widgetEffects.refs[SLOT.openPeakRef].current as () => void)();
await vi.advanceTimersByTimeAsync(80);
};
const nativePresence = () => widgetEffects.refs[SLOT.presenceRef].current as DetailPresence;

it.each(['widget', 'detail'] as const)('keeps ordinary %s hover out of the native shortcut tracker (#309)', async (surface) => {
const { dock, detail } = await wire();
// An ordinary entry must still cancel a pending DOM hover close.
dock.onMouseLeave();
if (surface === 'widget') dock.onMouseEnter();
else detail('enter');
expect(nativePresence().isAnyInside()).toBe(false);
await vi.advanceTimersByTimeAsync(1000);
expect(widgetEffects.states[SLOT.panel]).toEqual({ providerId: 'a', anchored: false });
if (surface === 'widget') dock.onMouseLeave();
else detail('leave');
await vi.advanceTimersByTimeAsync(279);
expect(widgetEffects.states[SLOT.panel]).toEqual({ providerId: 'a', anchored: false });
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
expect(nativePresence().isAnyInside()).toBe(false);
});

it.each(['widget', 'detail'] as const)('ends shortcut grace on a relayed entry into %s (#309)', async (surface) => {
const { native } = await wire();
await openShortcut();
nativePresence().sample(false, false);
native(surface, 'enter');
expect(nativePresence().isAnyInside()).toBe(true);
// A missed leave between samples still uses the ordinary close delay.
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(279);
expect(widgetEffects.states[SLOT.panel]).toEqual({ providerId: 'a', anchored: false });
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
});

it('keeps a shortcut detail open for exactly eight seconds despite outside native samples (#309)', async () => {
await wire();
await openShortcut();
for (let i = 0; i < 20; i++) {
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(i === 19 ? 399 : 400);
expect(widgetEffects.states[SLOT.panel]).toMatchObject({ providerId: 'a', anchored: false });
}
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
});

it.each(['widget', 'detail'] as const)('ends shortcut grace on DOM entry into %s before the next native sample (#309)', async (surface) => {
const { dock, detail } = await wire();
await openShortcut();
nativePresence().sample(false, false);
if (surface === 'widget') dock.onMouseEnter();
else detail('enter');
// No further entry or leave event: the next native sample must recover
// the missed DOM leave, even though entry happened between samples.
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(279);
expect(widgetEffects.states[SLOT.panel]).toMatchObject({ providerId: 'a' });
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
});

it.each(['widget', 'detail'] as const)('holds a shortcut detail inside %s then closes normally on native exit (#309)', async (surface) => {
await wire();
await openShortcut();
nativePresence().sample(surface === 'widget', surface === 'detail');
await vi.advanceTimersByTimeAsync(10000);
expect(widgetEffects.states[SLOT.panel]).toMatchObject({ providerId: 'a' });
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(279);
expect(widgetEffects.states[SLOT.panel]).toMatchObject({ providerId: 'a' });
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
});

it('restarts the eight-second lifetime on a repeated shortcut without changing provider (#309)', async () => {
await wire();
await openShortcut();
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(100);
await openShortcut();
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(7999);
expect(widgetEffects.states[SLOT.panel]).toEqual({ providerId: 'a', anchored: false });
await vi.advanceTimersByTimeAsync(1);
expect(widgetEffects.states[SLOT.panel]).toEqual(NO_PANEL);
});

it('leaves an already-pinned detail untouched by the shortcut (#309)', async () => {
await wire(true, { providerId: 'b', anchored: true });
await openShortcut();
nativePresence().sample(false, false);
await vi.advanceTimersByTimeAsync(10000);
expect(widgetEffects.states[SLOT.panel]).toEqual({ providerId: 'b', anchored: true });
});

it('closes the detail when it reports leave even if the strip never reported mouseleave', async () => {
const { dock, detail } = await wire();
dock.onMouseEnter(); // The pointer enters the strip.
Expand Down
44 changes: 44 additions & 0 deletions src/lib/detail-presence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,50 @@ function setup(isOpen: () => boolean = () => true) {
afterEach(() => vi.useRealTimers());

describe('createDetailPresence', () => {
it.each(['widget', 'detail'] as const)('ignores shortcut-only entry into %s before any shortcut', (surface) => {
const { tracker, scheduleClose, cancelClose } = setup();
tracker.entryDuringShortcutGrace(surface);
expect(tracker.isAnyInside()).toBe(false);
expect(scheduleClose).not.toHaveBeenCalled();
expect(cancelClose).not.toHaveBeenCalled();
// The ignored entry must not reconcile native presence either.
tracker.sample(false, false);
expect(scheduleClose).toHaveBeenCalledTimes(1);
expect(cancelClose).not.toHaveBeenCalled();
});

it.each(['widget', 'detail'] as const)('consumes shortcut grace on the first entry into %s', (surface) => {
const { tracker, scheduleClose, cancelClose } = setup();
tracker.beginShortcut();
tracker.sample(false, false);
expect(scheduleClose).not.toHaveBeenCalled();
expect(cancelClose).not.toHaveBeenCalled();
tracker.entryDuringShortcutGrace(surface);
expect(tracker.isAnyInside()).toBe(true);
expect(scheduleClose).not.toHaveBeenCalled();
expect(cancelClose).toHaveBeenCalledTimes(1);
tracker.sample(false, false);
expect(tracker.isAnyInside()).toBe(false);
expect(scheduleClose).toHaveBeenCalledTimes(1);
expect(cancelClose).toHaveBeenCalledTimes(1);
});

it.each(['widget', 'detail'] as const)('ignores shortcut-only entry into %s after grace was consumed', (surface) => {
const { tracker, scheduleClose, cancelClose } = setup();
tracker.beginShortcut();
tracker.sample(true, false);
// No later DOM entry may change even an already-inside native sample.
tracker.entryDuringShortcutGrace(surface);
expect(tracker.isAnyInside()).toBe(true);
expect(scheduleClose).not.toHaveBeenCalled();
expect(cancelClose).toHaveBeenCalledTimes(1);
tracker.sample(false, false);
tracker.entryDuringShortcutGrace(surface);
expect(tracker.isAnyInside()).toBe(false);
expect(scheduleClose).toHaveBeenCalledTimes(1);
expect(cancelClose).toHaveBeenCalledTimes(1);
});

it('cierra aunque la primera observación ya esté fuera de ambas ventanas y no haya mouseleave', () => {
const { tracker, scheduleClose } = setup();
tracker.sample(false, false);
Expand Down
38 changes: 31 additions & 7 deletions src/lib/detail-presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*
* DOM handlers remain the fast close path; native samples provide a fallback
* using the same close timer, independently of stale DOM presence flags.
* A shortcut keeps its eight-second timeout until the first DOM or sampled
* entry into either surface; subsequent exits use the ordinary close delay.
*/

import type { Os } from './os-detect';
Expand Down Expand Up @@ -43,19 +45,35 @@ export interface DetailPresence {
sample(widget: boolean, detail: boolean): void;
/** True while the cursor is over either surface. */
isAnyInside(): boolean;
/** Start a shortcut lifetime: absence cannot close it before first entry. */
beginShortcut(): void;
/** Consume shortcut grace on entry; otherwise leave native presence and timers untouched. */
entryDuringShortcutGrace(surface: PresenceSurface): void;
/** Forget presence (popup closed by another path). */
reset(): void;
}

export function createDetailPresence(hooks: DetailPresenceHooks): DetailPresence {
const inside: Record<PresenceSurface, boolean> = { widget: false, detail: false };
let reconciled = false;
let awaitingEntry = false;

const reset = () => {
awaitingEntry = false;
reconciled = false;
inside.widget = false;
inside.detail = false;
};

const sample = (widget: boolean, detail: boolean) => {
const wasInside = inside.widget || inside.detail;
const anyInside = widget || detail;
inside.widget = widget;
inside.detail = detail;
if (awaitingEntry) {
if (!anyInside) return;
awaitingEntry = false;
}
// Repeated outside samples must not keep restarting the close delay.
if (reconciled && wasInside === anyInside) return;
reconciled = true;
Expand All @@ -64,19 +82,25 @@ export function createDetailPresence(hooks: DetailPresenceHooks): DetailPresence
else hooks.scheduleClose();
};

const cursor = (surface: PresenceSurface, next: boolean) => {
sample(surface === 'widget' ? next : inside.widget, surface === 'detail' ? next : inside.detail);
};

return {
cursor(surface, next) {
sample(surface === 'widget' ? next : inside.widget, surface === 'detail' ? next : inside.detail);
},
cursor,
sample,
isAnyInside() {
return inside.widget || inside.detail;
},
reset() {
reconciled = false;
inside.widget = false;
inside.detail = false;
beginShortcut() {
// A repeated shortcut starts a new initial lifetime too.
reset();
awaitingEntry = true;
},
entryDuringShortcutGrace(surface) {
if (awaitingEntry) cursor(surface, true);
},
reset,
};
}

Expand Down
Loading