Diagnostics for focus and layering (--diag / WAYBETTER_DIAG=1): one timestamped line per event in the app's log folder

For the macOS reports (the menu never shows and the window goes inactive on a click; the find field gets no keyboard): off unless the app is started with `--diag` or WAYBETTER_DIAG=1. Then native code and the shell append to `diag.log` in the app's log folder (truncated at launch): menu open requests and every close with its reason, overlay counts, raise/lower and `shell_raise` results, native `shell_focus` calls and their result, the shell document's focus/blur/visibility, and where the find bar's focus is right after it opens and 300 ms later. A line is an event and a few words in plain ASCII (capped); never a URL, a query or page text. `diag_get` / `diag_log` are shell-only (in commands::SHELL and the template's list).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-10-01 04:11:53 +07:00
parent 7f9e172196
commit 43fc8a15f5
8 changed files with 147 additions and 69 deletions

View file

@ -15,6 +15,7 @@ import { useEffect, useLayoutEffect, useReducer, useRef, useState, type Keyboard
import { createPortal } from 'react-dom';
import { parseUpdateStatus, type UpdateStatus } from '../updateModel.ts';
import { invoke, listen } from './bridge.ts';
import { describe, diag } from './diag.ts';
import { decks } from './deckStore.ts';
import { refreshDev } from './devHost.ts';
import { useDev, usePaneTick, useT } from './hooks.ts';
@ -107,6 +108,7 @@ export function AppMenu() {
}, []);
function show(request: AppMenuRequest = {}) {
diag(`menu open: anchor=${request.anchor ?? 'button'} keyboard=${!!request.keyboard} hasFocus=${document.hasFocus()} active=${describe(document.activeElement)}`);
const logo = request.anchor === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
const rect = (logo ?? button.current)?.getBoundingClientRect();
if (rect) {
@ -135,7 +137,8 @@ export function AppMenu() {
}
/** `escape`: back to what had focus before. `action` and `away`: nothing focused, so typing returns to the active pane. */
function close(how: 'escape' | 'action' | 'away' = 'away') {
function close(how: 'escape' | 'action' | 'away' = 'away', why = '') {
diag(`menu close: ${how}${why ? ` (${why})` : ''} hasFocus=${document.hasFocus()}`);
clearTimeout(hover.current.timer);
hover.current = { el: null };
focusNext.current = null;
@ -173,7 +176,11 @@ export function AppMenu() {
// The window lost the keyboard: the menu closes, unless the focus is back a moment later (taking the
// keyboard from a tab for Alt+F / F10 can pass through a blur on its way to the shell).
let leaving: ReturnType<typeof setTimeout> | undefined;
const away = () => { clearTimeout(leaving); leaving = setTimeout(() => { if (!document.hasFocus()) close(); }, 160); };
const away = () => {
diag(`menu: window blur hasFocus=${document.hasFocus()}`);
clearTimeout(leaving);
leaving = setTimeout(() => { if (!document.hasFocus()) close('away', 'blur'); else diag('menu: blur passed, focus is back'); }, 160);
};
const resized = () => close();
// Keys while nothing in the menu has focus (a click on its padding): Esc closes, arrows enter it.
const onKey = (event: KeyboardEvent) => {