依 R5 五輪決策把 visionA-local 從「Wails 內嵌 Next.js」重構為「Wails
本機伺服器控制台 + 瀏覽器 Web UI」模式(類比 Docker Desktop / Ollama)。
程式碼變動
- M8-1 砍 yt-dlp 全套(後端 resolver / URL handler / 前端 URL tab /
Makefile vendor / installer / bootstrap / CI workflow,-555 行)
- M8-2 砍 Mock 模式全套(driver/mock、mock_camera、Settings runtimeMode、
VISIONA_MOCK 環境變數,-528 行)
- M8-3 ffmpeg 從 GPL 切換到 LGPL 混合方案:Windows/Linux 用 BtbN 現成
LGPL binary,macOS 自 build minimal decoder-only 進 git
(vendor/ffmpeg/macos/ffmpeg 5.7MB + ffprobe 5.6MB,比 GPL 版省 85% 空間)
- M8-4 Wails Server Controller:state machine、log ring buffer 2000 行、
preferences.json atomic write、boot-id、Gin SkipPaths、shutdown 7+1 秒、
notify_*.go 三平台 OS 通知、watchServer 改 Error state 不 os.Exit
- M8-4b 啟動階段管線 R5-E:6 階段進度 event、20s soft / 60s hard timeout、
stage 5/6 skip 規則、sentinel file、RestartStartupSequence 5 步驟
- M8-5 Wails 控制台 vanilla HTML/JS/CSS(9 檔 ~2012 行)取代 M7-B splash:
state 視覺、log panel、startup progress panel、Stage 6 manual CTA
pulse、shutdown modal、Settings、Dark Mode、i18n 中英雙語
- M8-6 上傳影片副檔名擴充(mp4/avi/mov/mpeg/mpg)
- M8-7 Web UI Server Offline Overlay(role=alertdialog + focus trap +
wsEverConnected 容錯 + Page Visibility)
- M8-8 CORS middleware(127.0.0.1/localhost only + suffix attack 防護)+
ws/origin.go 獨立 WebSocket CheckOrigin 避 package cycle
- MAJ-4 server:shutdown-imminent WebSocket broadcast 機制
(/ws/system endpoint + notifyShutdownImminent helper)
- M8-9 Boot-ID + 瀏覽器 tab 自動重連(sessionStorage loop guard)
品質
- ~105+ 新 unit test + race detector (-count=2) 全綠
- 10 個 milestone 全部通過 Reviewer 審查
- 三方 v2 + v2.1 文件(PRD / Design Spec / TDD)+ 交叉互審紀錄
收錄在 .autoflow/
交付前待處理(M8-10)
- 重跑 make payload-macos 把舊 GPL 77MB binary 換成新 LGPL
- 三平台 end-to-end build 驗證
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
223 lines
11 KiB
JavaScript
223 lines
11 KiB
JavaScript
// visionA-local 控制台 i18n
|
||
// namespace: desktop-control
|
||
// 對齊 Design Spec v2.1 control-panel.md §9 + startup-progress.md §7
|
||
|
||
const dict = {
|
||
'zh-TW': {
|
||
'control.title': 'visionA-local · 伺服器控制台',
|
||
'control.status.idle': '閒置',
|
||
'control.status.starting': '啟動中...',
|
||
'control.status.running': '執行中',
|
||
'control.status.runningBrowserOpened': '執行中 · 已開啟瀏覽器',
|
||
'control.status.stopping': '停止中...',
|
||
'control.status.stopped': '已停止',
|
||
'control.status.error': '錯誤:{reason}',
|
||
'control.meta.port': '連接埠',
|
||
'control.meta.uptime': '執行時間',
|
||
'control.meta.pid': '程序 ID',
|
||
'control.meta.version': '版本',
|
||
'control.action.openBrowser': '在瀏覽器開啟',
|
||
'control.action.start': '啟動',
|
||
'control.action.stop': '停止',
|
||
'control.action.restart': '重新啟動',
|
||
'control.action.manage': '管理',
|
||
'control.action.stopServer': '停止伺服器',
|
||
'control.action.restartServer': '重新啟動伺服器',
|
||
'control.log.followTail': '自動跟隨最新',
|
||
'control.log.showTimestamps': '顯示時間戳',
|
||
'control.log.filterPlaceholder': '過濾 log...',
|
||
'control.log.jumpToLatest': '跳到最新',
|
||
'control.log.clear': '清空',
|
||
'control.log.clearToast': '已清空 log',
|
||
'control.log.copy': '複製',
|
||
'control.log.copied': '已複製到剪貼簿',
|
||
'control.log.copyPrivacyHint': 'Log 可能包含檔名與裝置資訊,請注意分享對象',
|
||
'control.log.export': '匯出 log',
|
||
'control.log.exported': '已匯出到 {path}',
|
||
'control.log.openFolder': '開啟 log 資料夾',
|
||
'control.log.lines': '行數:{current} / {max}',
|
||
'control.footer.closeWarning': '⚠ 關閉此視窗會停止伺服器',
|
||
'control.error.title': '伺服器無法啟動',
|
||
'control.error.description': '{reason}',
|
||
'control.error.restartButton': '重新啟動伺服器',
|
||
'control.error.viewLogDetails': '檢視 log 詳情',
|
||
'control.error.reportButton': '回報問題...',
|
||
'control.shutdown.stopping': '正在停止伺服器…',
|
||
// startup progress
|
||
'startup.panel.title': '正在啟動 visionA-local',
|
||
'startup.panel.ariaLabel': '啟動進度:階段 {current} / {max}',
|
||
'startup.progressLabel': '進度 {current} / {max}',
|
||
'startup.progressWithElapsed': '進度 {current} / {max} · 已等待 {elapsed} 秒',
|
||
'startup.stage.1.label': '初始化控制台',
|
||
'startup.stage.1.description': '準備 visionA-local 桌面環境',
|
||
'startup.stage.2.label': '檢查 Python 執行環境',
|
||
'startup.stage.2.description': '首次啟動可能需要較長時間',
|
||
'startup.stage.3.label': '啟動本機伺服器',
|
||
'startup.stage.3.description': '在 127.0.0.1:3721 啟動服務',
|
||
'startup.stage.4.label': '偵測 Kneron 裝置',
|
||
'startup.stage.4.description': '掃描已連接的硬體',
|
||
'startup.stage.5.label': '開啟瀏覽器',
|
||
'startup.stage.5.description': '在預設瀏覽器開啟 Web UI',
|
||
'startup.stage.5.skipped.label': '跳過(依偏好設定)',
|
||
'startup.stage.6.label': '等待 Web UI 連線',
|
||
'startup.stage.6.description': '正在與瀏覽器建立即時連線',
|
||
'startup.stage.6.manualHint': '請點擊控制台的「在瀏覽器開啟」按鈕',
|
||
'startup.status.pending': '等待中',
|
||
'startup.status.running': '進行中',
|
||
'startup.status.done': '完成',
|
||
'startup.status.failed': '失敗',
|
||
'startup.status.skipped': '跳過(依偏好設定)',
|
||
'startup.timeout.message': '這個步驟花的時間比預期久,正在重試...',
|
||
'startup.error.title': '啟動失敗',
|
||
'startup.error.description.timeout': '啟動時間超過 60 秒,可能是系統環境異常或網路中斷。',
|
||
'startup.error.description.stageFailed': '階段「{stageLabel}」執行失敗。',
|
||
'startup.error.failedStage': '失敗階段:{n} · {label}',
|
||
'startup.error.retry': '重試',
|
||
'startup.error.viewLog': '檢視 log',
|
||
'startup.error.report': '回報問題',
|
||
// settings
|
||
'settings.title': '設定',
|
||
'settings.autoOpenBrowser.label': '啟動時自動開啟瀏覽器',
|
||
'settings.autoOpenBrowser.hintLinux': 'Linux 桌面環境差異大,預設關閉',
|
||
'settings.language.label': '語言',
|
||
'settings.about.title': '關於',
|
||
},
|
||
'en': {
|
||
'control.title': 'visionA-local · Server Control',
|
||
'control.status.idle': 'Idle',
|
||
'control.status.starting': 'Starting...',
|
||
'control.status.running': 'Running',
|
||
'control.status.runningBrowserOpened': 'Running · Browser opened',
|
||
'control.status.stopping': 'Stopping...',
|
||
'control.status.stopped': 'Stopped',
|
||
'control.status.error': 'Error: {reason}',
|
||
'control.meta.port': 'Port',
|
||
'control.meta.uptime': 'Uptime',
|
||
'control.meta.pid': 'PID',
|
||
'control.meta.version': 'Version',
|
||
'control.action.openBrowser': 'Open in Browser',
|
||
'control.action.start': 'Start',
|
||
'control.action.stop': 'Stop',
|
||
'control.action.restart': 'Restart',
|
||
'control.action.manage': 'Manage',
|
||
'control.action.stopServer': 'Stop server',
|
||
'control.action.restartServer': 'Restart server',
|
||
'control.log.followTail': 'Follow tail',
|
||
'control.log.showTimestamps': 'Show timestamps',
|
||
'control.log.filterPlaceholder': 'Filter...',
|
||
'control.log.jumpToLatest': 'Jump to latest',
|
||
'control.log.clear': 'Clear',
|
||
'control.log.clearToast': 'Log cleared',
|
||
'control.log.copy': 'Copy',
|
||
'control.log.copied': 'Copied to clipboard',
|
||
'control.log.copyPrivacyHint': 'Log may contain filenames and device info. Share with care.',
|
||
'control.log.export': 'Export log',
|
||
'control.log.exported': 'Exported to {path}',
|
||
'control.log.openFolder': 'Open log folder',
|
||
'control.log.lines': 'Lines: {current} / {max}',
|
||
'control.footer.closeWarning': '⚠ Closing this window will stop the server',
|
||
'control.error.title': 'Server failed to start',
|
||
'control.error.description': '{reason}',
|
||
'control.error.restartButton': 'Restart Server',
|
||
'control.error.viewLogDetails': 'View log details',
|
||
'control.error.reportButton': 'Report...',
|
||
'control.shutdown.stopping': 'Stopping server…',
|
||
// startup progress
|
||
'startup.panel.title': 'Starting visionA-local',
|
||
'startup.panel.ariaLabel': 'Startup progress: stage {current} / {max}',
|
||
'startup.progressLabel': 'Progress {current} / {max}',
|
||
'startup.progressWithElapsed': 'Progress {current} / {max} · {elapsed}s elapsed',
|
||
'startup.stage.1.label': 'Initializing control panel',
|
||
'startup.stage.1.description': 'Preparing visionA-local desktop',
|
||
'startup.stage.2.label': 'Checking Python runtime',
|
||
'startup.stage.2.description': 'First launch may take longer',
|
||
'startup.stage.3.label': 'Starting local server',
|
||
'startup.stage.3.description': 'Starting service on 127.0.0.1:3721',
|
||
'startup.stage.4.label': 'Detecting Kneron devices',
|
||
'startup.stage.4.description': 'Scanning connected hardware',
|
||
'startup.stage.5.label': 'Opening browser',
|
||
'startup.stage.5.description': 'Opening the Web UI in your default browser',
|
||
'startup.stage.5.skipped.label': 'Skipped (per preference)',
|
||
'startup.stage.6.label': 'Waiting for Web UI to connect',
|
||
'startup.stage.6.description': 'Establishing realtime connection with the browser',
|
||
'startup.stage.6.manualHint': 'Please click "Open in Browser" in the Control Panel',
|
||
'startup.status.pending': 'Waiting',
|
||
'startup.status.running': 'Running',
|
||
'startup.status.done': 'Done',
|
||
'startup.status.failed': 'Failed',
|
||
'startup.status.skipped': 'Skipped (per preference)',
|
||
'startup.timeout.message': 'This step is taking longer than expected, retrying...',
|
||
'startup.error.title': 'Startup failed',
|
||
'startup.error.description.timeout': 'Startup exceeded 60 seconds. Your environment may have issues or the network is interrupted.',
|
||
'startup.error.description.stageFailed': 'Stage "{stageLabel}" failed.',
|
||
'startup.error.failedStage': 'Failed stage: {n} · {label}',
|
||
'startup.error.retry': 'Retry',
|
||
'startup.error.viewLog': 'View Log',
|
||
'startup.error.report': 'Report Issue',
|
||
// settings
|
||
'settings.title': 'Settings',
|
||
'settings.autoOpenBrowser.label': 'Auto-open browser on startup',
|
||
'settings.autoOpenBrowser.hintLinux': 'Linux desktop environments vary, disabled by default',
|
||
'settings.language.label': 'Language',
|
||
'settings.about.title': 'About',
|
||
},
|
||
};
|
||
|
||
let currentLocale = 'zh-TW';
|
||
|
||
// 根據 navigator.language 或儲存值決定 locale
|
||
export function detectLocale(preferredLocale) {
|
||
// 1. 使用者明確指定(preferences)
|
||
if (preferredLocale && dict[preferredLocale]) return preferredLocale;
|
||
// 2. localStorage
|
||
const stored = localStorage.getItem('vl-locale');
|
||
if (stored && dict[stored]) return stored;
|
||
// 3. navigator.language
|
||
const lang = (navigator.language || navigator.userLanguage || '').toLowerCase();
|
||
if (lang.startsWith('zh')) return 'zh-TW';
|
||
if (lang.startsWith('en')) return 'en';
|
||
// 4. fallback
|
||
return 'zh-TW';
|
||
}
|
||
|
||
export function setLocale(locale) {
|
||
if (dict[locale]) {
|
||
currentLocale = locale;
|
||
localStorage.setItem('vl-locale', locale);
|
||
}
|
||
}
|
||
|
||
export function getLocale() {
|
||
return currentLocale;
|
||
}
|
||
|
||
// t('key', {param: value}) → 翻譯字串並替換 {param}
|
||
export function t(key, params) {
|
||
let s = (dict[currentLocale] && dict[currentLocale][key]);
|
||
if (s === undefined) {
|
||
// fallback en
|
||
s = (dict.en && dict.en[key]) || key;
|
||
}
|
||
if (params) {
|
||
for (const k in params) {
|
||
s = s.replace(new RegExp('\\{' + k + '\\}', 'g'), params[k]);
|
||
}
|
||
}
|
||
return s;
|
||
}
|
||
|
||
// 對 DOM 中所有 [data-i18n] / [data-i18n-placeholder] 執行翻譯
|
||
export function applyI18n(root) {
|
||
const scope = root || document;
|
||
scope.querySelectorAll('[data-i18n]').forEach(el => {
|
||
const key = el.getAttribute('data-i18n');
|
||
el.textContent = t(key);
|
||
});
|
||
scope.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
|
||
const key = el.getAttribute('data-i18n-placeholder');
|
||
el.setAttribute('placeholder', t(key));
|
||
});
|
||
}
|
||
|
||
export const LOCALES = Object.keys(dict);
|