diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 136c6b9..9077b9a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -38,27 +38,49 @@ CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -trimpath -ldflags="-s -w" -o . ## 3. WebUI 开发 -WebUI 负责所有可视化配置与状态显示。 +WebUI 是 Vue 3 + Vite 单页应用,UI 基于 **Material Design 3**(`@material/web` 组件 + 自有 MD3 token)。 + +### 目录结构 + +``` +webui/src/ + mwc.js @material/web 按需引入清单(唯一入口,勿在别处 import) + theme/tokens.css MD3 令牌:颜色全角色 / 字阶 / 形状 / 动效 / 状态层 + theme/base.css 字体、重置、insets、缩放、排版与表面工具类 + theme/components.css 跨视图模式(设置行、状态徽标、折叠区、状态网格、列表行) + theme/app.css 壳层布局(顶栏、页面轨、导航栏、操作锁横幅、snackbar) + api/ksu.js exec 封装 + shellQuote + 开发环境 mock + api/luminpro.js Go JSON API 客户端 + composables/ useStatus / useConfig / useLog / useApps / useSnackbar + components/ 顶栏、导航栏、对话框、菜单、snackbar、操作锁横幅 + views/ 状态 / 配置 / 黑名单 / 日志 / 关于(样式写在各自的 diff --git a/webui/src/components/OpLockBanner.vue b/webui/src/components/OpLockBanner.vue new file mode 100644 index 0000000..251b2f7 --- /dev/null +++ b/webui/src/components/OpLockBanner.vue @@ -0,0 +1,17 @@ + + + + + + + {{ label }},已暂停刷新 + {{ seconds }}s + + + diff --git a/webui/src/components/PromptDialog.vue b/webui/src/components/PromptDialog.vue new file mode 100644 index 0000000..d8dc531 --- /dev/null +++ b/webui/src/components/PromptDialog.vue @@ -0,0 +1,68 @@ + + + + + {{ headline }} + + {{ description }} + + + + {{ cancelText }} + {{ confirmText }} + + + + + diff --git a/webui/src/components/SnackbarHost.vue b/webui/src/components/SnackbarHost.vue new file mode 100644 index 0000000..97fd6fc --- /dev/null +++ b/webui/src/components/SnackbarHost.vue @@ -0,0 +1,15 @@ + + + + + + + {{ message.text }} + + + + diff --git a/webui/src/components/ui/Badge.vue b/webui/src/components/ui/Badge.vue deleted file mode 100644 index c08a6b0..0000000 --- a/webui/src/components/ui/Badge.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - diff --git a/webui/src/components/ui/Button.vue b/webui/src/components/ui/Button.vue deleted file mode 100644 index b0b5170..0000000 --- a/webui/src/components/ui/Button.vue +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - diff --git a/webui/src/components/ui/Card.vue b/webui/src/components/ui/Card.vue deleted file mode 100644 index 3e69509..0000000 --- a/webui/src/components/ui/Card.vue +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - diff --git a/webui/src/components/ui/Input.vue b/webui/src/components/ui/Input.vue deleted file mode 100644 index bb4aa74..0000000 --- a/webui/src/components/ui/Input.vue +++ /dev/null @@ -1,38 +0,0 @@ - - - - - diff --git a/webui/src/components/ui/Label.vue b/webui/src/components/ui/Label.vue deleted file mode 100644 index ce49f42..0000000 --- a/webui/src/components/ui/Label.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - diff --git a/webui/src/components/ui/Separator.vue b/webui/src/components/ui/Separator.vue deleted file mode 100644 index ff4bb30..0000000 --- a/webui/src/components/ui/Separator.vue +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/webui/src/components/ui/Switch.vue b/webui/src/components/ui/Switch.vue deleted file mode 100644 index 091c64c..0000000 --- a/webui/src/components/ui/Switch.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - diff --git a/webui/src/components/ui/Textarea.vue b/webui/src/components/ui/Textarea.vue deleted file mode 100644 index d16e7fc..0000000 --- a/webui/src/components/ui/Textarea.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - - diff --git a/webui/src/composables/useApps.js b/webui/src/composables/useApps.js index fa4a6b5..08d24df 100644 --- a/webui/src/composables/useApps.js +++ b/webui/src/composables/useApps.js @@ -1,8 +1,21 @@ -import { ref, reactive } from 'vue' +import { ref, reactive, computed } from 'vue' import { listPackages, getPackagesInfo } from 'kernelsu' -import PinyinMatch from 'pinyin-match' -import { readConfig, updateConfig } from '../utils.js' +import { fetchConfig, patchConfig } from '../api/luminpro.js' +/** 拼音匹配库体积较大,进入黑名单页后再按需加载 */ +let PinyinMatch = null +const pinyinReady = ref(false) +async function ensurePinyin() { + if (PinyinMatch || pinyinReady.value) return + try { + PinyinMatch = (await import('pinyin-match')).default + } catch { + PinyinMatch = null + } + pinyinReady.value = true +} + +/** 黑名单管理:应用列表来自 KernelSU API,黑名单本身存在 config.json */ export function useApps() { const apps = ref([]) const isLoading = ref(false) @@ -12,13 +25,14 @@ export function useApps() { const savedBlacklist = ref(new Set()) const activityEntries = ref(new Set()) - /** 每个 app 条目结构: { packageName, appLabel, isSystem, uid, checked, hasActivities } */ + /** 条目结构: { packageName, appLabel, isSystem, uid, checked, expanded } */ async function load() { isLoading.value = true loadError.value = '' + ensurePinyin() // 后台加载拼音库,不阻塞列表 try { - const cfg = await readConfig() + const cfg = await fetchConfig() const allSaved = Array.isArray(cfg.blacklist_apps) ? cfg.blacklist_apps : [] savedBlacklist.value = new Set(allSaved) const savedPkgSet = new Set(allSaved.filter((e) => !e.includes('/'))) @@ -30,7 +44,6 @@ export function useApps() { if (pkgs && pkgs.length > 0) infoList = await getPackagesInfo(pkgs) else throw new Error('no pkgs') } catch { - console.log('[DEBUG] 使用模拟数据') infoList = Array.from({ length: 150 }, (_, i) => ({ packageName: `com.mock.app${i}`, appLabel: i % 10 === 0 ? `测试应用 ${i} (含抖音关键字)` : `模拟应用 ${i}`, @@ -64,8 +77,7 @@ export function useApps() { expanded: false, }), ) - - _reorder() + reorder() } catch (e) { loadError.value = e.message || String(e) } finally { @@ -73,7 +85,7 @@ export function useApps() { } } - function _reorder() { + function reorder() { apps.value.sort((a, b) => { const stateA = a.checked ? 2 : hasActivity(a.packageName) ? 1 : 0 const stateB = b.checked ? 2 : hasActivity(b.packageName) ? 1 : 0 @@ -82,7 +94,10 @@ export function useApps() { } function hasActivity(pkg) { - return [...activityEntries.value].some((e) => e.startsWith(pkg + '/')) + for (const entry of activityEntries.value) { + if (entry.startsWith(pkg + '/')) return true + } + return false } function getActivities(pkg) { @@ -91,53 +106,44 @@ export function useApps() { function addActivity(entry) { activityEntries.value.add(entry) - _reorder() + reorder() } function removeActivity(entry) { activityEntries.value.delete(entry) - _reorder() + reorder() } - async function save(toast) { - toast('保存中...') - const selectedPkgs = apps.value.filter((a) => a.checked).map((a) => a.packageName) - const allEntries = [...selectedPkgs, ...activityEntries.value] - const res = await updateConfig({ blacklist_apps: allEntries }) - if (res.errno === 0) { - savedBlacklist.value = new Set(allEntries) - toast('黑名单保存成功') - } else { - toast('保存失败: ' + res.stderr) + async function save(snackbar) { + const selected = apps.value.filter((a) => a.checked).map((a) => a.packageName) + const all = [...selected, ...activityEntries.value] + try { + await patchConfig({ blacklist_apps: all }) + savedBlacklist.value = new Set(all) + snackbar?.('黑名单已保存') + } catch (e) { + snackbar?.(`保存失败: ${e.message}`) } } - function onCheckboxChange() { - _reorder() - } - function toggleSystemApps() { showingSystemApps.value = !showingSystemApps.value load() } function selectAll() { - apps.value.forEach((a) => { - a.checked = true - }) - _reorder() + for (const app of apps.value) app.checked = true + reorder() } + function selectNone() { - apps.value.forEach((a) => { - a.checked = false - }) - _reorder() + for (const app of apps.value) app.checked = false + reorder() } + function invertSelection() { - apps.value.forEach((a) => { - a.checked = !a.checked - }) - _reorder() + for (const app of apps.value) app.checked = !app.checked + reorder() } const smartKeywords = [ @@ -166,35 +172,53 @@ export function useApps() { 'x', ] - function smartSelect() { - apps.value.forEach((a) => { - const name = (a.appLabel || '').toLowerCase() - const pkg = (a.packageName || '').toLowerCase() - for (const kw of smartKeywords) { - if (kw === 'x') { + function smartSelect(snackbar) { + let count = 0 + for (const app of apps.value) { + const name = (app.appLabel || '').toLowerCase() + const pkg = (app.packageName || '').toLowerCase() + for (const keyword of smartKeywords) { + if (keyword === 'x') { if (name === 'x' || name === 'x (twitter)') { - a.checked = true + if (!app.checked) count++ + app.checked = true break } - } else if (name.includes(kw) || pkg.includes(kw)) { - a.checked = true + } else if (name.includes(keyword) || pkg.includes(keyword)) { + if (!app.checked) count++ + app.checked = true break } } - }) - _reorder() + } + reorder() + snackbar?.(count > 0 ? `已智能勾选 ${count} 个应用` : '没有匹配到可勾选的应用') } - // 过滤后的列表 + /** 过滤后的列表(供虚拟滚动使用) */ function getFilteredApps() { - const kw = searchKeyword.value.trim().toLowerCase() - if (!kw) return apps.value + const keyword = searchKeyword.value.trim().toLowerCase() + if (!keyword) return apps.value return apps.value.filter((a) => { const pkg = a.packageName.toLowerCase() - return pkg.includes(kw) || PinyinMatch.match(a.appLabel, kw) + if (pkg.includes(keyword)) return true + // 拼音库未就绪时退化为普通子串匹配 + if (!pinyinReady.value || !PinyinMatch) { + return (a.appLabel || '').toLowerCase().includes(keyword) + } + return !!PinyinMatch.match(a.appLabel, keyword) }) } + const unsavedCount = computed(() => { + const selected = apps.value.filter((a) => a.checked).map((a) => a.packageName) + const all = [...selected, ...activityEntries.value] + const saved = [...savedBlacklist.value] + if (all.length !== saved.length) return 1 + const savedSet = new Set(saved) + return all.some((e) => !savedSet.has(e)) ? 1 : 0 + }) + return { apps, isLoading, @@ -203,13 +227,14 @@ export function useApps() { showingSystemApps, savedBlacklist, activityEntries, + unsavedCount, load, save, hasActivity, getActivities, addActivity, removeActivity, - onCheckboxChange, + reorder, toggleSystemApps, selectAll, selectNone, diff --git a/webui/src/composables/useConfig.js b/webui/src/composables/useConfig.js index 0757f79..d3e8883 100644 --- a/webui/src/composables/useConfig.js +++ b/webui/src/composables/useConfig.js @@ -1,286 +1,168 @@ -import { ref, watch } from 'vue' -import { - runCmd, - readConfig, - writeConfig, - updateConfig, - BACKUP_CONFIG_FILE, - PID_FILE, - DEFAULT_NOW_BRI_FILE, - DEFAULT_SYS_MAX_BRI_FILE, -} from '../utils.js' +import { ref, reactive, computed } from 'vue' +import { fetchConfig, patchConfig, readModuleFile } from '../api/luminpro.js' + +/** 主配置卡片负责的字段 */ +const MAIN_KEYS = [ + 'ui_max_bri', + 'max_bri', + 'steps_num', + 'auto_bri_sleep', + 'display_hdr_sleep', + 'hdr_enter_ratio', + 'hdr_exit_ratio', + 'compatibility_mode', + 'sleep_time', +] + +/** 高级设置负责的字段 */ +const ADVANCED_KEYS = ['now_bri_file', 'max_bri_file', 'inotify_events', 'debug_mode', 'log_max_size', 'log_level'] + +const INT_KEYS = new Set([ + 'ui_max_bri', + 'max_bri', + 'steps_num', + 'log_max_size', + 'auto_bri_sleep', + 'display_hdr_sleep', + 'compatibility_mode', + 'debug_mode', +]) +const FLOAT_KEYS = new Set(['hdr_enter_ratio', 'hdr_exit_ratio']) + +/** 配置改动的类型还原:表单里统一用字符串,写回时按字段类型转换 */ +function toTyped(key, value) { + if (INT_KEYS.has(key)) return parseInt(value, 10) || 0 + if (FLOAT_KEYS.has(key)) return parseFloat(value) || 0 + return value +} + +/** 配置对象 -> 表单字符串(数组字段保持数组) */ +function toForm(cfg, keys) { + const out = {} + for (const key of keys) { + const value = cfg[key] + if (Array.isArray(value)) out[key] = value + else if (value === null || value === undefined) out[key] = '' + else out[key] = String(value) + } + return out +} export function useConfig() { - // 亮度配置 - const uiMaxBri = ref('') - const maxBri = ref('') - const stepsNum = ref('50') + const saved = ref({}) + const loading = ref(false) + const error = ref('') - // 执行策略 - const autoBriSleep = ref(false) - const displayHdrSleep = ref(false) - const hdrEnterRatio = ref('1.15') - const hdrExitRatio = ref('1.05') - const compatibilityMode = ref(false) - const sleepMode = ref(false) - const sleepStartH = ref('19') - const sleepStartM = ref('00') - const sleepEndH = ref('06') - const sleepEndM = ref('00') - - // 高级设置 - const nowBriFile = ref(DEFAULT_NOW_BRI_FILE) - const sysMaxBriFile = ref(DEFAULT_SYS_MAX_BRI_FILE) - const inotifyEvents = ref('c') - const debugMode = ref(false) - const logLevel = ref('info') - const logMaxSize = ref('500') - - // 脸污标记 - const dirty = ref(false) - const dirtyAdvanced = ref(false) - let _silent = false - - // Web UI 配置 (localStorage 持久化) - const autoRefresh = ref(localStorage.getItem('autoRefresh') !== 'false') - const statusRefreshInterval = ref( - Math.max(100, parseInt(localStorage.getItem('statusLogRefreshInterval') || '1000', 10)), - ) - const uiZoom = ref( - Math.min(150, Math.max(50, parseInt(localStorage.getItem('uiZoom') || '100', 10))), - ) - const themeMode = ref(localStorage.getItem('themeMode') || 'system') - - // 监听主配置字段 - watch( - [ - uiMaxBri, - maxBri, - stepsNum, - autoBriSleep, - displayHdrSleep, - hdrEnterRatio, - hdrExitRatio, - compatibilityMode, - sleepMode, - sleepStartH, - sleepStartM, - sleepEndH, - sleepEndM, - ], - () => { - if (!_silent) dirty.value = true - }, - ) - // 监听高级设置字段 (系统管理的日志项也随「保存设置」写入) - watch([nowBriFile, sysMaxBriFile, inotifyEvents, debugMode, logLevel, logMaxSize], () => { - if (!_silent) dirtyAdvanced.value = true + const form = reactive({ + ...toForm({}, [...MAIN_KEYS, ...ADVANCED_KEYS]), + blacklist_apps: [], }) + function hydrate(cfg) { + saved.value = { ...cfg } + Object.assign(form, toForm(cfg, [...MAIN_KEYS, ...ADVANCED_KEYS])) + form.blacklist_apps = Array.isArray(cfg.blacklist_apps) ? [...cfg.blacklist_apps] : [] + } + async function load() { - _silent = true - const cfg = await readConfig() - if (!cfg || Object.keys(cfg).length === 0) { - _silent = false + loading.value = true + try { + hydrate(await fetchConfig()) + error.value = '' + } catch (e) { + error.value = e.message + } finally { + loading.value = false + } + } + + /** 某组字段中相对已保存配置发生变化的项(已按类型还原) */ + function changedKeys(keys) { + const patch = {} + for (const key of keys) { + const current = key === 'blacklist_apps' ? JSON.stringify(form[key]) : String(form[key]) + const original = Array.isArray(saved.value[key]) + ? JSON.stringify(saved.value[key]) + : String(saved.value[key] ?? '') + if (current !== original) patch[key] = toTyped(key, form[key]) + } + return patch + } + + const diffMain = computed(() => changedKeys(MAIN_KEYS)) + const diffAdvanced = computed(() => changedKeys(ADVANCED_KEYS)) + const dirtyMain = computed(() => Object.keys(diffMain.value).length > 0) + const dirtyAdvanced = computed(() => Object.keys(diffAdvanced.value).length > 0) + + async function save(patch, snackbar, message) { + if (Object.keys(patch).length === 0) { + snackbar?.('没有需要保存的改动') return } - - uiMaxBri.value = cfg.ui_max_bri != null ? String(cfg.ui_max_bri) : '' - maxBri.value = cfg.max_bri != null ? String(cfg.max_bri) : '' - stepsNum.value = cfg.steps_num != null ? String(cfg.steps_num) : '50' - logMaxSize.value = cfg.log_max_size != null ? String(cfg.log_max_size) : '500' - autoBriSleep.value = cfg.auto_bri_sleep === 1 - displayHdrSleep.value = cfg.display_hdr_sleep === 1 - hdrEnterRatio.value = cfg.hdr_enter_ratio != null ? String(cfg.hdr_enter_ratio) : '1.15' - hdrExitRatio.value = cfg.hdr_exit_ratio != null ? String(cfg.hdr_exit_ratio) : '1.05' - compatibilityMode.value = cfg.compatibility_mode === 1 - nowBriFile.value = cfg.now_bri_file || DEFAULT_NOW_BRI_FILE - sysMaxBriFile.value = cfg.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE - inotifyEvents.value = cfg.inotify_events || 'c' - debugMode.value = cfg.debug_mode === 1 - logLevel.value = cfg.log_level || 'info' - - const st = cfg.sleep_time || '' - if (st && st.includes('-')) { - sleepMode.value = true - const [s, e] = st.split('-') - if (s.length === 4) { - sleepStartH.value = s.slice(0, 2) - sleepStartM.value = s.slice(2) - } - if (e.length === 4) { - sleepEndH.value = e.slice(0, 2) - sleepEndM.value = e.slice(2) - } - } else { - sleepMode.value = false + try { + await patchConfig(patch) + await load() + snackbar?.(message) + } catch (e) { + snackbar?.(`保存失败: ${e.message}`) } - dirty.value = false - dirtyAdvanced.value = false - _silent = false } - function getSleepTimeStr() { - if (!sleepMode.value) return '' - const pad = (v) => String(v).padStart(2, '0') - return `${pad(sleepStartH.value)}${pad(sleepStartM.value)}-${pad(sleepEndH.value)}${pad(sleepEndM.value)}` - } + const saveMain = (snackbar) => save(diffMain.value, snackbar, '配置已保存') + const saveAdvanced = (snackbar) => save(diffAdvanced.value, snackbar, '高级设置已保存,需重启模块生效') - async function save(toast) { - if (!uiMaxBri.value || !maxBri.value) { - toast('亮度値不能为空') - return - } - toast('保存中...') - // 读取当前配置(保留 blacklist_apps 等其他字段) - const current = await readConfig() - await writeConfig({ - ...current, - ui_max_bri: parseInt(uiMaxBri.value) || 0, - max_bri: parseInt(maxBri.value) || 0, - steps_num: parseInt(stepsNum.value) || 50, - auto_bri_sleep: autoBriSleep.value ? 1 : 0, - display_hdr_sleep: displayHdrSleep.value ? 1 : 0, - hdr_enter_ratio: parseFloat(hdrEnterRatio.value) || 1.15, - hdr_exit_ratio: parseFloat(hdrExitRatio.value) || 1.05, - compatibility_mode: compatibilityMode.value ? 1 : 0, - sleep_time: getSleepTimeStr(), - }) - const pidRes = await runCmd(`cat "${PID_FILE}"`) - toast( - pidRes.errno === 0 && pidRes.stdout.trim() - ? '配置已保存 (下次重启模块或触发时生效)' - : '配置已保存 (服务未运行)', - ) - dirty.value = false - } - - async function saveAdvanced(toast, onPathsChanged) { - toast('保存中...') - await updateConfig({ - now_bri_file: nowBriFile.value || DEFAULT_NOW_BRI_FILE, - max_bri_file: sysMaxBriFile.value || DEFAULT_SYS_MAX_BRI_FILE, - inotify_events: inotifyEvents.value || 'c', - debug_mode: debugMode.value ? 1 : 0, - log_max_size: parseInt(logMaxSize.value) || 500, - log_level: logLevel.value, - }) - onPathsChanged?.() - toast('高级设置已保存,需重启模块生效') - dirtyAdvanced.value = false - } - - async function resetToDefaults(toast) { - toast('正在恢复默认配置...') - const backupRes = await runCmd(`cat "${BACKUP_CONFIG_FILE}"`) - if (backupRes.errno !== 0 || !backupRes.stdout.trim()) { - toast('备份文件不存在,无法恢复') + /** 从安装时备份恢复默认值(只改表单,需再点保存) */ + async function restoreBackup(snackbar) { + const raw = await readModuleFile('config/.backup/config.json') + if (!raw.trim()) { + snackbar?.('备份文件不存在,无法恢复') return } let backup try { - backup = JSON.parse(backupRes.stdout) + backup = JSON.parse(raw) } catch { - toast('备份文件损坏') + snackbar?.('备份文件损坏') return } - - uiMaxBri.value = backup.ui_max_bri != null ? String(backup.ui_max_bri) : '' - maxBri.value = backup.max_bri != null ? String(backup.max_bri) : '' - autoBriSleep.value = backup.auto_bri_sleep === 1 - displayHdrSleep.value = backup.display_hdr_sleep === 1 - hdrEnterRatio.value = backup.hdr_enter_ratio != null ? String(backup.hdr_enter_ratio) : '1.15' - hdrExitRatio.value = backup.hdr_exit_ratio != null ? String(backup.hdr_exit_ratio) : '1.05' - compatibilityMode.value = backup.compatibility_mode === 1 - stepsNum.value = backup.steps_num != null ? String(backup.steps_num) : '50' - logMaxSize.value = backup.log_max_size != null ? String(backup.log_max_size) : '500' - nowBriFile.value = backup.now_bri_file || DEFAULT_NOW_BRI_FILE - sysMaxBriFile.value = backup.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE - inotifyEvents.value = backup.inotify_events || 'c' - - const st = backup.sleep_time || '' - if (st && st.includes('-')) { - sleepMode.value = true - const [s, e] = st.split('-') - if (s.length === 4) { - sleepStartH.value = s.slice(0, 2) - sleepStartM.value = s.slice(2) - } - if (e.length === 4) { - sleepEndH.value = e.slice(0, 2) - sleepEndM.value = e.slice(2) - } - } else { - sleepMode.value = true - sleepStartH.value = '19' - sleepStartM.value = '00' - sleepEndH.value = '06' - sleepEndM.value = '00' - } - await save(toast) - await saveAdvanced(toast) + hydrate({ ...saved.value, ...backup }) + snackbar?.('已载入安装时的配置,点击保存生效') } - function saveWebUIConfig(toast, newAutoRefresh, newInterval, newZoom, newTheme, onRestart) { - const interval = Math.max(100, parseInt(newInterval, 10) || 1000) - const zoom = Math.min(150, Math.max(50, parseInt(newZoom, 10) || 100)) - localStorage.setItem('autoRefresh', newAutoRefresh) - localStorage.setItem('statusLogRefreshInterval', interval) - localStorage.setItem('uiZoom', zoom) - localStorage.setItem('themeMode', newTheme) - autoRefresh.value = newAutoRefresh - statusRefreshInterval.value = interval - uiZoom.value = zoom - themeMode.value = newTheme - document.documentElement.style.zoom = zoom / 100 - applyTheme(newTheme) - onRestart?.(newAutoRefresh, interval) - toast('Web UI 配置已保存') - } + // ── 定时休眠:字符串 <-> 开关 + 四个时间输入 ────────────────────── + const sleepEnabled = computed({ + get: () => !!form.sleep_time, + set: (on) => { + form.sleep_time = on ? form.sleep_time || '2300-0700' : '' + }, + }) - function applyZoom() { - document.documentElement.style.zoom = uiZoom.value / 100 - } + const sleepParts = computed(() => { + const text = String(form.sleep_time || '') + const match = /^(\d{2})(\d{2})-(\d{2})(\d{2})$/.exec(text) + if (!match) return ['23', '00', '07', '00'] + return [match[1], match[2], match[3], match[4]] + }) - function applyTheme(mode) { - const html = document.documentElement - html.classList.remove('light', 'dark') - if (mode === 'light') html.classList.add('light') - else if (mode === 'dark') html.classList.add('dark') + function setSleepPart(index, value) { + const parts = [...sleepParts.value] + parts[index] = String(value).padStart(2, '0').slice(-2) + form.sleep_time = `${parts[0]}${parts[1]}-${parts[2]}${parts[3]}` } return { - uiMaxBri, - maxBri, - stepsNum, - logMaxSize, - autoBriSleep, - displayHdrSleep, - hdrEnterRatio, - hdrExitRatio, - compatibilityMode, - sleepMode, - sleepStartH, - sleepStartM, - sleepEndH, - sleepEndM, - nowBriFile, - sysMaxBriFile, - inotifyEvents, - debugMode, - logLevel, - dirty, + saved, + form, + loading, + error, + dirtyMain, dirtyAdvanced, - autoRefresh, - statusRefreshInterval, - uiZoom, - themeMode, load, - save, + saveMain, saveAdvanced, - resetToDefaults, - saveWebUIConfig, - applyZoom, - applyTheme, + restoreBackup, + sleepEnabled, + sleepParts, + setSleepPart, } } diff --git a/webui/src/composables/useLog.js b/webui/src/composables/useLog.js index e377fdb..8a8f776 100644 --- a/webui/src/composables/useLog.js +++ b/webui/src/composables/useLog.js @@ -1,58 +1,68 @@ import { ref, computed } from 'vue' -import { runCmd, LOG_FILE } from '../utils.js' +import { fetchLog, clearLog, exportLog } from '../api/luminpro.js' +const LEVELS = ['', 'INFO', 'WARN', 'ERROR', 'SUCCESS'] + +/** 日志:数据来自 Go 侧 `luminpro log tail`,等级过滤在前端进行 */ export function useLog() { - const fullLog = ref('') - const filterLevel = ref('') - const isLoading = ref(false) + const entries = ref([]) + const level = ref('') + const error = ref('') + const loading = ref(false) - const filteredLog = computed(() => { - if (!fullLog.value) return '暂无日志' - if (!filterLevel.value) return fullLog.value - const lines = fullLog.value.split('\n').filter((l) => l.includes(`[${filterLevel.value}]`)) - return lines.length > 0 ? lines.join('\n') : `暂无 [${filterLevel.value}] 等级的日志` - }) + const levels = LEVELS + const filtered = computed(() => + level.value ? entries.value.filter((e) => e.level === level.value) : entries.value, + ) + + const asText = (list = filtered.value) => + list.map((e) => `[${e.time}] [${e.tag}] [${e.level}] ${e.message}`.trim()).join('\n') async function load() { - const res = await runCmd(`tail -n 100 "${LOG_FILE}"`) - fullLog.value = - res.errno === 0 ? res.stdout.trim() || '暂无日志' : '无法读取日志 (可能模块尚未产生日志文件)' + loading.value = true + try { + const page = await fetchLog(200) + entries.value = page.entries ?? [] + error.value = '' + } catch (e) { + error.value = e.message + } finally { + loading.value = false + } } - async function clear(toast) { - toast('正在清空日志...') - const res = await runCmd(`> "${LOG_FILE}"`) - if (res.errno === 0) { - fullLog.value = '' - toast('日志已清空') - } else toast('清空失败: ' + (res.stderr || '未知错误')) + async function clear(snackbar) { + try { + await clearLog() + entries.value = [] + snackbar?.('日志已清空') + } catch (e) { + snackbar?.(`清空失败: ${e.message}`) + } } - async function copy(toast) { - const res = await runCmd(`tail -n 50 "${LOG_FILE}"`) - if (res.errno !== 0 || !res.stdout.trim()) { - toast('暂无日志内容') + async function exportTo(snackbar) { + try { + const res = await exportLog('/sdcard') + snackbar?.(`已导出到 ${res.path}`) + } catch (e) { + snackbar?.(`导出失败: ${e.message}`) + } + } + + async function copy(snackbar) { + const text = asText() + if (!text) { + snackbar?.('暂无日志可复制') return } try { - await navigator.clipboard.writeText(res.stdout.trim()) + await navigator.clipboard.writeText(text) + snackbar?.('日志已复制到剪贴板') } catch { - const ta = document.createElement('textarea') - ta.value = res.stdout.trim() - ta.style.cssText = 'position:fixed;opacity:0;pointer-events:none' - document.body.appendChild(ta) - ta.select() - document.execCommand('copy') - document.body.removeChild(ta) + snackbar?.('复制失败,请手动选择文本') } - toast('已复制最新 50 条日志') } - async function exportLog(toast) { - toast('正在导出...') - const res = await runCmd(`cp "${LOG_FILE}" "/sdcard/LuminPro_$(date '+%Y%m%d_%H%M%S').log"`) - toast(res.errno === 0 ? '日志已导出到 /sdcard' : '导出失败: ' + (res.stderr || '未知错误')) - } - - return { fullLog, filterLevel, filteredLog, isLoading, load, clear, copy, exportLog } + return { entries, filtered, level, levels, error, loading, asText, load, clear, exportTo, copy } } diff --git a/webui/src/composables/useOplock.js b/webui/src/composables/useOplock.js deleted file mode 100644 index 7cc18a7..0000000 --- a/webui/src/composables/useOplock.js +++ /dev/null @@ -1,23 +0,0 @@ -import { ref } from 'vue' -import { runCmd, OPLOCK_FILE } from '../utils.js' - -/** - * 操作锁:后台脚本 (up.sh 渐变 / boost.sh 峰值 / restart.sh 重启) 写亮度节点期间 - * 会创建 oplock 并写入自身 PID。WebUI 据此暂停刷新、禁用写操作。 - * 锁文件中的 PID 不存在时视为遗留锁,就地清理并放行。 - */ -export function useOplock() { - const isLocked = ref(false) - - async function refresh() { - const res = await runCmd( - `F="${OPLOCK_FILE}"; if [ -f "$F" ]; then P="$(cat "$F" 2>/dev/null)"; ` + - `if [ -n "$P" ] && [ -d "/proc/$P" ]; then echo locked; ` + - `else rm -f "$F"; echo free; fi; else echo free; fi`, - ) - isLocked.value = res.errno === 0 && res.stdout.trim() === 'locked' - return isLocked.value - } - - return { isLocked, refresh } -} diff --git a/webui/src/composables/useSnackbar.js b/webui/src/composables/useSnackbar.js new file mode 100644 index 0000000..8825806 --- /dev/null +++ b/webui/src/composables/useSnackbar.js @@ -0,0 +1,70 @@ +import { ref, computed } from 'vue' + +/** Snackbar(M3):底部浮层提示,自动消失 */ +export function useSnackbar() { + const messages = ref([]) + let seq = 0 + + function show(text, { duration = 3000 } = {}) { + if (!text) return + const id = ++seq + messages.value.push({ id, text }) + if (messages.value.length > 3) messages.value.shift() + setTimeout(() => dismiss(id), duration) + } + + function dismiss(id) { + messages.value = messages.value.filter((m) => m.id !== id) + } + + return { messages, show, dismiss } +} + +/** + * 主题 / 缩放 / 刷新频率等纯前端偏好(localStorage)。 + * 模块状态不放这里——它属于 config.json。 + */ +export function useWebUIPrefs() { + const autoRefresh = ref(localStorage.getItem('autoRefresh') !== 'false') + const refreshInterval = ref( + Math.max(100, parseInt(localStorage.getItem('statusLogRefreshInterval') || '1000', 10)), + ) + const zoom = ref(Math.min(150, Math.max(50, parseInt(localStorage.getItem('uiZoom') || '100', 10)))) + const themeMode = ref(localStorage.getItem('themeMode') || 'system') + + const zoomScale = computed(() => zoom.value / 100) + + function applyZoom() { + document.documentElement.style.zoom = String(zoomScale.value) + } + + function applyTheme(mode) { + const root = document.documentElement + root.classList.remove('light', 'dark') + if (mode === 'light' || mode === 'dark') root.classList.add(mode) + } + + function save({ autoRefresh: ar, refreshInterval: ri, zoom: z, themeMode: tm }) { + autoRefresh.value = ar + refreshInterval.value = Math.max(100, parseInt(ri, 10) || 1000) + zoom.value = Math.min(150, Math.max(50, parseInt(z, 10) || 100)) + themeMode.value = tm + localStorage.setItem('autoRefresh', String(autoRefresh.value)) + localStorage.setItem('statusLogRefreshInterval', String(refreshInterval.value)) + localStorage.setItem('uiZoom', String(zoom.value)) + localStorage.setItem('themeMode', themeMode.value) + applyZoom() + applyTheme(themeMode.value) + } + + return { + autoRefresh, + refreshInterval, + zoom, + themeMode, + zoomScale, + applyZoom, + applyTheme, + save, + } +} diff --git a/webui/src/composables/useStatus.js b/webui/src/composables/useStatus.js index 6a7d228..6e295a9 100644 --- a/webui/src/composables/useStatus.js +++ b/webui/src/composables/useStatus.js @@ -1,150 +1,108 @@ import { ref, computed } from 'vue' import { - runCmd, - readConfig, - PID_FILE, - STOP_FLAG_FILE, - DEFAULT_NOW_BRI_FILE, - DEFAULT_SYS_MAX_BRI_FILE, -} from '../utils.js' + fetchStatus, + fetchOplock, + setBrightness as apiSetBrightness, + boost as apiBoost, + restart as apiRestart, + toggleService as apiToggleService, +} from '../api/luminpro.js' +/** 守护进程与亮度状态:数据来自 Go 侧 `luminpro status` */ export function useStatus() { - // 亮度 - const currentBri = ref(null) - const sysMaxBri = ref(null) + const status = ref(null) + const oplock = ref({ locked: false }) + const error = ref('') - // 服务状态 - const inotifydPid = ref('—') - const inotifydState = ref('—') - const isRunning = ref(false) - const isPaused = ref(false) - const statusClass = computed(() => { - if (isPaused.value) return 'status-paused' - if (isRunning.value) return 'status-running' - return 'status-loading' + const moduleInfo = computed(() => status.value?.module ?? {}) + const daemon = computed(() => status.value?.daemon ?? {}) + const brightness = computed(() => status.value?.brightness ?? { current: 0, max: 0, percent: 0 }) + const display = computed(() => status.value?.display ?? null) + const sleep = computed(() => status.value?.sleep ?? { window: '', active: false }) + const cfg = computed(() => status.value?.config ?? {}) + + const isPaused = computed(() => !!daemon.value.paused) + const isRunning = computed(() => !!daemon.value.running && !daemon.value.paused) + const statusText = computed(() => (isPaused.value ? '已暂停' : isRunning.value ? '运行中' : '未运行')) + const statusClass = computed(() => + isPaused.value ? 'paused' : isRunning.value ? 'running' : 'stopped', + ) + const sleepText = computed(() => { + if (!sleep.value.window) return '未配置' + return sleep.value.active ? '休眠中' : '非休眠' }) - const statusText = computed(() => { - if (isPaused.value) return '已暂停' - if (isRunning.value) return '运行中' - return '未运行' + const hdrText = computed(() => { + const d = display.value + if (!d || !d.hdrKnown) return '—' + return `${d.hdrRatio.toFixed(2)}${d.hdrStale ? '*' : ''}` }) - // HDR / 睡眠状态 - const hdrRatio = ref('—') - const sleepStatus = ref('—') - - // 缓存配置字段(避免每次刷新都 readConfig) - let _nowBriFile = null - let _sysMaxBriFile = null - let _sleepTime = null - - async function _ensurePaths() { - if (_nowBriFile && _sysMaxBriFile) return - const cfg = await readConfig() - _nowBriFile = cfg.now_bri_file || DEFAULT_NOW_BRI_FILE - _sysMaxBriFile = cfg.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE - _sleepTime = cfg.sleep_time || '' - } - - function invalidatePaths() { - _nowBriFile = null - _sysMaxBriFile = null - _sleepTime = null - } - - async function load(forceFull = false) { - await _ensurePaths() - - const needBri = forceFull || currentBri.value === null || sysMaxBri.value === null - - // 所有 Shell 命令一次并发,消除多轮顺序等待 - // PID + 进程状态合并为一条命令以减少 exec 次数 - const [pidStateRes, stopRes, hdrRes, cBriRes, sBriRes] = await Promise.all([ - runCmd( - `PID=$(cat "${PID_FILE}" 2>/dev/null || true); printf '%s\\n' "$PID"; [ -n "$PID" ] && grep '^State:' "/proc/$PID/status" 2>/dev/null | awk '{print $2}' || true`, - ), - runCmd(`[ -f "${STOP_FLAG_FILE}" ] && echo "1" || echo "0"`), - runCmd( - `dumpsys display 2>/dev/null | sed -n 's/.*hdrSdrRatio \\([0-9.]*\\).*/\\1/p' | head -n 1`, - ), - needBri ? runCmd(`cat "${_nowBriFile}"`) : Promise.resolve({ errno: -1, stdout: '' }), - needBri ? runCmd(`cat "${_sysMaxBriFile}"`) : Promise.resolve({ errno: -1, stdout: '' }), - ]) - - if (needBri) { - currentBri.value = cBriRes.errno === 0 ? cBriRes.stdout.trim() : '0' - sysMaxBri.value = sBriRes.errno === 0 ? sBriRes.stdout.trim() : '255' + async function load({ display = true } = {}) { + try { + const next = await fetchStatus({ display }) + // --no-display 时后端不返回 display 字段,沿用上一次的结果避免界面闪烁 + if (!display && !next.display && status.value?.display) { + next.display = status.value.display + } + status.value = next + error.value = '' + } catch (e) { + error.value = e.message } - - const psLines = (pidStateRes.errno === 0 ? pidStateRes.stdout : '').split('\n') - const pidStr = psLines[0]?.trim() || '' - const stateChar = psLines[1]?.trim() || '' - - isPaused.value = stopRes.errno === 0 && stopRes.stdout.trim() === '1' - isRunning.value = !isPaused.value && !!pidStr - inotifydPid.value = pidStr || '离线' - inotifydState.value = isRunning.value ? stateChar || '已退出' : '离线' - - const hdrRaw = hdrRes.errno === 0 ? hdrRes.stdout.trim() : '' - hdrRatio.value = hdrRaw && /^\d+(\.\d+)?$/.test(hdrRaw) ? parseFloat(hdrRaw).toFixed(2) : '-' - - sleepStatus.value = _calcSleep(_sleepTime) } - function _calcSleep(sleepTime) { - if (!sleepTime || !sleepTime.includes('-')) return '非休眠' - const [s, e] = sleepTime.split('-') - if (s.length !== 4 || e.length !== 4) return '非休眠' - const now = new Date() - const nV = now.getHours() * 100 + now.getMinutes() - const sNum = parseInt(s.slice(0, 2), 10) * 100 + parseInt(s.slice(2), 10) - const eNum = parseInt(e.slice(0, 2), 10) * 100 + parseInt(e.slice(2), 10) - if (sNum > eNum) { - return nV >= sNum || nV < eNum ? '休眠中' : '非休眠' + async function refreshOplock() { + try { + oplock.value = await fetchOplock() + } catch { + /* 忽略:下次轮询会重试 */ } - return nV >= sNum && nV < eNum ? '休眠中' : '非休眠' } - async function toggleService(toast) { - const res = await runCmd(`sh /data/adb/modules/LuminPro/action.sh`) - toast(res.errno === 0 ? res.stdout.trim() || '状态已切换' : '操作失败: ' + res.stderr) - await load(true) + async function setBrightness(value) { + await apiSetBrightness(value) + await load({ display: false }) } - async function restartService(toast) { - toast('正在重启模块...') - const res = await runCmd(`sh /data/adb/modules/LuminPro/script/restart.sh`) - setTimeout(async () => { - await load(true) - }, 1000) - toast(res.errno === 0 ? '模块重启成功' : '模块重启失败: ' + res.stderr) + async function toggleService(snackbar) { + const res = await apiToggleService() + snackbar?.(res.ok ? res.stdout.trim() || '状态已切换' : '操作失败: ' + res.stderr) + await load({ display: false }) } - async function setBrightness(newBri, toast) { - currentBri.value = String(newBri) - const cmd = `echo -n '${newBri}' > '${_nowBriFile}' 2>/dev/null && echo 'OK'` - const res = await runCmd(cmd) - if (!(res.errno === 0 && res.stdout.includes('OK'))) { - toast('亮度设置失败,已恢复') - await load(true) - } + async function boost(snackbar) { + const res = await apiBoost() + snackbar?.(res.ok ? '已切换峰值亮度' : '操作失败: ' + res.stderr) + await load({ display: false }) + } + + async function restart(snackbar) { + const res = await apiRestart() + snackbar?.(res.ok ? '模块已重启' : '模块重启失败: ' + res.stderr) + setTimeout(() => load({ display: false }), 600) } return { - currentBri, - sysMaxBri, - inotifydPid, - inotifydState, + status, + oplock, + error, + moduleInfo, + daemon, + brightness, + display, + sleep, + cfg, isRunning, isPaused, - statusClass, statusText, - hdrRatio, - sleepStatus, + statusClass, + sleepText, + hdrText, load, - invalidatePaths, - toggleService, - restartService, + refreshOplock, setBrightness, + toggleService, + boost, + restart, } } diff --git a/webui/src/header.css b/webui/src/header.css deleted file mode 100644 index 0b92e16..0000000 --- a/webui/src/header.css +++ /dev/null @@ -1,220 +0,0 @@ -/* Header */ -.app-header { - position: absolute; - top: var(--oplock-offset, 0); - left: 0; - right: 0; - z-index: 10; - display: flex; - align-items: center; - justify-content: space-between; - padding: 25px 25px; - transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1); - will-change: transform; -} - -.header-content { - display: flex; - align-items: center; - gap: 16px; - flex: 1; -} - -.header-icon { - font-size: 2.5rem; - background: linear-gradient( - 135deg, - var(--md-sys-color-primary-container), - var(--md-sys-color-secondary-container) - ); - width: 56px; - height: 56px; - border-radius: 12px; - display: flex; - align-items: center; - justify-content: center; - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); - flex-shrink: 0; -} - -.header-text { - display: flex; - flex-direction: column; - gap: 2px; -} - -.header-text h1 { - margin: 0; - font-size: 1.5rem; - font-weight: 700; - color: var(--md-sys-color-on-background); - letter-spacing: -0.3px; -} - -.header-subtitle { - margin: 0; - font-size: 0.9rem; - color: var(--md-sys-color-on-surface-variant); - font-weight: 400; -} - -.header-version { - margin: 0; - font-size: 0.75rem; - color: var(--md-sys-color-primary); - font-weight: 600; - letter-spacing: 0.5px; - text-transform: uppercase; -} - -/* 版本通道徽标 (Beta / Dev) */ -.version-channel { - display: inline-block; - margin-left: 6px; - padding: 1px 6px; - border-radius: 999px; - font-size: 0.6875rem; - font-weight: 700; - color: var(--color-warning); - background: color-mix(in srgb, var(--color-warning) 18%, transparent); - vertical-align: middle; -} - -.header-status-container { - display: flex; - flex-direction: column; - align-items: flex-end; - gap: 12px; -} - -.header-status { - display: flex; - align-items: center; - gap: 8px; - background: var(--md-sys-color-surface-container-high); - padding: 8px 16px; - border-radius: 12px; - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface); - font-weight: 500; - box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); - border: 1px solid rgba(var(--md-sys-color-on-surface-rgb, 0, 0, 0), 0.08); -} - -.header-status-actions { - display: flex; - gap: 16px; -} - -.btn-status-action { - background: transparent; - border: none; - color: var(--md-sys-color-primary); - font-size: 0.8125rem; - font-weight: 600; - cursor: pointer; - padding: 2px 4px; - border-radius: 4px; - transition: all 0.2s; - opacity: 0.9; -} - -.btn-status-action:active { - background-color: var(--md-sys-color-primary-container); - opacity: 1; -} - -.btn-status-action:disabled { - opacity: 0.4; - cursor: not-allowed; - pointer-events: none; -} - -/* 操作锁横幅 */ -.oplock-banner { - position: fixed; - top: var(--safe-area-inset-top, 0px); - left: 0; - right: 0; - z-index: 20; - display: flex; - align-items: center; - justify-content: center; - gap: 8px; - padding: 8px 16px; - font-size: 0.8125rem; - font-weight: 500; - color: var(--md-sys-color-on-surface); - background: var(--md-sys-color-surface-container-high); - border-bottom: 1px solid var(--md-sys-color-outline-variant); - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); -} - -.oplock-spinner { - width: 14px; - height: 14px; - flex-shrink: 0; - border: 2px solid var(--md-sys-color-primary); - border-top-color: transparent; - border-radius: 50%; - animation: oplock-spin 0.8s linear infinite; -} - -@keyframes oplock-spin { - to { - transform: rotate(360deg); - } -} - -.oplock-fade-enter-active, -.oplock-fade-leave-active { - transition: - opacity 0.2s, - transform 0.2s; -} - -.oplock-fade-enter-from, -.oplock-fade-leave-to { - opacity: 0; - transform: translateY(-100%); -} - -.status-dot { - width: 10px; - height: 10px; - border-radius: 50%; - background-color: var(--md-sys-color-error); - box-shadow: 0 0 8px rgba(244, 67, 54, 0.5); - animation: status-pulse 2s infinite; -} - -@keyframes status-pulse { - 0%, - 100% { - box-shadow: 0 0 8px rgba(244, 67, 54, 0.5); - } - 50% { - box-shadow: 0 0 12px rgba(244, 67, 54, 0.8); - } -} - -@keyframes status-pulse-green { - 0%, - 100% { - box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); - } - 50% { - box-shadow: 0 0 12px rgba(76, 175, 80, 0.8); - } -} - -.header-status.status-running .status-dot { - background-color: #4caf50; - box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); - animation: status-pulse-green 2s infinite; -} - -.header-status.status-paused .status-dot, -.header-status.status-loading .status-dot { - animation: status-pulse 2s infinite; -} diff --git a/webui/src/index.css b/webui/src/index.css deleted file mode 100644 index 5ced31b..0000000 --- a/webui/src/index.css +++ /dev/null @@ -1,175 +0,0 @@ -@import 'tailwindcss'; -@import 'tw-animate-css'; - -@custom-variant dark (&:is(.dark *)); - -@theme inline { - --color-background: var(--background); - --color-foreground: var(--foreground); - --color-card: var(--card); - --color-card-foreground: var(--card-foreground); - --color-popover: var(--popover); - --color-popover-foreground: var(--popover-foreground); - --color-primary: var(--primary); - --color-primary-foreground: var(--primary-foreground); - --color-secondary: var(--secondary); - --color-secondary-foreground: var(--secondary-foreground); - --color-muted: var(--muted); - --color-muted-foreground: var(--muted-foreground); - --color-accent: var(--accent); - --color-accent-foreground: var(--accent-foreground); - --color-destructive: var(--destructive); - --color-border: var(--border); - --color-input: var(--input); - --color-ring: var(--ring); - --radius-sm: calc(var(--radius) - 4px); - --radius-md: calc(var(--radius) - 2px); - --radius-lg: var(--radius); - --radius-xl: calc(var(--radius) + 4px); - --font-sans: Geist, system-ui, -apple-system, sans-serif; - --font-mono: 'Geist Mono', 'Roboto Mono', monospace; -} - -/* =============================== - Shadcn 主题 Token (暗色, MD3 调色板) - =============================== */ -:root, -:root.dark { - --radius: 0.75rem; - - /* Shadcn tokens */ - --background: #111318; - --foreground: #e2e2e9; - --card: #1e1f25; - --card-foreground: #e2e2e9; - --popover: #2b2930; - --popover-foreground: #e2e2e9; - --primary: #a8c7fa; - --primary-foreground: #062e6f; - --secondary: #2b2930; - --secondary-foreground: #e2e2e9; - --muted: #212429; - --muted-foreground: #c4c6d0; - --accent: #1b4b9b; - --accent-foreground: #d3e3fd; - --destructive: #ffb4ab; - --border: #44474f; - --input: #44474f; - --ring: rgba(168, 199, 250, 0.5); - - /* MD3 tokens (保留,legacy CSS 仍在使用) */ - --md-sys-color-background: #111318; - --md-sys-color-background-rgb: 17, 19, 24; - --md-sys-color-on-background: #e2e2e9; - --md-sys-color-surface: #1e1f25; - --md-sys-color-surface-container: #212429; - --md-sys-color-surface-container-high: #2b2930; - --md-sys-color-surface-container-high-rgb: 43, 41, 48; - --md-sys-color-on-surface: #e2e2e9; - --md-sys-color-on-surface-variant: #c4c6d0; - --md-sys-color-primary: #a8c7fa; - --md-sys-color-primary-rgb: 168, 199, 250; - --md-sys-color-on-primary: #062e6f; - --md-sys-color-primary-container: #1b4b9b; - --md-sys-color-on-primary-container: #d3e3fd; - --md-sys-color-outline: #8e9099; - --md-sys-color-outline-variant: #44474f; - --md-sys-color-error: #ffb4ab; - --md-sys-color-on-error: #690005; - --md-sys-color-error-container: #93000a; - --border-radius-m: 16px; - --border-radius-s: 8px; - --spacing-s: 8px; - --spacing-m: 16px; - --spacing-l: 24px; - --color-warning: #f59e0b; -} - -/* =============================== - 浅色主题 Token - =============================== */ -@media (prefers-color-scheme: light) { - :root:not(.dark) { - --background: #f8f9fc; - --foreground: #191c20; - --card: #ffffff; - --card-foreground: #191c20; - --popover: #ffffff; - --popover-foreground: #191c20; - --primary: #0b57d0; - --primary-foreground: #ffffff; - --secondary: #e8eaf0; - --secondary-foreground: #191c20; - --muted: #eff1f6; - --muted-foreground: #44474f; - --accent: #d3e3fd; - --accent-foreground: #062e6f; - --destructive: #b3261e; - --border: #c4c7d0; - --input: #c4c7d0; - --ring: rgba(11, 87, 208, 0.3); - /* MD3 */ - --md-sys-color-background: #f8f9fc; - --md-sys-color-background-rgb: 248, 249, 252; - --md-sys-color-on-background: #191c20; - --md-sys-color-surface: #ffffff; - --md-sys-color-surface-container: #eff1f6; - --md-sys-color-surface-container-high: #e8eaf0; - --md-sys-color-surface-container-high-rgb: 232, 234, 240; - --md-sys-color-on-surface: #191c20; - --md-sys-color-on-surface-variant: #44474f; - --md-sys-color-primary: #0b57d0; - --md-sys-color-primary-rgb: 11, 87, 208; - --md-sys-color-on-primary: #ffffff; - --md-sys-color-primary-container: #d3e3fd; - --md-sys-color-on-primary-container: #062e6f; - --md-sys-color-outline: #74777f; - --md-sys-color-outline-variant: #c4c7d0; - --md-sys-color-error: #b3261e; - --md-sys-color-on-error: #ffffff; - --md-sys-color-error-container: #f9dedc; - --color-warning: #b45309; - } -} - -:root.light { - --background: #f8f9fc; - --foreground: #191c20; - --card: #ffffff; - --card-foreground: #191c20; - --popover: #ffffff; - --popover-foreground: #191c20; - --primary: #0b57d0; - --primary-foreground: #ffffff; - --secondary: #e8eaf0; - --secondary-foreground: #191c20; - --muted: #eff1f6; - --muted-foreground: #44474f; - --accent: #d3e3fd; - --accent-foreground: #062e6f; - --destructive: #b3261e; - --border: #c4c7d0; - --input: #c4c7d0; - --ring: rgba(11, 87, 208, 0.3); - /* MD3 */ - --md-sys-color-background: #f8f9fc; - --md-sys-color-background-rgb: 248, 249, 252; - --md-sys-color-on-background: #191c20; - --md-sys-color-surface: #ffffff; - --md-sys-color-surface-container: #eff1f6; - --md-sys-color-surface-container-high: #e8eaf0; - --md-sys-color-surface-container-high-rgb: 232, 234, 240; - --md-sys-color-on-surface: #191c20; - --md-sys-color-on-surface-variant: #44474f; - --md-sys-color-primary: #0b57d0; - --md-sys-color-primary-rgb: 11, 87, 208; - --md-sys-color-on-primary: #ffffff; - --md-sys-color-primary-container: #d3e3fd; - --md-sys-color-on-primary-container: #062e6f; - --md-sys-color-outline: #74777f; - --md-sys-color-outline-variant: #c4c7d0; - --md-sys-color-error: #b3261e; - --md-sys-color-on-error: #ffffff; - --md-sys-color-error-container: #f9dedc; - --color-warning: #b45309; -} diff --git a/webui/src/lib/utils.js b/webui/src/lib/utils.js deleted file mode 100644 index 9d7d3ea..0000000 --- a/webui/src/lib/utils.js +++ /dev/null @@ -1,6 +0,0 @@ -import { clsx } from 'clsx' -import { twMerge } from 'tailwind-merge' - -export function cn(...inputs) { - return twMerge(clsx(inputs)) -} diff --git a/webui/src/log.css b/webui/src/log.css deleted file mode 100644 index dbeab64..0000000 --- a/webui/src/log.css +++ /dev/null @@ -1,265 +0,0 @@ -/* Logs */ -.log-output { - font-family: 'Geist Mono', 'JetBrains Mono', 'Consolas', monospace; - font-size: 0.6875rem; - padding: var(--spacing-m); - background-color: #0d0e12; - color: #e3e3e3; - border-radius: var(--border-radius-m); - border: 1px solid rgba(255, 255, 255, 0.05); - flex: 1; - max-height: 60vh; - overflow-y: auto; - margin: 0; - white-space: pre-wrap; - word-wrap: break-word; - line-height: 1.5; - scrollbar-width: thin; - scrollbar-color: var(--md-sys-color-outline-variant) transparent; -} - -.log-output::-webkit-scrollbar { - width: 4px; -} - -.log-output::-webkit-scrollbar-thumb { - background-color: var(--md-sys-color-outline-variant); - border-radius: 4px; -} - -.log-filter-select { - padding: 0 12px; - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: 8px; - background-color: var(--md-sys-color-surface-container-high); - color: var(--md-sys-color-on-surface); - font-family: inherit; - font-size: 0.8125rem; - height: 32px; - cursor: pointer; - outline: none; - transition: all 0.22s ease; -} - -.log-filter-select:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); -} - -.log-output::-webkit-scrollbar { - display: none; /* Chrome, Safari */ -} - -/* Simple Toast */ -.top-blur { - position: fixed; - top: 0; - left: 0; - right: 0; - height: calc(85px + var(--safe-area-inset-top, 0px)); - z-index: 998; - pointer-events: none; - /* 基础暗色背景,增强状态栏文字可读性 */ - background: linear-gradient( - to bottom, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.85) 0%, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.4) 40%, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0) 100% - ); - /* 核心:毛玻璃滤镜 */ - -webkit-backdrop-filter: blur(16px); - backdrop-filter: blur(16px); - /* 梯度蒙版:越往上越模糊的核心逻辑 */ - -webkit-mask-image: linear-gradient( - to bottom, - rgba(0, 0, 0, 1) 0%, - rgba(0, 0, 0, 1) 30%, - rgba(0, 0, 0, 0.7) 60%, - rgba(0, 0, 0, 0) 100% - ); - mask-image: linear-gradient( - to bottom, - rgba(0, 0, 0, 1) 0%, - rgba(0, 0, 0, 1) 30%, - rgba(0, 0, 0, 0.7) 60%, - rgba(0, 0, 0, 0) 100% - ); - transform: translateZ(0); /* 开启 GPU 加速 */ - opacity: 0; - transition: opacity 0.3s ease; -} - -.top-blur.scrolled { - opacity: 1; -} - -.toast { - position: fixed; - bottom: 24px; - left: 50%; - transform: translateX(-50%) translateY(100px); - background-color: var(--md-sys-color-on-surface); - color: var(--md-sys-color-surface); - padding: 12px 24px; - border-radius: var(--border-radius-s); - font-size: 0.875rem; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); - transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); - z-index: 1000; - width: max-content; - max-width: 90vw; - text-align: center; -} - -.toast.show { - transform: translateX(-50%) translateY(0); -} - -/* Floating Navigation Bar */ -.floating-navbar { - position: fixed; - bottom: calc(18px + var(--safe-area-inset-bottom, 0px)); - left: 50%; - transform: translateX(-50%) translateZ(0); - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - background: rgba(var(--md-sys-color-surface-container-high-rgb, 43, 41, 48), 0.75); - -webkit-backdrop-filter: blur(12px); - backdrop-filter: blur(12px); - will-change: transform; - padding: 8px 16px; - border-radius: 28px; - border: 1px solid rgba(255, 255, 255, 0.08); - box-shadow: - 0 4px 12px rgba(0, 0, 0, 0.15), - 0 8px 32px rgba(0, 0, 0, 0.3); - z-index: 999; - width: fit-content; - max-width: calc(100% - 32px); - user-select: none; - -webkit-user-select: none; - -webkit-tap-highlight-color: transparent; - touch-action: none; -} - -.navbar-slider { - position: absolute; - left: 0; - top: 8px; - bottom: 8px; - height: auto; - background: var(--md-sys-color-primary-container); - border-radius: 20px; - will-change: transform, width; - pointer-events: none; - z-index: 0; -} - -.navbar-btn { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - gap: 5px; - padding: 6px 12px; - background-color: transparent; - border: none; - color: var(--md-sys-color-on-surface-variant); - font-size: 0.75rem; - cursor: pointer; - border-radius: 8px; - transition: all 0.2s ease; - flex: 1; - max-width: 90px; - white-space: nowrap; - position: relative; - z-index: 1; -} - -.navbar-btn i, -.navbar-btn svg { - width: 20px; - height: 20px; - display: flex; - align-items: center; - justify-content: center; -} - -.navbar-btn span { - font-size: 0.75rem; -} - -.navbar-btn:active { - /* No scaling here, we rely on the slider feedback */ -} - -.navbar-btn.active { - color: var(--md-sys-color-on-primary-container); -} - -/* Dropdown Menu */ -.dropdown-container { - position: relative; -} - -.dropdown-menu { - position: absolute; - top: 100%; - right: 0; - margin-top: 8px; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); - min-width: 160px; - opacity: 0; - visibility: hidden; - transform: translateY(-8px); - transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28); - z-index: 100; - display: flex; - flex-direction: column; - padding: 4px; -} - -.dropdown-menu.show { - opacity: 1; - visibility: visible; - transform: translateY(0); -} - -.dropdown-item { - display: flex; - align-items: center; - gap: 12px; - padding: 10px 12px; - border-radius: 4px; - cursor: pointer; - color: var(--md-sys-color-on-surface); - font-size: 0.875rem; - transition: background-color 0.2s; -} - -.dropdown-item:hover { - background-color: var(--md-sys-color-surface-container); -} - -.dropdown-item:active { - background-color: var(--md-sys-color-surface); -} - -.dropdown-item svg { - color: var(--md-sys-color-primary); - width: 18px; - height: 18px; -} - -.dropdown-item-danger { - color: var(--md-sys-color-error, #cf6679); -} - -.dropdown-item-danger svg { - color: var(--md-sys-color-error, #cf6679); -} diff --git a/webui/src/main.js b/webui/src/main.js index ff6a16e..88b4de0 100644 --- a/webui/src/main.js +++ b/webui/src/main.js @@ -1,11 +1,11 @@ import { createApp } from 'vue' +import './mwc.js' + +import './theme/tokens.css' +import './theme/base.css' +import './theme/components.css' +import './theme/app.css' + import App from './App.vue' -import './index.css' -import './style.css' -import './header.css' -import './components.css' -import './about.css' -import './apps.css' -import './log.css' createApp(App).mount('#app') diff --git a/webui/src/mwc.js b/webui/src/mwc.js new file mode 100644 index 0000000..a8e5d60 --- /dev/null +++ b/webui/src/mwc.js @@ -0,0 +1,31 @@ +// @material/web 组件的唯一引入入口:只 import 本项目实际用到的组件,避免打包体积膨胀。 +// 说明:Material Web Components 官方处于维护模式,不包含 M3 Expressive 的动效; +// 导航栏(navigationbar/navigationtab)位于 labs/ 目录。 + +// 按钮与图标按钮 +import '@material/web/button/filled-button.js' +import '@material/web/button/outlined-button.js' +import '@material/web/button/text-button.js' +import '@material/web/iconbutton/icon-button.js' + +// 输入类 +import '@material/web/textfield/outlined-text-field.js' +import '@material/web/select/outlined-select.js' +import '@material/web/select/select-option.js' +import '@material/web/switch/switch.js' +import '@material/web/slider/slider.js' +import '@material/web/checkbox/checkbox.js' + +// 容器与浮层 +import '@material/web/dialog/dialog.js' +import '@material/web/menu/menu.js' +import '@material/web/menu/menu-item.js' +import '@material/web/divider/divider.js' + +// 反馈 +import '@material/web/chips/chip-set.js' +import '@material/web/chips/filter-chip.js' + +// 导航(labs) +import '@material/web/labs/navigationbar/navigation-bar.js' +import '@material/web/labs/navigationtab/navigation-tab.js' diff --git a/webui/src/style.css b/webui/src/style.css deleted file mode 100644 index 09ffaed..0000000 --- a/webui/src/style.css +++ /dev/null @@ -1,131 +0,0 @@ -:root, -:root.dark { - --md-sys-color-background: #111318; - --md-sys-color-background-rgb: 17, 19, 24; - --md-sys-color-on-background: #e2e2e9; - --md-sys-color-surface: #1e1f25; - --md-sys-color-surface-container: #212429; - --md-sys-color-surface-container-high: #2b2930; - --md-sys-color-surface-container-high-rgb: 43, 41, 48; - --md-sys-color-on-surface: #e2e2e9; - --md-sys-color-on-surface-variant: #c4c6d0; - --md-sys-color-primary: #a8c7fa; - --md-sys-color-primary-rgb: 168, 199, 250; - --md-sys-color-on-primary: #062e6f; - --md-sys-color-primary-container: #1b4b9b; - --md-sys-color-on-primary-container: #d3e3fd; - --md-sys-color-outline: #8e9099; - --md-sys-color-outline-variant: #44474f; - --md-sys-color-error: #ffb4ab; - --md-sys-color-on-error: #690005; - - --border-radius-m: 16px; - --border-radius-s: 8px; - --spacing-s: 8px; - --spacing-m: 16px; - --spacing-l: 24px; -} - -@font-face { - font-family: 'Geist'; - src: url('/Geist[wght].woff2') format('woff2'); - font-weight: 100 900; - font-style: normal; -} - -@font-face { - font-family: 'Geist Mono'; - src: url('/GeistMono[wght].woff2') format('woff2'); - font-weight: 100 900; - font-style: normal; -} - -* { - box-sizing: border-box; - -webkit-tap-highlight-color: transparent; -} - -/* 隐藏所有滚动条 */ -html { - scrollbar-width: none; /* Firefox */ - -ms-overflow-style: none; /* IE/Edge */ - background-color: var(--md-sys-color-background); -} - -html::-webkit-scrollbar { - display: none; /* Chrome, Safari */ -} - -body { - margin: 0; - padding: 0; - zoom: 0.95; - /* insets 会在这里被 internal/insets.css 处理,我们预留顶底内边距 */ - padding-top: var(--safe-area-inset-top, 0); - padding-bottom: var(--safe-area-inset-bottom, 0); - background-color: var(--md-sys-color-background); - color: var(--md-sys-color-on-background); - font-family: - 'Geist', - system-ui, - -apple-system, - sans-serif; - line-height: 1.5; - scrollbar-width: none; /* Firefox */ - -ms-overflow-style: none; /* IE/Edge */ -} - -body::-webkit-scrollbar { - display: none; /* Chrome, Safari */ -} - -#app { - position: relative; - padding: 0; - max-width: 600px; - margin: 0 auto; - display: flex; - flex-direction: column; - height: calc(100dvh / 0.95); - overflow: hidden; -} - -/* header 自动隐藏 */ -#app.header-hidden .app-header { - transform: translateY(-100%); -} - -/* 滑动页面轨道 */ -.page-viewport { - flex: 1; - min-height: 0; - overflow: hidden; - position: relative; -} - -.page-track { - display: flex; - height: 100%; - transition: transform 0.38s cubic-bezier(0.25, 1, 0.5, 1); - will-change: transform; -} - -.page-slide { - width: 100%; - flex-shrink: 0; - height: 100%; - overflow-y: auto; - overflow-x: hidden; - padding: 12px; - padding-top: calc(var(--header-height, 120px) + var(--oplock-offset, 0px)); - padding-bottom: calc(16px + 80px + var(--safe-area-inset-bottom, 0px)); - scrollbar-width: none; - -ms-overflow-style: none; - display: flex; - flex-direction: column; - gap: var(--spacing-m); -} - -.page-slide::-webkit-scrollbar { - display: none; -} diff --git a/webui/src/theme/app.css b/webui/src/theme/app.css new file mode 100644 index 0000000..3ae6b70 --- /dev/null +++ b/webui/src/theme/app.css @@ -0,0 +1,274 @@ +/* ========================================================================== + 应用外壳:顶栏 / 页面滑动轨 / M3 导航栏 / 操作锁横幅 / snackbar + ========================================================================== */ + +#app { + position: relative; + display: flex; + flex-direction: column; + max-width: 600px; + margin: 0 auto; + height: calc(100dvh / 0.95); + overflow: hidden; + background-color: var(--md-sys-color-background); +} + +/* ── M3 small top app bar ─────────────────────────────────────────── */ +.app-bar { + position: relative; + z-index: 3; + flex: 0 0 auto; + display: flex; + align-items: center; + gap: var(--md-sys-spacing-1); + min-height: 64px; + padding: var(--md-sys-spacing-2) var(--md-sys-spacing-1) var(--md-sys-spacing-2) + var(--md-sys-spacing-4); + background-color: var(--md-sys-color-surface); + transition: background-color var(--md-sys-motion-duration-medium2) + var(--md-sys-motion-easing-standard); +} + +.app-bar.scrolled { + background-color: var(--md-sys-color-surface-container); +} + +.app-bar__text { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 2px; +} + +.app-bar__title { + margin: 0; + color: var(--md-sys-color-on-surface); + display: flex; + align-items: center; + gap: var(--md-sys-spacing-2); +} + +.app-bar__subtitle { + color: var(--md-sys-color-on-surface-variant); +} + +/* 发布通道徽标(Beta / Dev) */ +.channel-badge { + flex: 0 0 auto; + padding: 2px 8px; + border-radius: var(--md-sys-shape-corner-full); + background-color: var(--lp-color-warning-container); + color: var(--lp-color-warning); + font-size: var(--md-sys-typescale-label-small-size); + line-height: var(--md-sys-typescale-label-small-line-height); + font-weight: 700; + text-transform: uppercase; +} + +/* 守护进程状态胶囊 */ +.status-pill { + flex: 0 0 auto; + display: inline-flex; + align-items: center; + gap: 6px; + padding: 4px 10px; + border-radius: var(--md-sys-shape-corner-full); + background-color: var(--md-sys-color-surface-container-high); + color: var(--md-sys-color-on-surface-variant); + font-size: var(--md-sys-typescale-label-small-size); + font-weight: 600; +} + +.status-pill__dot { + width: 8px; + height: 8px; + border-radius: 50%; + background-color: var(--md-sys-color-outline); +} + +.status-pill.running .status-pill__dot { + background-color: var(--lp-color-success); + box-shadow: 0 0 8px var(--lp-color-success-container); + animation: status-pulse 2.4s var(--md-sys-motion-easing-standard) infinite; +} + +.status-pill.paused .status-pill__dot { + background-color: var(--lp-color-warning); +} + +.status-pill.stopped .status-pill__dot { + background-color: var(--md-sys-color-error); + animation: status-pulse 2s var(--md-sys-motion-easing-standard) infinite; +} + +@keyframes status-pulse { + 0%, + 100% { + opacity: 1; + } + 50% { + opacity: 0.45; + } +} + +.app-bar__actions { + flex: 0 0 auto; + display: flex; + align-items: center; + gap: 2px; +} + +/* ── 页面滑动轨 ───────────────────────────────────────────────────── */ +.page-viewport { + flex: 1; + min-height: 0; + overflow: hidden; + position: relative; +} + +.page-track { + display: flex; + height: 100%; + transition: transform var(--md-sys-motion-duration-medium4) + var(--md-sys-motion-easing-emphasized); + will-change: transform; +} + +.page-slide { + flex: 0 0 100%; + width: 100%; + height: 100%; + overflow-y: auto; + overflow-x: hidden; + display: flex; + flex-direction: column; + gap: var(--md-sys-spacing-3); + padding: var(--md-sys-spacing-3) var(--md-sys-spacing-3) + calc(var(--md-sys-spacing-5) + var(--safe-area-inset-bottom, 0px)); + scrollbar-width: none; +} + +/* ── M3 导航栏 ────────────────────────────────────────────────────── */ +md-navigation-bar { + flex: 0 0 auto; + --md-navigation-bar-container-color: var(--md-sys-color-surface-container); + --md-navigation-bar-active-indicator-color: var(--md-sys-color-secondary-container); + --md-navigation-bar-active-icon-color: var(--md-sys-color-on-secondary-container); + --md-navigation-bar-active-label-text-color: var(--md-sys-color-on-surface); + --md-navigation-bar-inactive-icon-color: var(--md-sys-color-on-surface-variant); + --md-navigation-bar-inactive-label-text-color: var(--md-sys-color-on-surface-variant); +} + +md-navigation-tab { + --md-navigation-tab-active-indicator-shape: var(--md-sys-shape-corner-full); +} + +/* ── 操作锁横幅 ───────────────────────────────────────────────────── */ +.oplock-banner { + position: absolute; + top: 0; + left: 0; + right: 0; + z-index: 5; + display: flex; + align-items: center; + gap: var(--md-sys-spacing-2); + padding: var(--md-sys-spacing-2) var(--md-sys-spacing-4); + background-color: var(--md-sys-color-surface-container-highest); + border-bottom: 1px solid var(--md-sys-color-outline-variant); + color: var(--md-sys-color-on-surface); +} + +.oplock-banner__spinner { + flex: 0 0 auto; + width: 16px; + height: 16px; + border: 2px solid var(--md-sys-color-primary); + border-top-color: transparent; + border-radius: 50%; + animation: oplock-spin 0.8s linear infinite; +} + +@keyframes oplock-spin { + to { + transform: rotate(360deg); + } +} + +.oplock-banner__text { + flex: 1; + min-width: 0; + font-size: var(--md-sys-typescale-title-small-size); + line-height: var(--md-sys-typescale-title-small-line-height); + font-weight: var(--md-sys-typescale-title-small-weight); +} + +.oplock-banner__elapsed { + font-family: var(--md-sys-typescale-font-mono); + font-size: var(--md-sys-typescale-label-medium-size); + color: var(--md-sys-color-on-surface-variant); +} + +.oplock-enter-active, +.oplock-leave-active { + transition: + opacity var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard), + transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard); +} + +.oplock-enter-from, +.oplock-leave-to { + opacity: 0; + transform: translateY(-100%); +} + +/* ── Snackbar(M3:反色表面 + 4dp 圆角)───────────────────────────── */ +.snackbar-host { + position: absolute; + left: var(--md-sys-spacing-3); + right: var(--md-sys-spacing-3); + bottom: calc(96px + var(--safe-area-inset-bottom, 0px)); + z-index: 7; + display: flex; + flex-direction: column; + align-items: center; + gap: var(--md-sys-spacing-2); + pointer-events: none; +} + +.snackbar { + pointer-events: auto; + display: flex; + align-items: center; + gap: var(--md-sys-spacing-3); + width: 100%; + min-height: 48px; + padding: var(--md-sys-spacing-3) var(--md-sys-spacing-4); + border-radius: var(--md-sys-shape-corner-extra-small); + background-color: var(--md-sys-color-inverse-surface); + color: var(--md-sys-color-inverse-on-surface); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); + font-size: var(--md-sys-typescale-body-medium-size); + line-height: var(--md-sys-typescale-body-medium-line-height); +} + +.snackbar-enter-active, +.snackbar-leave-active { + transition: + opacity var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard), + transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized-decelerate); +} + +.snackbar-enter-from, +.snackbar-leave-to { + opacity: 0; + transform: translateY(16px); +} + +/* ── 对话框:宽屏居中、窄屏留边 ───────────────────────────────────── */ +md-dialog { + --md-dialog-container-shape: var(--md-sys-shape-corner-extra-large); + max-width: min(560px, calc(100vw - 48px)); + max-height: calc(100dvh - 96px); +} diff --git a/webui/src/theme/base.css b/webui/src/theme/base.css new file mode 100644 index 0000000..8909f95 --- /dev/null +++ b/webui/src/theme/base.css @@ -0,0 +1,214 @@ +/* ========================================================================== + 基础层:字体、重置、insets、缩放、滚动条与通用排版/表面类 + ========================================================================== */ + +@font-face { + font-family: 'Geist'; + src: url('/Geist[wght].woff2') format('woff2-variations'); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Geist Mono'; + src: url('/GeistMono[wght].woff2') format('woff2-variations'); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} + +*, +*::before, +*::after { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; +} + +body { + /* 全局 0.95 视觉缩放;用户自定义缩放叠加在 html 上(沿用既有策略) */ + zoom: 0.95; + padding-top: var(--safe-area-inset-top, 0); + padding-bottom: var(--safe-area-inset-bottom, 0); + background-color: var(--md-sys-color-background); + color: var(--md-sys-color-on-background); + font-family: var(--md-sys-typescale-font); + font-size: var(--md-sys-typescale-body-medium-size); + line-height: var(--md-sys-typescale-body-medium-line-height); + font-weight: var(--md-sys-typescale-body-medium-weight); + letter-spacing: var(--md-sys-typescale-body-medium-tracking); + -webkit-font-smoothing: antialiased; + -webkit-tap-highlight-color: transparent; +} + +button, +input, +select, +textarea { + font: inherit; + color: inherit; +} + +/* 隐藏滚动条(保持移动端观感) */ +html, +body, +.scroll-area { + scrollbar-width: none; + -ms-overflow-style: none; +} + +html::-webkit-scrollbar, +body::-webkit-scrollbar, +.scroll-area::-webkit-scrollbar { + display: none; +} + +/* ── 排版工具类(直接映射 typescale)───────────────────────────────── */ +.ts-display { + font-size: var(--md-sys-typescale-display-small-size); + line-height: var(--md-sys-typescale-display-small-line-height); + font-weight: var(--md-sys-typescale-display-small-weight); +} +.ts-headline { + font-size: var(--md-sys-typescale-headline-small-size); + line-height: var(--md-sys-typescale-headline-small-line-height); + font-weight: var(--md-sys-typescale-headline-small-weight); +} +.ts-title-lg { + font-size: var(--md-sys-typescale-title-large-size); + line-height: var(--md-sys-typescale-title-large-line-height); + font-weight: var(--md-sys-typescale-title-large-weight); +} +.ts-title-md { + font-size: var(--md-sys-typescale-title-medium-size); + line-height: var(--md-sys-typescale-title-medium-line-height); + font-weight: var(--md-sys-typescale-title-medium-weight); + letter-spacing: var(--md-sys-typescale-title-medium-tracking); +} +.ts-title-sm { + font-size: var(--md-sys-typescale-title-small-size); + line-height: var(--md-sys-typescale-title-small-line-height); + font-weight: var(--md-sys-typescale-title-small-weight); + letter-spacing: var(--md-sys-typescale-title-small-tracking); +} +.ts-body-lg { + font-size: var(--md-sys-typescale-body-large-size); + line-height: var(--md-sys-typescale-body-large-line-height); +} +.ts-body { + font-size: var(--md-sys-typescale-body-medium-size); + line-height: var(--md-sys-typescale-body-medium-line-height); + letter-spacing: var(--md-sys-typescale-body-medium-tracking); +} +.ts-body-sm { + font-size: var(--md-sys-typescale-body-small-size); + line-height: var(--md-sys-typescale-body-small-line-height); + letter-spacing: var(--md-sys-typescale-body-small-tracking); +} +.ts-label { + font-size: var(--md-sys-typescale-label-large-size); + line-height: var(--md-sys-typescale-label-large-line-height); + font-weight: var(--md-sys-typescale-label-large-weight); + letter-spacing: var(--md-sys-typescale-label-large-tracking); +} +.ts-label-sm { + font-size: var(--md-sys-typescale-label-small-size); + line-height: var(--md-sys-typescale-label-small-line-height); + font-weight: var(--md-sys-typescale-label-small-weight); + letter-spacing: var(--md-sys-typescale-label-small-tracking); +} + +.supporting { + color: var(--md-sys-color-on-surface-variant); +} + +.mono { + font-family: var(--md-sys-typescale-font-mono); + font-variant-numeric: tabular-nums; +} + +/* ── 表面:MD3 用色调层级而非阴影表达层级 ─────────────────────────── */ +.section { + background-color: var(--md-sys-color-surface-container-low); + border-radius: var(--md-sys-shape-corner-large); + padding: var(--md-sys-spacing-4); + display: flex; + flex-direction: column; + gap: var(--md-sys-spacing-3); +} + +.section-header { + display: flex; + align-items: center; + gap: var(--md-sys-spacing-2); + min-height: 40px; +} + +.section-header .section-title { + flex: 1; + margin: 0; + color: var(--md-sys-color-on-surface); +} + +.divider { + height: 1px; + background-color: var(--md-sys-color-outline-variant); + border: 0; + margin: 0; +} + +/* 可点击行:用状态层表达交互反馈(MD3 state layer) */ +.state-layer { + position: relative; + overflow: hidden; + cursor: pointer; + transition: background-color var(--md-sys-motion-duration-short4) + var(--md-sys-motion-easing-standard); +} + +.state-layer::after { + content: ''; + position: absolute; + inset: 0; + background-color: currentColor; + opacity: 0; + pointer-events: none; + transition: opacity var(--md-sys-motion-duration-short2) + var(--md-sys-motion-easing-standard); +} + +.state-layer:hover::after { + opacity: var(--md-sys-state-hover-opacity); +} + +.state-layer:focus-visible::after { + opacity: var(--md-sys-state-focus-opacity); +} + +.state-layer:active::after { + opacity: var(--md-sys-state-pressed-opacity); +} + +/* 焦点环(不做全局关闭,保证键盘/无障碍可见) */ +:focus-visible { + outline: 2px solid var(--md-sys-color-primary); + outline-offset: 2px; +} + +/* 屏幕阅读器专用文本 */ +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; +} diff --git a/webui/src/theme/components.css b/webui/src/theme/components.css new file mode 100644 index 0000000..65373c0 --- /dev/null +++ b/webui/src/theme/components.css @@ -0,0 +1,160 @@ +/* ========================================================================== + 跨视图复用的模式:设置行 / 状态徽标 / 空状态 / 折叠区 / 状态网格 / 列表行 + 视图专属样式放在各自的 diff --git a/webui/src/views/AppsView.vue b/webui/src/views/AppsView.vue index a057971..c8a58aa 100644 --- a/webui/src/views/AppsView.vue +++ b/webui/src/views/AppsView.vue @@ -1,67 +1,99 @@ - - - - 黑名单 - - - - - - 智能选择 - - - - 更多 - - - - - - - - - - {{ showingSystemApps ? '隐藏系统应用' : '显示系统应用' }} - - - 手动添加包名 - - - 全选 - - - 全不选 - - - 反选 - - - + + + 黑名单 + 未保存 + + + + + 被选中的应用在前台时不执行亮度提升。 + 推荐选择视频类、相册等需要展示 HDR 内容的应用。 + + + + + + 按活动屏蔽 + + 扫描获取 + - - - 被选中的应用将不生效本模块推荐选择视频类、相册等需展示 HDR 内容的应用 - - - - - - 按活动屏蔽 - - 扫描获取 - - - - - 确认 - + + + 确认 + - - - - - - {{ appCount }} - - 保存 - - - - - - 加载中... - - - 加载失败: {{ loadError }} - - - - - - - - - - - - {{ row.app.appLabel }} - {{ row.app.uid }} - - - {{ row.app.packageName }} - 系统 - - - - - - - - - - {{ entry.slice(row.app.packageName.length + 1) }} - - - - - - - - - - - - - - + + - - - - - 获取活动名 - - - - - - - - - 将 Web UI 挂小窗 - - 在开始获取前,请先将当前 Web UI 调整为小窗模式。 - 这样在后续步骤中,你可以同时操作目标应用并看到 Web UI 的反馈。 - - 已挂小窗,下一步 - - - - - 切换到目标界面 - - 切换到需要屏蔽的应用界面,并点击 「开始获取」 - 检测到非 Web UI 界面后将自动停止。 - {{ - pickerStatusText - }} - - 开始获取 - - - - - + + + + 保存 + + + + + 共 {{ appCount }} 个应用 + 加载中… + + + + + 加载中… + + 加载失败: {{ appsApi.loadError.value }} + + 没有匹配的应用 + + + + + + + + {{ row.app.appLabel }} + {{ row.app.uid }} + + + {{ row.app.packageName }} + 系统 + + + + + - 检测到活动 - 以下活动将被添加到按活动屏蔽列表: - {{ pickerResult }} - - 重试 - 确认添加 + + + + + {{ entry.slice(row.app.packageName.length + 1) }} + + + + + - - + + + + + + + + + + + 获取活动名 + + + + + + 将 Web UI 挂为小窗 + + 开始之前先把当前 Web UI 切到小窗模式,这样后续可以一边操作目标应用,一边看到这里的反馈。 + + 已挂小窗,下一步 + + + + + 切换到目标界面 + + 切换到需要屏蔽的应用界面,然后点击「开始获取」。检测到非 Web UI 界面后会自动停止。 + + {{ pickerStatus }} + 开始获取 + + + + + 检测到活动 + 以下活动将被添加到按活动屏蔽列表: + {{ pickerResult }} + + + + + 重试 + + + 确认添加 + + + + + diff --git a/webui/src/views/ConfigView.vue b/webui/src/views/ConfigView.vue index 8984aed..4e9f77a 100644 --- a/webui/src/views/ConfigView.vue +++ b/webui/src/views/ConfigView.vue @@ -1,430 +1,389 @@ - - - - - 亮度配置 - - {{ config.dirty.value ? '未保存' : '已保存' }} - + + + + 亮度配置 + + {{ config.dirtyMain.value ? '未保存' : '已保存' }} + + + + + 亮度调节 + + + + + + + + + 执行策略 + + + + + + + + + + + + + + + + - - 亮度调节 + + + 恢复默认 + + + 保存配置 + + + - - - 前台最大亮度 - 触发亮度提升的阈值 - - + + + + 高级设置 + + {{ config.dirtyAdvanced.value ? '未保存' : '已保存' }} + + + + + + + + 运行环境 - - - - 峰值最大亮度 - 亮度提升的目标值 - - - - - - - 亮度提升步数 - 约 0.02 秒 / 步 - - + + + + 支持的事件 + - + + - - 执行策略 + - - - 自动亮度时休眠 - 开启自动亮度时不提升 - - + + 系统管理 - - - - 显示 HDR 内容时休眠 - 比率 ≥ 进入阈值休眠,≤ 退出阈值恢复 - 出现闪屏建议改用黑名单 - - - - - - - - - 进入 - - - - 退出 - - - - - - - 兼容模式 (轮询驱动) - 不使用事件监听,改用 2 秒一次轮询 - 仅在事件驱动失效时开启,会略微增加耗电 - - - - - - - 定时休眠 - 设定时段内不提升亮度 - - - - - - - - - : - - - 至 - - - : - - - - - - - - + - {{ resetConfirming ? '确认恢复?' : '恢复默认' }} - - - 保存配置 - - - + 关闭 + 仅错误 + 警告+ + 全部 + - - - - 高级设置 - - {{ config.dirtyAdvanced.value ? '未保存' : '已保存' }} - - - - - - - 运行环境 - - - - 调试模式 - 记录详细 inotify 事件到日志 - 需重启模块生效,用完请关闭 - - - - - - - 监听事件 - 默认 c,改后需重启模块 - - 查看支持事件 - - - - - - - - 当前亮度节点 - 改后需重启模块 - - - - - - - 最大亮度节点 - 改后需重启模块 - - - - - - - 系统管理 - - - 日志大小限制 - 单位: KB - - - - - - - 日志等级 - 低于此级别不写入日志 - - - 关闭 - 仅错误 - 警告+ - 全部 - - - - - - {})" - > - 保存设置 - - + + + 保存设置 + - + + - - - - Web UI 配置 - - - - - - 界面设置 + + + + Web UI 配置 + + {{ webuiDirty ? '未保存' : '已保存' }} + + + - - - 自动刷新 - 定时拉取状态和日志 - - - + + + + 界面设置 + + + + + 跟随系统 + 浅色 + 深色 + + - - - 状态/日志刷新间隔 - ms,最小 100 - - - - - - - 外观主题 - - - 跟随系统 - 浅色 - 深色 - - - - - - 界面缩放 - 50%–150%,立即生效 - - - - - - - 保存配置 - + + + 保存配置 + - - + + + + + + + 支持的事件字母 + {{ INOTIFY_HELP }} + + 知道了 + + + + diff --git a/webui/src/views/LogView.vue b/webui/src/views/LogView.vue index f46e79c..e194473 100644 --- a/webui/src/views/LogView.vue +++ b/webui/src/views/LogView.vue @@ -1,107 +1,118 @@ - - - 运行日志 - - - - - - 更多操作 - - - - - - - - 复制日志 - - 导出日志文件 - - - - {{ clearConfirming ? '再次点击确认清除' : '清除日志' }} - - - + + + 运行日志 + + + + - - - - - {{ opt.label }} - - - + + + - - {{ log.filteredLog.value || '暂无日志' }} + {{ log.error.value }} + + 暂无{{ log.level.value ? ` [${log.level.value}] ` : '' }}日志 + + [{{ entry.time }}] [{{ entry.tag }}] [{{ entry.level }}] {{ entry.message }} + + + + + diff --git a/webui/src/views/StatusView.vue b/webui/src/views/StatusView.vue index 37239f3..175b34a 100644 --- a/webui/src/views/StatusView.vue +++ b/webui/src/views/StatusView.vue @@ -1,116 +1,148 @@ - - - 实时状态 - - - + + + 实时状态 + 读取失败 - - - + + - {{ item.label }} - - {{ item.value }} + {{ item.label }} + + {{ item.value }} - - - - 亮度 - {{ brightnessPercent }} - - - 0% - - 100% - - + + 亮度节点不可用:{{ nodeError }} + + + 系统自动亮度已开启,模块会跳过亮度提升 + + + + + 亮度 + {{ percent }}% + + + + + + + + + 触发阈值 {{ uiThreshold }}(约 {{ thresholdPercent }}%):亮度达到该值后模块会平滑提升到峰值。 + + + + + + diff --git a/webui/vite.config.js b/webui/vite.config.js index 4774bdf..ac9a34b 100644 --- a/webui/vite.config.js +++ b/webui/vite.config.js @@ -1,10 +1,18 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' -import tailwindcss from '@tailwindcss/vite' import { fileURLToPath, URL } from 'node:url' export default defineConfig({ - plugins: [vue(), tailwindcss()], + plugins: [ + vue({ + template: { + compilerOptions: { + // @material/web 提供的是自定义元素(md-*),交由浏览器处理而非 Vue 组件 + isCustomElement: (tag) => tag.startsWith('md-'), + }, + }, + }), + ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)),
{{ description }}
+ 被选中的应用在前台时不执行亮度提升。 + 推荐选择视频类、相册等需要展示 HDR 内容的应用。 +
- 被选中的应用将不生效本模块推荐选择视频类、相册等需展示 HDR 内容的应用 -
- 在开始获取前,请先将当前 Web UI 调整为小窗模式。 - 这样在后续步骤中,你可以同时操作目标应用并看到 Web UI 的反馈。 -
- 切换到需要屏蔽的应用界面,并点击 「开始获取」 - 检测到非 Web UI 界面后将自动停止。 - {{ - pickerStatusText - }} -
以下活动将被添加到按活动屏蔽列表:
+ 开始之前先把当前 Web UI 切到小窗模式,这样后续可以一边操作目标应用,一边看到这里的反馈。 +
+ 切换到需要屏蔽的应用界面,然后点击「开始获取」。检测到非 Web UI 界面后会自动停止。 +
{{ pickerStatus }}
{{ pickerResult }}
{{ INOTIFY_HELP }}
{{ log.filteredLog.value || '暂无日志' }}
[{{ entry.time }}] [{{ entry.tag }}] [{{ entry.level }}] {{ entry.message }} +
+ 亮度节点不可用:{{ nodeError }} +
+ 系统自动亮度已开启,模块会跳过亮度提升 +
+ 触发阈值 {{ uiThreshold }}(约 {{ thresholdPercent }}%):亮度达到该值后模块会平滑提升到峰值。 +