App menu: the titlebar's "Settings and more" (Alt+F, F10, the palette, the account menu's last row) with rows from the site config; page zoom per tab in the host
Frame: AppMenu.tsx is a menu at the end of the titlebar cluster (before the caption buttons; macOS has none there). Its rows are `ShellSite.menu`: ordered groups of built-in rows by name and the app's own ({id, label, icon, shortcut, hint, when, checked, run | submenu}); `DEFAULT_MENU`, `menuWith` and `menuWithout` order, add and remove. A built-in row shows only when the app serves it (decks, `menu.languages`, themes, `menu.modes`, and `features`: zoom, store, workspaces, developer, updates), so no app gets a dead row. Language, Theme, Mode, Workspaces and Developer are submenus; Language and Theme apply live and keep the menu open, Mode asks the same keep-my-changes question as Settings (panel `menuModes()`). Keyboard: arrows, Home/End, type-ahead, the arrow along the reading direction opens a submenu, Esc closes one level; ARIA menu roles; submenus stay inside the window; one highlight for pointer and keys. It is an overlay like the other shell menus (the shell is raised, panes stay visible, nothing is dimmed).
Words: menuMessages.en.json (`wb.menu.*`), read through the framework i18n with that English as the fallback until the catalogs have them; words the panel already has are reused.
Host: `tab_zoom {id, factor}` (shell-only) sets a tab's page zoom with the engine's own zoom, clamped to 25%..500% and remembered per tab id in app data `zoom.json` (a number per tab id, nothing else; a closed tab's entry goes); without a factor it reads. A tab may forward four more shortcut names: `app-menu`, `zoom-in`, `zoom-out`, `zoom-reset`. The titlebar shows a zoom chip only while the pane in front is not at 100%.
create-waybetter: `tab_zoom` in the shell capability list; the template says which panel sections it lacks (store, updates) and how to add menu rows.
This commit is contained in:
parent
6e80b3e2c9
commit
613723ee93
27 changed files with 1587 additions and 18 deletions
54
packages/shell/src/frame/zoomStore.ts
Normal file
54
packages/shell/src/frame/zoomStore.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// Page zoom of the tab webviews, as the shell knows it. Native code owns it (`tab_zoom`, shell-only:
|
||||
// the engine's own page zoom, clamped and remembered per tab; waybetter-host `zoom.rs`); the shell
|
||||
// asks for a factor and keeps what native code answered, for the app menu's zoom row and the
|
||||
// titlebar chip. Nothing here touches a page's CSS.
|
||||
|
||||
import { invoke } from './bridge.ts';
|
||||
import { deckById, decks } from './deckStore.ts';
|
||||
import { zoomStep } from './menuModel.ts';
|
||||
import { hasFeature } from './site.ts';
|
||||
import { isWeb, shell, type TabParams } from './state.ts';
|
||||
|
||||
const factors = new Map<string, number>();
|
||||
|
||||
/** The factor tab `id` shows, as last answered by native code (100% until asked). */
|
||||
export const zoomOf = (id: string | null) => (id ? factors.get(id) ?? 1 : 1);
|
||||
|
||||
function note(id: string, factor: number) {
|
||||
if (!Number.isFinite(factor) || zoomOf(id) === factor) return;
|
||||
if (factor === 1) factors.delete(id); else factors.set(id, factor);
|
||||
window.dispatchEvent(new CustomEvent('bt-zoom', { detail: id }));
|
||||
}
|
||||
|
||||
/** The active pane's page: the tab in front, or the focused column of the deck in front. None for the app's own tabs. */
|
||||
export function zoomTarget(): string | null {
|
||||
const panel = shell.api?.activePanel;
|
||||
if (!panel) return null;
|
||||
if (isWeb(panel)) return panel.id;
|
||||
const params = panel.params as TabParams | undefined;
|
||||
if (params?.kind !== 'deck') return null;
|
||||
const deck = deckById(params.deckId);
|
||||
const focused = decks.focus.get(params.deckId);
|
||||
return deck?.columns.find(column => column.id === focused)?.tabId ?? null;
|
||||
}
|
||||
|
||||
/** Reads a tab's remembered zoom (a restored tab may come back zoomed). */
|
||||
export async function readZoom(id: string | null): Promise<void> {
|
||||
if (!id || !hasFeature('zoom')) return;
|
||||
try { note(id, await invoke<number>('tab_zoom', { id })); } catch { /* No such webview yet: 100%. */ }
|
||||
}
|
||||
|
||||
/** Sets a tab's zoom; native code answers the factor in effect. */
|
||||
export async function setZoom(id: string, factor: number): Promise<number> {
|
||||
const applied = await invoke<number>('tab_zoom', { id, factor });
|
||||
note(id, applied);
|
||||
return applied;
|
||||
}
|
||||
|
||||
/** One step in (`1`), out (`-1`) or back to 100% (`0`) for tab `id` (default: the active pane's page). */
|
||||
export async function stepZoom(direction: 1 | -1 | 0, id: string | null = zoomTarget()): Promise<void> {
|
||||
if (!id || !hasFeature('zoom')) return;
|
||||
const next = zoomStep(zoomOf(id), direction);
|
||||
if (next === zoomOf(id)) return;
|
||||
try { await setZoom(id, next); } catch (error) { console.error('[shell] tab_zoom', error); }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue