diff --git a/packages/shell/src/frame/AppMenu.tsx b/packages/shell/src/frame/AppMenu.tsx index 734cfe6..509a74b 100644 --- a/packages/shell/src/frame/AppMenu.tsx +++ b/packages/shell/src/frame/AppMenu.tsx @@ -24,6 +24,7 @@ import { DEFAULT_MENU, ZOOM_MAX, ZOOM_MIN, findSpec, joinGroups, languageChoice, languageRows, menuText, moveStop, planMenu, shortcutText, specRows, submenuKeys, submenuLeft, typeahead, updateRow, type BuiltinMenuItem, type MenuEnv, type MenuItemRow, type MenuRow, } from './menuModel.ts'; +import { ReportDialog } from './ReportDialog.tsx'; import { safe, setSafeMode } from './safeStore.ts'; import { hasFeature, site } from './site.ts'; import { isWeb, setOverlay, shell, type TabParams } from './state.ts'; @@ -81,6 +82,7 @@ export function AppMenu() { const [version, setVersion] = useState(''); const [update, setUpdate] = useState({ state: 'idle' }); const [askedUpdate, setAskedUpdate] = useState(false); + const [reporting, setReporting] = useState(false); const [error, setError] = useState(''); const [, tick] = useReducer((n: number) => n + 1, 0); const button = useRef(null); @@ -306,6 +308,7 @@ export function AppMenu() { case 'safe-mode': return safe.active ? item(id, menuText('safeLeave'), 'shield', { run: () => setSafeMode(false) }) : item(id, menuText('safeRestart'), 'shield', { submenu: true }); + case 'report': return item(id, menuText('report'), 'flag', { run: () => setReporting(true) }); case 'about': return item(id, menuText('about', { product: config.product }), 'info', { run: () => shell.openPanelSection('home') }); case 'settings': return item(id, section(t('wb.panel.section.settings')), 'settings', { run: () => shell.openPanelSection('settings') }); } @@ -523,6 +526,7 @@ export function AppMenu() { {renderMenus()} , document.body)} + {reporting && setReporting(false)}/>} ; } diff --git a/packages/shell/src/frame/ReportDialog.tsx b/packages/shell/src/frame/ReportDialog.tsx new file mode 100644 index 0000000..2ccf796 --- /dev/null +++ b/packages/shell/src/frame/ReportDialog.tsx @@ -0,0 +1,102 @@ +// "Report a problem": a small dialog that shows the diagnostic summary (reportModel.ts) exactly as +// it would be shared, with Copy and a button that opens the project's new-issue page in the system +// browser. The app sends nothing itself: no request, and the summary is never put in a URL (the +// issue page opens bare; the owner pastes what they copied). Without a configured issue page the +// button is off and says why. + +import { useEffect, useRef, useState } from 'react'; +import { createPortal } from 'react-dom'; +import { invoke } from './bridge.ts'; +import { useT } from './hooks.ts'; +import { textLocale } from './i18n.ts'; +import { Icon } from './icons.tsx'; +import { menuText } from './menuModel.ts'; +import { buildReport, systemFromUserAgent, webviewFromUserAgent, type ReportInfo } from './reportModel.ts'; +import { safe } from './safeStore.ts'; +import { site } from './site.ts'; +import { setOverlay } from './state.ts'; + +type Hints = { platformVersion?: string; architecture?: string; bitness?: string }; + +/** What the engine says about the system when asked (Chromium webviews; others have the user agent only). */ +async function systemHints(): Promise { + try { + const data = (navigator as Navigator & { userAgentData?: { getHighEntropyValues(hints: string[]): Promise } }).userAgentData; + return data ? await data.getHighEntropyValues(['platformVersion', 'architecture', 'bitness']) : {}; + } catch { return {}; } +} + +/** Gathers the facts a report may say: from the app's config and the shell's own state, nothing about the person. */ +async function collect(): Promise { + const config = site(); + const menu = config.menu ?? {}; + const themes = config.themes; + const [appVersion, hints, mode, plugins, details] = await Promise.all([ + menu.version ? menu.version().catch(() => '') : Promise.resolve(''), + systemHints(), + menu.modes ? menu.modes.current().catch(() => null) : Promise.resolve(undefined), + invoke>('plugins_list').then(list => list.filter(plugin => plugin.enabled === true).map(plugin => String(plugin.file ?? '')), () => null), + menu.report?.details ? Promise.resolve(menu.report.details()).catch(() => []) : Promise.resolve([]), + ]); + if (themes) await themes.loadThemes().catch(() => {}); + const choice = themes?.current().choice; + const theme = themes ? themes.adapter.resolve(choice) as { id?: unknown; icons?: { pack?: unknown } } : null; + return { + product: config.product, + appVersion, + system: systemFromUserAgent(navigator.userAgent, hints), + webview: webviewFromUserAgent(navigator.userAgent), + language: menu.languages?.state().locale ?? textLocale(), + languageChoice: menu.languages?.state().preference ?? 'fixed', + mode, + theme: themes ? themes.adapter.preset(choice) : undefined, + iconPack: theme ? (typeof theme.icons?.pack === 'string' ? theme.icons.pack : '') : undefined, + plugins, + details, + safeMode: safe.active, + }; +} + +export function ReportDialog({ onClose }: { onClose(): void }) { + const t = useT(); + const [text, setText] = useState(null); + const [copied, setCopied] = useState(false); + const dialog = useRef(null); + const issueUrl = site().menu?.report?.issueUrl; + const canOpen = typeof issueUrl === 'string' && /^https:\/\//.test(issueUrl); + + useEffect(() => { + setOverlay(1); + invoke('shell_focus').catch(() => {}); + let live = true; + collect().then(info => { if (live) setText(buildReport(info)); }, () => { if (live) setText(''); }); + dialog.current?.focus(); + return () => { live = false; setOverlay(-1); }; + }, []); + + const copy = async () => { + if (!text) return; + try { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2200); } + catch { dialog.current?.querySelector('textarea')?.select(); } + }; + + return createPortal(
+
event.stopPropagation()} onKeyDown={event => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); onClose(); } }}> +
+

{menuText('reportTitle')}

+ +
+

{menuText('reportLede')}

+