Align the Wails desktop shell with the macOS Tahoe visual design: - Add bundled open-source Inter Variable (Latin) and multi-weight CJK font mapping tuned for Windows DirectWrite readability - Refine VMPage with compact Studio Display stand, 2x3 icon spec card, inline telemetry meters, single-row Connection list, numbered install guide, and one-click tech summary copy - Move LogPanel to full-width status bar with ambient WHPX status and pointer-captured vertical resize handle - Upgrade HostView tiles, InstallersPage skeletons/empty state, system theme detection, and unified Segmented/Switch primitives - Refine translucent chrome surfaces, GPU scaleX meters/progress, toast swipe/enter motion, and reduced-motion/transparency/contrast support
213 lines
8.2 KiB
TypeScript
213 lines
8.2 KiB
TypeScript
import { ArrowDown, ChevronDown, ChevronUp, Eraser, LoaderCircle, Pause, RefreshCw } from 'lucide-react'
|
|
import React, { useLayoutEffect, useRef, useState } from 'react'
|
|
import { t } from '../i18n'
|
|
import { LogLine } from '../lib/logs'
|
|
import { taskDetail, taskTitle } from '../lib/tasks'
|
|
import { Locale, Task } from '../types'
|
|
import { Button, IconButton, Tip } from '../ui/controls'
|
|
|
|
export type LogTab = 'app' | 'serial' | 'qemu'
|
|
|
|
interface Props {
|
|
locale: Locale
|
|
open: boolean
|
|
onToggle: () => void
|
|
tab: LogTab
|
|
onTab: (tab: LogTab) => void
|
|
lines: LogLine[]
|
|
unseenErrors: number
|
|
onClear: () => void
|
|
serialText: string
|
|
qemuText: string
|
|
showSerial: boolean
|
|
onRefreshSerial: () => void
|
|
onRefreshQemu: () => void
|
|
task: Task | null
|
|
runningTasks: number
|
|
onCancelTask: (id: string) => void
|
|
statusText?: string
|
|
statusWarn?: boolean
|
|
}
|
|
|
|
/** Sticks to the bottom until the user scrolls up; offers "jump to latest" then. */
|
|
function useStickToBottom(dep: unknown, active: boolean) {
|
|
const ref = useRef<HTMLDivElement>(null)
|
|
const [stuck, setStuck] = useState(true)
|
|
|
|
useLayoutEffect(() => {
|
|
const el = ref.current
|
|
if (el && active && stuck) el.scrollTop = el.scrollHeight
|
|
}, [dep, active, stuck])
|
|
|
|
const onScroll = () => {
|
|
const el = ref.current
|
|
if (!el) return
|
|
setStuck(el.scrollHeight - el.scrollTop - el.clientHeight < 24)
|
|
}
|
|
const jump = () => {
|
|
const el = ref.current
|
|
if (el) el.scrollTop = el.scrollHeight
|
|
setStuck(true)
|
|
}
|
|
return { ref, stuck, onScroll, jump }
|
|
}
|
|
|
|
const LOG_HEIGHT_KEY = 'reims-go-log-height'
|
|
const DEFAULT_LOG_HEIGHT = 240
|
|
const MIN_LOG_HEIGHT = 120
|
|
const MAX_LOG_HEIGHT = 520
|
|
|
|
export const LogPanel: React.FC<Props> = ({
|
|
locale, open, onToggle, tab, onTab, lines, unseenErrors, onClear, serialText, qemuText, showSerial, onRefreshSerial, onRefreshQemu,
|
|
task, runningTasks, onCancelTask, statusText, statusWarn,
|
|
}) => {
|
|
const tr = (k: Parameters<typeof t>[1]) => t(locale, k)
|
|
const content = tab === 'app' ? lines : tab === 'serial' ? serialText : qemuText
|
|
const { ref, stuck, onScroll, jump } = useStickToBottom(content, open)
|
|
|
|
const [height, setHeight] = useState<number>(() => {
|
|
try {
|
|
const saved = Number(localStorage.getItem(LOG_HEIGHT_KEY))
|
|
if (Number.isFinite(saved) && saved >= MIN_LOG_HEIGHT && saved <= MAX_LOG_HEIGHT) return saved
|
|
} catch {}
|
|
return DEFAULT_LOG_HEIGHT
|
|
})
|
|
const [dragging, setDragging] = useState(false)
|
|
const dragRef = useRef<{ startY: number; startH: number } | null>(null)
|
|
|
|
const onResizeDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
e.preventDefault()
|
|
e.currentTarget.setPointerCapture(e.pointerId)
|
|
dragRef.current = { startY: e.clientY, startH: height }
|
|
setDragging(true)
|
|
}
|
|
const onResizeMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
if (!dragRef.current) return
|
|
const next = Math.min(MAX_LOG_HEIGHT, Math.max(MIN_LOG_HEIGHT, Math.round(dragRef.current.startH + (dragRef.current.startY - e.clientY))))
|
|
setHeight(next)
|
|
}
|
|
const onResizeUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
if (!dragRef.current) return
|
|
dragRef.current = null
|
|
setDragging(false)
|
|
if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId)
|
|
try { localStorage.setItem(LOG_HEIGHT_KEY, String(height)) } catch {}
|
|
}
|
|
|
|
return (
|
|
<div className="logs">
|
|
{open && (
|
|
<div
|
|
className="log-resize-handle"
|
|
role="separator"
|
|
aria-orientation="horizontal"
|
|
aria-label={tr('resizeLogPanel')}
|
|
data-dragging={dragging}
|
|
onPointerDown={onResizeDown}
|
|
onPointerMove={onResizeMove}
|
|
onPointerUp={onResizeUp}
|
|
onPointerCancel={onResizeUp}
|
|
onDoubleClick={() => {
|
|
setHeight(DEFAULT_LOG_HEIGHT)
|
|
try { localStorage.setItem(LOG_HEIGHT_KEY, String(DEFAULT_LOG_HEIGHT)) } catch {}
|
|
}}
|
|
>
|
|
<span className="log-resize-pill" aria-hidden="true" />
|
|
</div>
|
|
)}
|
|
<div className="logbar">
|
|
{task ? (
|
|
<>
|
|
<Tip label={[task.step, taskDetail(task)].filter(Boolean).join(' · ') || taskTitle(locale, task)} side="top">
|
|
<span className="task" tabIndex={0}>
|
|
<LoaderCircle size={14} className="spin" aria-hidden="true" />
|
|
<span className="task-label">
|
|
{runningTasks > 1 ? t(locale, 'tasksRunning', { n: runningTasks }) : taskTitle(locale, task)}
|
|
</span>
|
|
{task.percent >= 0 && (
|
|
<>
|
|
<span className="progress" aria-hidden="true">
|
|
<span className="progress-fill" style={{ transform: `scaleX(${Math.max(0, Math.min(1, task.percent / 100))})` }} />
|
|
</span>
|
|
<span className="task-pct">{Math.floor(task.percent)}%</span>
|
|
</>
|
|
)}
|
|
</span>
|
|
</Tip>
|
|
{task.cancelable && (
|
|
<IconButton small tipSide="top" label={tr('pauseDownload')} icon={<Pause size={14} />} onClick={() => onCancelTask(task.id)} />
|
|
)}
|
|
</>
|
|
) : statusText ? (
|
|
<span className={`status-ambient${statusWarn ? ' warn' : ''}`}>{statusText}</span>
|
|
) : null}
|
|
<span className="spacer" />
|
|
{open && (
|
|
<div className="tabs" role="tablist">
|
|
<button type="button" role="tab" className="tab" aria-selected={tab === 'app'} onClick={() => onTab('app')}>
|
|
{tr('logActivity')}
|
|
</button>
|
|
{showSerial && (
|
|
<>
|
|
<button type="button" role="tab" className="tab" aria-selected={tab === 'serial'} onClick={() => onTab('serial')}>
|
|
{tr('logSerial')}
|
|
</button>
|
|
<button type="button" role="tab" className="tab" aria-selected={tab === 'qemu'} onClick={() => onTab('qemu')}>
|
|
{tr('logQemu')}
|
|
</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
)}
|
|
{open && tab === 'app' && lines.length > 0 && (
|
|
<IconButton small tipSide="top" label={tr('clear')} icon={<Eraser size={14} />} onClick={onClear} />
|
|
)}
|
|
{open && tab === 'serial' && (
|
|
<IconButton small tipSide="top" label={tr('refresh')} icon={<RefreshCw size={14} />} onClick={onRefreshSerial} />
|
|
)}
|
|
{open && tab === 'qemu' && (
|
|
<IconButton small tipSide="top" label={tr('refresh')} icon={<RefreshCw size={14} />} onClick={onRefreshQemu} />
|
|
)}
|
|
{!open && unseenErrors > 0 && <span className="badge badge-error" aria-hidden="true">{unseenErrors}</span>}
|
|
<Tip label={open ? tr('collapseLogs') : tr('expandLogs')} shortcut="Ctrl+L" side="top">
|
|
<button
|
|
type="button"
|
|
className="log-toggle-btn"
|
|
onClick={onToggle}
|
|
aria-expanded={open}
|
|
aria-label={open ? tr('collapseLogs') : tr('expandLogs')}
|
|
>
|
|
<span>{tr('logButton')}</span>
|
|
{open ? <ChevronDown size={14} aria-hidden="true" /> : <ChevronUp size={14} aria-hidden="true" />}
|
|
</button>
|
|
</Tip>
|
|
</div>
|
|
|
|
{open && (
|
|
<div className="logs-body-wrap">
|
|
<div className="logs-body" style={{ height }} ref={ref} onScroll={onScroll} role="log" aria-live="off">
|
|
{tab === 'app'
|
|
? (lines.length === 0
|
|
? <span className="muted">{tr('logsEmpty')}</span>
|
|
: lines.map((l) => (
|
|
<div key={l.id} className={`log-line ${l.level}`}>
|
|
<span className="log-ts">{l.ts}</span>
|
|
<span className="log-src">{l.source}</span>
|
|
<span className="log-msg">{l.line}</span>
|
|
</div>
|
|
)))
|
|
: tab === 'serial'
|
|
? (serialText || <span className="muted">{tr('logsEmpty')}</span>)
|
|
: (qemuText || <span className="muted">{tr('logsEmpty')}</span>)}
|
|
</div>
|
|
{!stuck && (
|
|
<Button className="jump-latest" icon={<ArrowDown size={14} />} onClick={jump}>
|
|
{tr('jumpLatest')}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|