From 220075f94c117e87713b8a31d28d86afa0d0e7f2 Mon Sep 17 00:00:00 2001 From: Yule Date: Thu, 10 Sep 2026 05:27:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?docs:=20=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E6=AE=B5=E4=BD=8D=E8=A7=84=E8=8C=83=E4=BF=AE=E6=AD=A3=E4=B8=BA?= =?UTF-8?q?=205x=3Dbeta=20/=209x=3D=E6=AD=A3=E5=BC=8F=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEVELOPMENT.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 136c6b9..80e5685 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -80,17 +80,21 @@ npm run build `version` 采用语义化命名(不含 versionCode),`versionCode` 单独维护: ``` -versionCode = 主版本 × 1000000 + 次版本 × 10000 + 修订 × 100 + 段位 +versionCode = 基础号 × 100 + 段位 +基础号 = 主版本 × 10000 + 次版本 × 100 + 修订 ``` +以 `V2.5.0` 为例,基础号为 `20500`,末两位即段位: + | 段位 | 段位值 | version 示例 | versionCode | | --- | --- | --- | --- | -| 正式 | `00` | `V2.5.0` | `2050000` | -| beta | `51–99` | `V2.5.0-beta.1` | `2050051` | | dev | `01–49` | `V2.5.0-dev.1` | `2050001` | +| beta | `51–59` | `V2.5.0-beta.1` | `2050051` | +| 正式 | `90`(9x) | `V2.5.0` | `2050090` | -排序恒为 `dev < beta < 下一个正式版`:dev 测试者可平滑收到 beta,beta 用户会平滑收到 -下一个正式版。同周期内从 beta/dev 回退到正式版需手动刷包(管理器不支持降级)。 +末两位约定:**`5x` 表示 beta,`9x` 表示正式版**。排序恒为 +`dev < beta < 同周期正式版`:dev 测试者可平滑收到 beta,beta 用户会平滑收到同周期的 +正式版。只有从 beta/dev 回退到已发布的正式版才需要手动刷包(管理器不支持降级)。 tag 名 = version 的小写形式(如 `v2.5.0-beta.1`),Release 资产名为 `LuminPro_.zip`。 From 6a54cdae71b01a793fb2d6eb1cea3e36bff8ef58 Mon Sep 17 00:00:00 2001 From: Yule Date: Thu, 10 Sep 2026 09:12:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(go):=20=E6=96=B0=E5=A2=9E=20JSON=20API?= =?UTF-8?q?=20=E4=BE=9B=20WebUI=20=E4=BD=BF=E7=94=A8=EF=BC=8Coplock/state?= =?UTF-8?q?=20=E6=94=B9=E4=B8=BA=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - internal/api:状态聚合(status)、操作锁读写与自愈、daemon 运行状态、 日志读取解析、module.prop 解析与通道判定 - status 一次调用取代原先 5~6 条 shell 命令;--no-display 跳过 dumpsys/settings - oplock 文件改为 JSON 并带 kind(ramp/boost/restart/manual), WebUI 可显示具体操作文案;兼容旧版裸 PID 格式 - daemon 维护 pid/state.json(模式、最近事件/操作、缓存的比率与亮度) - 新子命令:status / oplock / brightness set / config read|patch(stdin) / log tail|clear|export;config patch 走 stdin 并严格校验类型 - pid/inotifyd.pid → pid/daemon.pid;清理 action.sh 死标记、统一文案 --- action.sh | 6 +- customize.sh | 4 +- go/cmd/luminpro/main.go | 194 +++++++++++++++-- go/internal/api/api_test.go | 343 ++++++++++++++++++++++++++++++ go/internal/api/log.go | 117 ++++++++++ go/internal/api/oplock.go | 149 +++++++++++++ go/internal/api/paths.go | 47 ++++ go/internal/api/state.go | 85 ++++++++ go/internal/api/status.go | 271 +++++++++++++++++++++++ go/internal/config/config.go | 66 ++++-- go/internal/config/config_test.go | 105 +++++++++ go/internal/daemon/daemon.go | 157 +++++++++----- go/internal/daemon/daemon_test.go | 11 +- go/internal/daemon/ops.go | 31 +-- service.sh | 2 +- 15 files changed, 1471 insertions(+), 117 deletions(-) create mode 100644 go/internal/api/api_test.go create mode 100644 go/internal/api/log.go create mode 100644 go/internal/api/oplock.go create mode 100644 go/internal/api/paths.go create mode 100644 go/internal/api/state.go create mode 100644 go/internal/api/status.go diff --git a/action.sh b/action.sh index e12f263..9d920e9 100644 --- a/action.sh +++ b/action.sh @@ -1,18 +1,16 @@ #!/system/bin/sh -# 快速切换脚本 +#shellcheck shell=ash +# 快速启停切换(管理器「操作」按钮 / WebUI 调用) MODDIR="/data/adb/modules/LuminPro" PID_DIR="$MODDIR/pid" STOP_FLAG="$PID_DIR/stop.flag" -UP_FLAG="$PID_DIR/up.flag" -# 切换逻辑 if [ -f "$STOP_FLAG" ]; then rm -f "$STOP_FLAG" echo "LuminPro: 服务已启用" else touch "$STOP_FLAG" - rm -f "$UP_FLAG" echo "LuminPro: 服务已暂停" fi diff --git a/customize.sh b/customize.sh index 5250512..19c0e75 100755 --- a/customize.sh +++ b/customize.sh @@ -246,7 +246,7 @@ CHECK_DEVICE_COMPATIBILITY() { if [ "$prefix" = "25128PNA1" ] || [ "$prefix" = "2512BPNDA" ]; then echo "" echo " ✿ 您可能是 Xiaomi 17 Ultra 用户,建议使用 '0' 事件作为监测对象" - echo " ✿ 是否将 inotifyd 监测事件修改为 '0'? (音量 + 确认,音量 - 跳过)" + echo " ✿ 是否将监听事件修改为 '0'? (音量 + 确认,音量 - 跳过)" if [ "$(btn)" = "0" ]; then "$BIN" config set inotify_events=0 >/dev/null 2>&1 echo " ✦ 已设置为 0 事件监测" @@ -327,7 +327,7 @@ END() { else echo " - 休眠时段: 未配置" fi - echo " - inotifyd 事件: $inotify" + echo " - 监听事件: $inotify" echo " - 当前亮度节点: $now_path" echo " - 最大亮度节点: $max_path" [ ! -f "$now_path" ] && echo " ⚠ 当前亮度节点不存在, 重启后功能将不会启用" diff --git a/go/cmd/luminpro/main.go b/go/cmd/luminpro/main.go index 8b815d9..e0e67aa 100644 --- a/go/cmd/luminpro/main.go +++ b/go/cmd/luminpro/main.go @@ -2,11 +2,19 @@ package main import ( + "encoding/json" + "errors" "fmt" + "io" "os" "path/filepath" "sort" + "strconv" + "strings" + "time" + "github.com/YuleBest/LuminPro/go/internal/api" + "github.com/YuleBest/LuminPro/go/internal/brightness" "github.com/YuleBest/LuminPro/go/internal/config" "github.com/YuleBest/LuminPro/go/internal/daemon" "github.com/YuleBest/LuminPro/go/internal/logging" @@ -28,7 +36,7 @@ func run(args []string) error { if err != nil { return err } - paths := daemon.DefaultPaths(moduleDir) + paths := api.DefaultPaths(moduleDir) log := logging.New(paths.LogFile, config.DefaultLogLevel, config.DefaultLogMaxSize) switch args[0] { @@ -51,8 +59,16 @@ func run(args []string) error { return err } return daemon.Restart(paths, self, log) + case "status": + return runStatus(paths, args[1:]) + case "oplock": + return emitJSON(api.ReadOplock(paths.Oplock)) + case "brightness": + return runBrightness(paths, args[1:]) case "config": return runConfig(paths, args[1:]) + case "log": + return runLog(paths, args[1:]) case "help", "-h", "--help": return usage() default: @@ -64,16 +80,20 @@ func usage() error { fmt.Print(`luminpro - LuminPro 模块守护进程 用法: - luminpro daemon 启动守护进程(监听亮度节点并自动提升) - luminpro boost 一键提升到峰值亮度 / 再次调用恢复 - luminpro restart 重启模块(daemon 未运行时按需拉起) - luminpro config <操作> 配置管理 - init 写入默认配置(已存在则补齐字段) - ensure 补齐缺失字段 - set key=value [...] 写入字段(按字段类型编码) - inspect <旧目录> 输出旧配置字段(key=value 行) - migrate <旧目录> [目标] 迁移旧配置 - remove-old-txt <旧目录> 删除旧版 txt 配置 + luminpro daemon 启动守护进程(监听亮度节点并自动提升) + luminpro boost 一键提升到峰值亮度 / 再次调用恢复 + luminpro restart 重启模块(daemon 未运行时按需拉起) + + luminpro status [--no-display] 聚合状态(JSON) + luminpro oplock 操作锁状态(JSON) + luminpro brightness set <值> 设置亮度(JSON) + + luminpro config <操作> 配置管理(JSON) + read | patch(stdin JSON) | get | set k=v [...] | summary + init | ensure | inspect <旧目录> | migrate <旧目录> [目标] | remove-old-txt <旧目录> + + luminpro log <操作> + tail [-n 行数] [--raw] | clear | export [目录] 模块目录默认由可执行文件位置推导,可用环境变量 LUMINPRO_MODDIR 覆盖(调试用)。 `) @@ -95,7 +115,116 @@ func resolveModuleDir() (string, error) { return filepath.Dir(filepath.Dir(exe)), nil } -func runConfig(paths daemon.Paths, args []string) error { +// emitJSON 输出 JSON(不转义 HTML,供前端直接解析)。 +func emitJSON(v any) error { + enc := json.NewEncoder(os.Stdout) + enc.SetEscapeHTML(false) + return enc.Encode(v) +} + +func runStatus(paths api.Paths, args []string) error { + includeDisplay := true + for _, arg := range args { + if arg == "--no-display" { + includeDisplay = false + } + } + cfg, err := config.Load(paths.ConfigFile) + if err != nil { + return err + } + status := api.BuildStatus(paths, cfg, api.StatusDeps{ + AutoBrightness: system.AutoBrightness{Runner: system.ExecRunner{}}, + HDR: system.HdrRatio{Runner: system.ExecRunner{}}, + Now: time.Now, + }, api.StatusOptions{IncludeDisplay: includeDisplay}) + return emitJSON(status) +} + +func runBrightness(paths api.Paths, args []string) error { + if len(args) < 2 || args[0] != "set" { + return errors.New("用法: luminpro brightness set <值>") + } + value, err := strconv.Atoi(strings.TrimSpace(args[1])) + if err != nil { + return fmt.Errorf("亮度值必须是整数: %q", args[1]) + } + if value < 0 { + return errors.New("亮度值不能为负") + } + cfg, err := config.Load(paths.ConfigFile) + if err != nil { + return err + } + if max, err := brightness.ReadInt(cfg.MaxBriFile); err == nil && max > 0 && value > max { + return fmt.Errorf("亮度值需在 0~%d 之间", max) + } + if !api.FileExists(cfg.NowBriFile) { + return fmt.Errorf("亮度节点不存在: %s", cfg.NowBriFile) + } + + if err := os.MkdirAll(paths.PIDDir, 0o755); err != nil { + return err + } + if err := api.WriteOplock(paths.Oplock, api.KindManual); err != nil { + return err + } + defer api.RemoveOplock(paths.Oplock) + + if err := brightness.WriteInt(cfg.NowBriFile, value); err != nil { + return err + } + return emitJSON(map[string]any{"ok": true, "value": value}) +} + +func runLog(paths api.Paths, args []string) error { + if len(args) == 0 { + return errors.New("用法: luminpro log tail|clear|export") + } + switch args[0] { + case "tail": + lines, raw := 100, false + for i := 1; i < len(args); i++ { + switch { + case args[i] == "--raw": + raw = true + case args[i] == "-n" && i+1 < len(args): + if n, err := strconv.Atoi(args[i+1]); err == nil { + lines = n + } + i++ + case strings.HasPrefix(args[i], "-n="): + if n, err := strconv.Atoi(strings.TrimPrefix(args[i], "-n=")); err == nil { + lines = n + } + } + } + page, err := api.TailLog(paths.LogFile, lines, raw) + if err != nil { + return err + } + return emitJSON(page) + case "clear": + if err := api.ClearLog(paths.LogFile); err != nil { + return err + } + return emitJSON(map[string]any{"ok": true}) + case "export": + dir := "/sdcard" + if len(args) > 1 { + dir = args[1] + } + path, err := api.ExportLog(paths.LogFile, dir) + if err != nil { + return err + } + return emitJSON(map[string]any{"ok": true, "path": path}) + default: + return fmt.Errorf("未知 log 操作: %s", args[0]) + } +} + +func runConfig(paths api.Paths, args []string) error { if len(args) == 0 { return usage() } @@ -104,14 +233,41 @@ func runConfig(paths daemon.Paths, args []string) error { return config.Init(paths.ConfigFile) case "ensure": return config.Ensure(paths.ConfigFile) + case "read": + cfg, err := config.Load(paths.ConfigFile) + if err != nil { + return err + } + data, err := cfg.JSON() + if err != nil { + return err + } + _, err = os.Stdout.Write(append(data, '\n')) + return err + case "patch": + input, err := io.ReadAll(os.Stdin) + if err != nil { + return err + } + var patch map[string]json.RawMessage + if err := json.Unmarshal(input, &patch); err != nil { + return fmt.Errorf("补丁必须是 JSON 对象: %w", err) + } + if err := config.Patch(paths.ConfigFile, patch); err != nil { + return err + } + return emitJSON(map[string]any{"ok": true, "patched": len(patch)}) case "set": if len(args) < 2 { - return fmt.Errorf("set 需要至少一个 key=value") + return errors.New("set 需要至少一个 key=value") } - return config.Set(paths.ConfigFile, args[1:]) + if err := config.Set(paths.ConfigFile, args[1:]); err != nil { + return err + } + return emitJSON(map[string]any{"ok": true}) case "get": if len(args) < 2 { - return fmt.Errorf("get 需要字段名") + return errors.New("get 需要字段名") } cfg, err := config.Load(paths.ConfigFile) if err != nil { @@ -132,17 +288,17 @@ func runConfig(paths daemon.Paths, args []string) error { return nil case "inspect": if len(args) < 2 { - return fmt.Errorf("inspect 需要旧配置目录") + return errors.New("inspect 需要旧配置目录") } old, ok := config.InspectOld(args[1]) if !ok { - return fmt.Errorf("未找到可迁移的旧配置") + return errors.New("未找到可迁移的旧配置") } printOld(old) return nil case "migrate": if len(args) < 2 { - return fmt.Errorf("migrate 需要旧配置目录") + return errors.New("migrate 需要旧配置目录") } target := paths.ConfigFile if len(args) >= 3 { @@ -156,7 +312,7 @@ func runConfig(paths daemon.Paths, args []string) error { return nil case "remove-old-txt": if len(args) < 2 { - return fmt.Errorf("remove-old-txt 需要旧配置目录") + return errors.New("remove-old-txt 需要旧配置目录") } return config.RemoveOldTxt(args[1]) default: diff --git a/go/internal/api/api_test.go b/go/internal/api/api_test.go new file mode 100644 index 0000000..79f5a8d --- /dev/null +++ b/go/internal/api/api_test.go @@ -0,0 +1,343 @@ +package api + +import ( + "encoding/json" + "errors" + "os" + "path/filepath" + "strconv" + "sync" + "testing" + "time" + + "github.com/YuleBest/LuminPro/go/internal/config" + "github.com/YuleBest/LuminPro/go/internal/system" +) + +// scriptRunner 是可编程的命令假实现。 +type scriptRunner struct { + mu sync.Mutex + outputs map[string]string +} + +func (r *scriptRunner) Output(name string, args ...string) (string, error) { + r.mu.Lock() + defer r.mu.Unlock() + key := name + for _, a := range args { + key += " " + a + } + if v, ok := r.outputs[key]; ok { + return v, nil + } + return "", errors.New("no output") +} + +func TestParseLogLine(t *testing.T) { + cases := []struct { + line string + want LogEntry + }{ + { + "[09-10 12:34:56] [luminpro] [INFO] 触发提升", + LogEntry{Time: "09-10 12:34:56", Tag: "luminpro", Level: "INFO", Message: "触发提升"}, + }, + { + "[09-10 12:34:56] [luminpro] [SUCCESS] 亮度提升完成 (3000)", + LogEntry{Time: "09-10 12:34:56", Tag: "luminpro", Level: "SUCCESS", Message: "亮度提升完成 (3000)"}, + }, + { + "没有格式的一行", + LogEntry{Message: "没有格式的一行"}, + }, + } + for _, tc := range cases { + if got := ParseLogLine(tc.line); got != tc.want { + t.Errorf("ParseLogLine(%q) = %+v, 期望 %+v", tc.line, got, tc.want) + } + } +} + +func TestTailLog(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "service.log") + content := "[09-10 12:00:00] [luminpro] [INFO] 第一条\n" + + "[09-10 12:00:01] [luminpro] [WARN] 第二条\n" + + "[09-10 12:00:02] [luminpro] [ERROR] 第三条\n" + if err := os.WriteFile(path, []byte(content), 0o644); err != nil { + t.Fatal(err) + } + + page, err := TailLog(path, 2, false) + if err != nil { + t.Fatal(err) + } + if page.Total != 3 || len(page.Entries) != 2 { + t.Fatalf("应取末 2 条(共 3 条): total=%d len=%d", page.Total, len(page.Entries)) + } + if page.Entries[0].Level != "WARN" || page.Entries[1].Message != "第三条" { + t.Fatalf("条目内容不正确: %+v", page.Entries) + } + + raw, err := TailLog(path, 1, true) + if err != nil { + t.Fatal(err) + } + if raw.Raw == "" || len(raw.Entries) != 0 { + t.Fatalf("--raw 模式应只返回原文: %+v", raw) + } + + missing, err := TailLog(filepath.Join(dir, "不存在.log"), 10, false) + if err != nil || len(missing.Entries) != 0 { + t.Fatalf("缺失文件应返回空页且不报错: %+v %v", missing, err) + } +} + +func TestClearAndExportLog(t *testing.T) { + dir := t.TempDir() + src := filepath.Join(dir, "service.log") + if err := os.WriteFile(src, []byte("data\n"), 0o644); err != nil { + t.Fatal(err) + } + outDir := filepath.Join(dir, "out") + if err := os.Mkdir(outDir, 0o755); err != nil { + t.Fatal(err) + } + + path, err := ExportLog(src, outDir) + if err != nil { + t.Fatal(err) + } + if data, err := os.ReadFile(path); err != nil || string(data) != "data\n" { + t.Fatalf("导出内容不正确: %q %v", string(data), err) + } + if _, err := ExportLog(src, filepath.Join(dir, "缺失目录")); err == nil { + t.Fatal("导出目录不可用时应报错") + } + + if err := ClearLog(src); err != nil { + t.Fatal(err) + } + if data, _ := os.ReadFile(src); len(data) != 0 { + t.Fatalf("清空后应为空文件: %q", string(data)) + } +} + +func TestOplockLifecycle(t *testing.T) { + path := filepath.Join(t.TempDir(), "oplock") + + if got := ReadOplock(path); got.Locked { + t.Fatal("无锁文件应返回未锁定") + } + + if err := WriteOplock(path, KindRamp); err != nil { + t.Fatal(err) + } + got := ReadOplock(path) + if !got.Locked || got.PID != os.Getpid() || got.Kind != KindRamp { + t.Fatalf("锁状态不正确: %+v", got) + } + if got.Label != "正在调整亮度" { + t.Fatalf("锁文案不正确: %q", got.Label) + } + + RemoveOplock(path) + if got := ReadOplock(path); got.Locked { + t.Fatal("释放后应返回未锁定") + } +} + +// 遗留锁(持锁进程已死)应被就地清理。 +func TestOplockSelfHeals(t *testing.T) { + path := filepath.Join(t.TempDir(), "oplock") + if err := os.WriteFile(path, []byte(`{"pid":999999,"kind":"ramp","startedAt":1}`), 0o644); err != nil { + t.Fatal(err) + } + if got := ReadOplock(path); got.Locked { + t.Fatal("进程已死的锁应视为未锁定") + } + if _, err := os.Stat(path); err == nil { + t.Fatal("遗留锁文件应被清理") + } +} + +// 兼容旧版裸 PID 格式的锁文件。 +func TestOplockLegacyFormat(t *testing.T) { + path := filepath.Join(t.TempDir(), "oplock") + if err := os.WriteFile(path, []byte(strconv.Itoa(os.Getpid())), 0o644); err != nil { + t.Fatal(err) + } + got := ReadOplock(path) + if !got.Locked || got.PID != os.Getpid() { + t.Fatalf("旧格式应可识别: %+v", got) + } + + if err := os.WriteFile(path, []byte("garbage"), 0o644); err != nil { + t.Fatal(err) + } + if got := ReadOplock(path); got.Locked { + t.Fatal("无法解析的内容应视为未锁定") + } +} + +func TestChannelOf(t *testing.T) { + cases := map[string]string{ + "V2.5.0": "stable", + "V2.5.0-beta.1": "beta", + "V2.5.0-Beta.2": "beta", + "V2.5.0-dev.3": "dev", + "V2.4-2401": "stable", + } + for version, want := range cases { + if got := ChannelOf(version); got != want { + t.Errorf("ChannelOf(%q) = %q, 期望 %q", version, got, want) + } + } +} + +func TestReadModuleInfo(t *testing.T) { + dir := t.TempDir() + prop := "id=LuminPro\nname=LuminPro丨测试\nversion=V2.5.0-beta.2\nversionCode=2050052\n" + if err := os.WriteFile(filepath.Join(dir, "module.prop"), []byte(prop), 0o644); err != nil { + t.Fatal(err) + } + info := ReadModuleInfo(dir) + if info.ID != "LuminPro" || info.Version != "V2.5.0-beta.2" || info.VersionCode != 2050052 || info.Channel != "beta" { + t.Fatalf("module.prop 解析不正确: %+v", info) + } + // 缺失文件时回退默认值 + if info := ReadModuleInfo(filepath.Join(dir, "不存在")); info.Channel != "stable" { + t.Fatalf("缺失 module.prop 应回退 stable: %+v", info) + } +} + +func TestBuildStatus(t *testing.T) { + dir := t.TempDir() + paths := DefaultPaths(dir) + if err := os.MkdirAll(paths.PIDDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.MkdirAll(filepath.Dir(paths.ConfigFile), 0o755); err != nil { + t.Fatal(err) + } + + node := filepath.Join(dir, "brightness") + maxNode := filepath.Join(dir, "max_brightness") + if err := os.WriteFile(node, []byte("1200"), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(maxNode, []byte("4000"), 0o644); err != nil { + t.Fatal(err) + } + + cfg := config.Default() + cfg.NowBriFile = node + cfg.MaxBriFile = maxNode + cfg.UIMaxBri = 1000 + cfg.MaxBri = 3000 + cfg.SleepTime = "2300-0700" + cfg.BlacklistApps = []string{"com.a"} + if err := cfg.Save(paths.ConfigFile); err != nil { + t.Fatal(err) + } + + // daemon 状态 + if err := os.WriteFile(paths.PIDFile, []byte(strconv.Itoa(os.Getpid())), 0o644); err != nil { + t.Fatal(err) + } + if err := WriteState(paths.StateFile, DaemonState{ + PID: os.Getpid(), + StartedAt: time.Now().Add(-90 * time.Second).Unix(), + Mode: "event", + Ratio: &RatioInfo{Value: 1.08, At: time.Now().Unix()}, + HdrSleep: true, + }); err != nil { + t.Fatal(err) + } + if err := WriteOplock(paths.Oplock, KindRamp); err != nil { + t.Fatal(err) + } + + runner := &scriptRunner{outputs: map[string]string{ + "settings get system screen_brightness_mode": "1\n", + "dumpsys display": "hdrSdrRatio 1.02\n", + }} + status := BuildStatus(paths, cfg, StatusDeps{ + AutoBrightness: system.AutoBrightness{Runner: runner}, + HDR: system.HdrRatio{Runner: runner}, + Now: func() time.Time { return time.Date(2026, 9, 10, 12, 0, 0, 0, time.Local) }, + }, StatusOptions{IncludeDisplay: true}) + + if status.Module.Version != "" && status.Module.Channel != "stable" { + t.Fatalf("模块信息不正确: %+v", status.Module) + } + if !status.Daemon.Running || status.Daemon.PID != os.Getpid() || status.Daemon.Mode != "event" { + t.Fatalf("daemon 状态不正确: %+v", status.Daemon) + } + if status.Daemon.UptimeSec < 80 { + t.Fatalf("运行时长计算不正确: %d", status.Daemon.UptimeSec) + } + if status.Brightness.Current != 1200 || status.Brightness.Max != 4000 || status.Brightness.Percent != 30 { + t.Fatalf("亮度信息不正确: %+v", status.Brightness) + } + if status.Sleep.Window != "2300-0700" || status.Sleep.Active { + t.Fatalf("休眠状态不正确: %+v", status.Sleep) + } + if !status.Oplock.Locked || status.Oplock.Kind != KindRamp { + t.Fatalf("操作锁不正确: %+v", status.Oplock) + } + if status.Config.UIMaxBri != 1000 || status.Config.BlacklistCount != 1 { + t.Fatalf("配置摘要不正确: %+v", status.Config) + } + if status.Display == nil || status.Display.HdrRatio != 1.02 || !status.Display.HdrKnown || !status.Display.AutoBrightness || !status.Display.HdrSleep { + t.Fatalf("显示信息不正确: %+v", status.Display) + } + + // --no-display:不调用 dumpsys/settings,改用 daemon 缓存 + light := BuildStatus(paths, cfg, StatusDeps{ + AutoBrightness: system.AutoBrightness{Runner: runner}, + HDR: system.HdrRatio{Runner: runner}, + }, StatusOptions{IncludeDisplay: false}) + if light.Display != nil { + t.Fatalf("--no-display 不应包含显示信息: %+v", light.Display) + } + + // JSON 可序列化 + if _, err := json.Marshal(light); err != nil { + t.Fatalf("状态无法序列化: %v", err) + } +} + +// dumpsys 读取失败时回退到 daemon 缓存并标记 stale。 +func TestBuildStatusFallsBackToCachedRatio(t *testing.T) { + dir := t.TempDir() + paths := DefaultPaths(dir) + if err := os.MkdirAll(paths.PIDDir, 0o755); err != nil { + t.Fatal(err) + } + node := filepath.Join(dir, "brightness") + if err := os.WriteFile(node, []byte("500"), 0o644); err != nil { + t.Fatal(err) + } + cfg := config.Default() + cfg.NowBriFile = node + if err := cfg.Save(paths.ConfigFile); err != nil { + t.Fatal(err) + } + if err := WriteState(paths.StateFile, DaemonState{ + PID: os.Getpid(), + Ratio: &RatioInfo{Value: 1.30, At: time.Now().Unix()}, + }); err != nil { + t.Fatal(err) + } + + runner := &scriptRunner{outputs: map[string]string{}} // 全部失败 + status := BuildStatus(paths, cfg, StatusDeps{ + AutoBrightness: system.AutoBrightness{Runner: runner}, + HDR: system.HdrRatio{Runner: runner}, + }, StatusOptions{IncludeDisplay: true}) + + if status.Display == nil || !status.Display.HdrKnown || !status.Display.HdrStale || status.Display.HdrRatio != 1.30 { + t.Fatalf("应回退到缓存的比率并标记 stale: %+v", status.Display) + } +} diff --git a/go/internal/api/log.go b/go/internal/api/log.go new file mode 100644 index 0000000..1e8b2a3 --- /dev/null +++ b/go/internal/api/log.go @@ -0,0 +1,117 @@ +package api + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "time" +) + +// LogEntry 是一条结构化日志。 +type LogEntry struct { + Time string `json:"time"` + Tag string `json:"tag"` + Level string `json:"level"` + Message string `json:"message"` +} + +// LogPage 是 log tail 的输出。 +type LogPage struct { + Entries []LogEntry `json:"entries"` + Raw string `json:"raw,omitempty"` + SizeKB int `json:"sizeKB"` + Total int `json:"total"` +} + +// ParseLogLine 解析 `[09-10 12:34:56] [luminpro] [INFO] msg`。 +// 不匹配时整行作为 message,level/tag 留空,前端可原样展示。 +func ParseLogLine(line string) LogEntry { + rest := line + var entry LogEntry + + if strings.HasPrefix(rest, "[") { + if end := strings.Index(rest, "]"); end > 0 { + entry.Time = strings.TrimSpace(rest[1:end]) + rest = strings.TrimSpace(rest[end+1:]) + } + } + if strings.HasPrefix(rest, "[") { + if end := strings.Index(rest, "]"); end > 0 { + entry.Tag = strings.TrimSpace(rest[1:end]) + rest = strings.TrimSpace(rest[end+1:]) + } + } + if strings.HasPrefix(rest, "[") { + if end := strings.Index(rest, "]"); end > 0 { + entry.Level = strings.ToUpper(strings.TrimSpace(rest[1:end])) + rest = strings.TrimSpace(rest[end+1:]) + } + } + entry.Message = rest + return entry +} + +// TailLog 读取日志末尾若干行。 +func TailLog(path string, lines int, raw bool) (LogPage, error) { + page := LogPage{Entries: []LogEntry{}} + + data, err := os.ReadFile(path) + if err != nil { + if os.IsNotExist(err) { + return page, nil + } + return page, err + } + page.SizeKB = int(int64(len(data)) / 1024) + + text := strings.TrimRight(string(data), "\n") + if text == "" { + return page, nil + } + all := strings.Split(text, "\n") + page.Total = len(all) + + if lines > 0 && len(all) > lines { + all = all[len(all)-lines:] + } + if raw { + page.Raw = strings.Join(all, "\n") + return page, nil + } + for _, line := range all { + page.Entries = append(page.Entries, ParseLogLine(line)) + } + return page, nil +} + +// ClearLog 清空日志文件。 +func ClearLog(path string) error { + return os.WriteFile(path, nil, 0o644) +} + +// ExportLog 把日志复制到目标目录,返回最终路径。 +func ExportLog(src, dir string) (string, error) { + if dir == "" { + dir = "/sdcard" + } + if info, err := os.Stat(dir); err != nil || !info.IsDir() { + return "", fmt.Errorf("导出目录不可用: %s", dir) + } + name := fmt.Sprintf("LuminPro_%s.log", time.Now().Format("20060102_150405")) + dst := filepath.Join(dir, name) + + data, err := os.ReadFile(src) + if err != nil { + return "", err + } + if err := os.WriteFile(dst, data, 0o644); err != nil { + return "", err + } + return dst, nil +} + +// FormatLogEntry 反向格式化,供需要时使用。 +func FormatLogEntry(e LogEntry) string { + return fmt.Sprintf("[%s] [%s] [%s] %s", e.Time, e.Tag, e.Level, e.Message) +} diff --git a/go/internal/api/oplock.go b/go/internal/api/oplock.go new file mode 100644 index 0000000..5c738c2 --- /dev/null +++ b/go/internal/api/oplock.go @@ -0,0 +1,149 @@ +package api + +import ( + "encoding/json" + "os" + "strconv" + "strings" + "time" +) + +// 操作锁类型,用于前端显示更具体的提示文案。 +const ( + KindRamp = "ramp" // 亮度渐变写入 + KindBoost = "boost" // 一键峰值 / 恢复 + KindRestart = "restart" // 重启模块 + KindManual = "manual" // 前端手动设置亮度 +) + +// OplockFile 是 pid/oplock 的内容。 +type OplockFile struct { + PID int `json:"pid"` + Kind string `json:"kind"` + StartedAt int64 `json:"startedAt"` +} + +// OplockStatus 是给前端的操作锁状态。 +type OplockStatus struct { + Locked bool `json:"locked"` + PID int `json:"pid,omitempty"` + Kind string `json:"kind,omitempty"` + Label string `json:"label,omitempty"` + Seconds int `json:"seconds"` +} + +// KindLabel 返回操作类型的中文说明。 +func KindLabel(kind string) string { + switch kind { + case KindRamp: + return "正在调整亮度" + case KindBoost: + return "正在执行一键提升" + case KindRestart: + return "正在重启模块" + case KindManual: + return "正在设置亮度" + default: + return "正在执行后台操作" + } +} + +// WriteOplock 写入操作锁(持锁进程把自己的 PID 与操作类型写进去)。 +func WriteOplock(path, kind string) error { + info := OplockFile{PID: os.Getpid(), Kind: kind, StartedAt: time.Now().Unix()} + data, err := json.Marshal(info) + if err != nil { + return err + } + return os.WriteFile(path, data, 0o644) +} + +// RemoveOplock 释放操作锁。 +func RemoveOplock(path string) { + _ = os.Remove(path) +} + +// ReadOplock 读取并校验操作锁;持锁进程已不存在时视为遗留锁并就地清理。 +func ReadOplock(path string) OplockStatus { + data, err := os.ReadFile(path) + if err != nil { + return OplockStatus{} + } + text := strings.TrimSpace(string(data)) + if text == "" { + _ = os.Remove(path) + return OplockStatus{} + } + + var info OplockFile + if err := json.Unmarshal([]byte(text), &info); err != nil { + // 兼容旧版裸 PID 格式 + if pid, perr := strconv.Atoi(text); perr == nil { + info = OplockFile{PID: pid} + } else { + _ = os.Remove(path) + return OplockStatus{} + } + } + + if info.PID <= 0 || !ProcessAlive(info.PID) { + _ = os.Remove(path) // 遗留锁:进程已被 SIGKILL 等 + return OplockStatus{} + } + + seconds := 0 + if info.StartedAt > 0 { + if d := time.Now().Unix() - info.StartedAt; d > 0 { + seconds = int(d) + } + } + return OplockStatus{ + Locked: true, + PID: info.PID, + Kind: info.Kind, + Label: KindLabel(info.Kind), + Seconds: seconds, + } +} + +// ProcessAlive 通过 /proc 判断进程是否存活。 +func ProcessAlive(pid int) bool { + if pid <= 0 { + return false + } + _, err := os.Stat("/proc/" + strconv.Itoa(pid)) + return err == nil +} + +// DaemonPID 读取 daemon PID 文件并确认进程存活。 +func DaemonPID(pidFile string) (int, bool) { + data, err := os.ReadFile(pidFile) + if err != nil { + return 0, false + } + pid, err := strconv.Atoi(strings.TrimSpace(string(data))) + if err != nil || pid <= 0 { + return 0, false + } + if !ProcessAlive(pid) { + return 0, false + } + return pid, true +} + +// ProcessState 读取 /proc//status 的状态字符(R/S/D/Z/T/I)。 +func ProcessState(pid int) string { + data, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/status") + if err != nil { + return "" + } + for _, line := range strings.Split(string(data), "\n") { + if strings.HasPrefix(line, "State:") { + fields := strings.Fields(line) + if len(fields) >= 2 { + return fields[1] + } + } + } + return "" +} diff --git a/go/internal/api/paths.go b/go/internal/api/paths.go new file mode 100644 index 0000000..f4ef1f9 --- /dev/null +++ b/go/internal/api/paths.go @@ -0,0 +1,47 @@ +// Package api 提供 WebUI 使用的 JSON API:状态聚合、操作锁、daemon 运行状态与日志读取。 +// +// 设计目标:把过去前端要跑 5~6 条 shell 命令(cat /proc、dumpsys、settings、读节点) +// 才能拿到的信息合并成一次调用,并让所有写操作走 argv/stdin 而不是拼接 shell 字符串。 +package api + +import ( + "os" + "path/filepath" +) + +// Paths 是模块内的文件布局(与 WebUI 的契约)。 +type Paths struct { + ModuleDir string + PIDDir string + ConfigFile string + LogFile string + PIDFile string + StopFlag string + PauseFlag string + Oplock string + BoostFlag string + StateFile string +} + +// DefaultPaths 按模块目录推导全部路径。 +func DefaultPaths(moduleDir string) Paths { + pidDir := filepath.Join(moduleDir, "pid") + return Paths{ + ModuleDir: moduleDir, + PIDDir: pidDir, + ConfigFile: filepath.Join(moduleDir, "config", "config.json"), + LogFile: filepath.Join(moduleDir, "service.log"), + PIDFile: filepath.Join(pidDir, "daemon.pid"), + StopFlag: filepath.Join(pidDir, "stop.flag"), + PauseFlag: filepath.Join(pidDir, "daemon.pause"), + Oplock: filepath.Join(pidDir, "oplock"), + BoostFlag: filepath.Join(pidDir, "boost.flag"), + StateFile: filepath.Join(pidDir, "state.json"), + } +} + +// FileExists 判断普通文件是否存在。 +func FileExists(path string) bool { + info, err := os.Stat(path) + return err == nil && !info.IsDir() +} diff --git a/go/internal/api/state.go b/go/internal/api/state.go new file mode 100644 index 0000000..5d5f60d --- /dev/null +++ b/go/internal/api/state.go @@ -0,0 +1,85 @@ +package api + +import ( + "encoding/json" + "os" +) + +// daemon 运行状态文件的 DTO。daemon 每次判定后刷新,status 直接读取, +// 避免前端高频刷新时反复调用 dumpsys。 + +// EventInfo 最近一次监听到的事件。 +type EventInfo struct { + Letters string `json:"letters"` + At int64 `json:"at"` +} + +// ActionInfo 最近一次亮度操作。 +type ActionInfo struct { + Kind string `json:"kind"` + From int `json:"from"` + To int `json:"to"` + At int64 `json:"at"` +} + +// RatioInfo 最近一次读到的 HDR/SDR 比率。 +type RatioInfo struct { + Value float64 `json:"value"` + At int64 `json:"at"` +} + +// BoolInfo 带时间戳的布尔值。 +type BoolInfo struct { + Value bool `json:"value"` + At int64 `json:"at"` +} + +// IntInfo 带时间戳的整数。 +type IntInfo struct { + Value int `json:"value"` + At int64 `json:"at"` +} + +// DaemonState 是 pid/state.json 的内容。 +type DaemonState struct { + PID int `json:"pid"` + StartedAt int64 `json:"startedAt"` + Mode string `json:"mode"` // event | polling + Node string `json:"node"` + Paused bool `json:"paused"` + HdrSleep bool `json:"hdrSleep"` + LastEvent *EventInfo `json:"lastEvent,omitempty"` + LastAction *ActionInfo `json:"lastAction,omitempty"` + Ratio *RatioInfo `json:"ratio,omitempty"` + AutoBrightness *BoolInfo `json:"autoBrightness,omitempty"` + Brightness *IntInfo `json:"brightness,omitempty"` +} + +// WriteState 原子写入运行状态。 +func WriteState(path string, s DaemonState) error { + data, err := json.Marshal(s) + if err != nil { + return err + } + tmp := path + ".tmp" + if err := os.WriteFile(tmp, data, 0o644); err != nil { + return err + } + return os.Rename(tmp, path) +} + +// ReadState 读取运行状态;文件缺失或损坏时返回 false。 +func ReadState(path string) (DaemonState, bool) { + var s DaemonState + data, err := os.ReadFile(path) + if err != nil { + return s, false + } + if err := json.Unmarshal(data, &s); err != nil { + return s, false + } + if s.PID <= 0 || !ProcessAlive(s.PID) { + return s, false + } + return s, true +} diff --git a/go/internal/api/status.go b/go/internal/api/status.go new file mode 100644 index 0000000..169f4ef --- /dev/null +++ b/go/internal/api/status.go @@ -0,0 +1,271 @@ +package api + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" + "time" + + "github.com/YuleBest/LuminPro/go/internal/config" + "github.com/YuleBest/LuminPro/go/internal/policy" + "github.com/YuleBest/LuminPro/go/internal/system" +) + +// ModuleInfo 来自 module.prop。 +type ModuleInfo struct { + ID string `json:"id"` + Name string `json:"name"` + Version string `json:"version"` + VersionCode int `json:"versionCode"` + Channel string `json:"channel"` +} + +// ReadModuleInfo 解析模块根目录下的 module.prop,并从版本号推导发布通道。 +func ReadModuleInfo(moduleDir string) ModuleInfo { + info := ModuleInfo{ID: "LuminPro", Channel: "stable"} + f, err := os.Open(moduleDir + "/module.prop") + if err != nil { + return info + } + defer f.Close() + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + key, value, ok := strings.Cut(line, "=") + if !ok { + continue + } + value = strings.TrimSpace(value) + switch strings.TrimSpace(key) { + case "id": + info.ID = value + case "name": + info.Name = value + case "version": + info.Version = value + case "versionCode": + if n, err := strconv.Atoi(value); err == nil { + info.VersionCode = n + } + } + } + info.Channel = ChannelOf(info.Version) + return info +} + +// ChannelOf 依据版本号判断发布通道。 +func ChannelOf(version string) string { + v := strings.ToLower(version) + switch { + case strings.Contains(v, "-beta"): + return "beta" + case strings.Contains(v, "-dev"): + return "dev" + default: + return "stable" + } +} + +// DaemonPart 是守护进程状态。 +type DaemonPart struct { + PID int `json:"pid"` + Running bool `json:"running"` + State string `json:"state"` + Mode string `json:"mode"` + Paused bool `json:"paused"` + UptimeSec int `json:"uptimeSec"` +} + +// BrightnessPart 是亮度信息。 +type BrightnessPart struct { + Current int `json:"current"` + Max int `json:"max"` + Percent int `json:"percent"` + Node string `json:"node"` + MaxNode string `json:"maxNode"` + Error string `json:"error,omitempty"` +} + +// DisplayPart 是屏幕相关状态(需要 dumpsys / settings)。 +type DisplayPart struct { + HdrRatio float64 `json:"hdrRatio"` + HdrKnown bool `json:"hdrKnown"` + HdrStale bool `json:"hdrStale"` + HdrSleep bool `json:"hdrSleep"` + AutoBrightness bool `json:"autoBrightness"` +} + +// SleepPart 是休眠时段状态。 +type SleepPart struct { + Window string `json:"window"` + Active bool `json:"active"` +} + +// ConfigPart 是前端展示需要的配置子集。 +type ConfigPart struct { + UIMaxBri int `json:"uiMaxBri"` + MaxBri int `json:"maxBri"` + StepsNum int `json:"stepsNum"` + SleepTime string `json:"sleepTime"` + AutoBriSleep int `json:"autoBriSleep"` + DisplayHdrSleep int `json:"displayHdrSleep"` + HdrEnterRatio float64 `json:"hdrEnterRatio"` + HdrExitRatio float64 `json:"hdrExitRatio"` + CompatibilityMode int `json:"compatibilityMode"` + LogLevel string `json:"logLevel"` + LogMaxSize int `json:"logMaxSize"` + DebugMode int `json:"debugMode"` + NowBriFile string `json:"nowBriFile"` + MaxBriFile string `json:"maxBriFile"` + BlacklistCount int `json:"blacklistCount"` +} + +// LogPart 是日志文件信息。 +type LogPart struct { + Path string `json:"path"` + SizeKB int `json:"sizeKB"` +} + +// Status 是 status 子命令的输出。 +type Status struct { + Module ModuleInfo `json:"module"` + Daemon DaemonPart `json:"daemon"` + Brightness BrightnessPart `json:"brightness"` + Display *DisplayPart `json:"display,omitempty"` + Sleep SleepPart `json:"sleep"` + Oplock OplockStatus `json:"oplock"` + Config ConfigPart `json:"config"` + Log LogPart `json:"log"` +} + +// StatusDeps 是状态聚合用到的系统调用(测试可注入)。 +type StatusDeps struct { + AutoBrightness system.AutoBrightness + HDR system.HdrRatio + Now func() time.Time +} + +// StatusOptions 控制是否读取需要系统调用的字段。 +type StatusOptions struct { + // IncludeDisplay=false 时跳过 dumpsys/settings,仅用 daemon 缓存的数值, + // 供前端高频刷新(例如操作锁轮询)使用。 + IncludeDisplay bool +} + +// BuildStatus 聚合一次完整状态。 +func BuildStatus(p Paths, cfg config.Config, deps StatusDeps, opts StatusOptions) Status { + now := deps.Now + if now == nil { + now = time.Now + } + + st := Status{ + Module: ReadModuleInfo(p.ModuleDir), + Oplock: ReadOplock(p.Oplock), + Sleep: SleepPart{ + Window: cfg.SleepTime, + Active: policy.InSleepWindow(cfg.SleepTime, now()), + }, + Config: ConfigPart{ + UIMaxBri: cfg.UIMaxBri, + MaxBri: cfg.MaxBri, + StepsNum: cfg.StepsNum, + SleepTime: cfg.SleepTime, + AutoBriSleep: cfg.AutoBriSleep, + DisplayHdrSleep: cfg.DisplayHdrSleep, + HdrEnterRatio: cfg.HdrEnterRatio, + HdrExitRatio: cfg.HdrExitRatio, + CompatibilityMode: cfg.CompatibilityMode, + LogLevel: cfg.LogLevel, + LogMaxSize: cfg.LogMaxSize, + DebugMode: cfg.DebugMode, + NowBriFile: cfg.NowBriFile, + MaxBriFile: cfg.MaxBriFile, + BlacklistCount: len(cfg.BlacklistApps), + }, + } + + // 守护进程 + daemonState, hasState := ReadState(p.StateFile) + if pid, alive := DaemonPID(p.PIDFile); alive { + st.Daemon = DaemonPart{ + PID: pid, + Running: true, + State: ProcessState(pid), + } + if hasState { + st.Daemon.Mode = daemonState.Mode + if daemonState.StartedAt > 0 { + if d := now().Unix() - daemonState.StartedAt; d > 0 { + st.Daemon.UptimeSec = int(d) + } + } + } + } + st.Daemon.Paused = FileExists(p.StopFlag) + + // 亮度节点 + st.Brightness = BrightnessPart{Node: cfg.NowBriFile, MaxNode: cfg.MaxBriFile} + current, err := readIntFile(cfg.NowBriFile) + if err != nil { + st.Brightness.Error = err.Error() + } + maxBri, err := readIntFile(cfg.MaxBriFile) + if err != nil && st.Brightness.Error == "" { + st.Brightness.Error = err.Error() + } + st.Brightness.Current = current + st.Brightness.Max = maxBri + if maxBri > 0 { + st.Brightness.Percent = current * 100 / maxBri + } + + // 日志 + st.Log = LogPart{Path: p.LogFile} + if fi, err := os.Stat(p.LogFile); err == nil { + st.Log.SizeKB = int(fi.Size() / 1024) + } + + if !opts.IncludeDisplay { + return st + } + + display := &DisplayPart{} + if deps.HDR.Runner != nil { + if ratio, ok := deps.HDR.Ratio(); ok { + display.HdrRatio = ratio + display.HdrKnown = true + } else if hasState && daemonState.Ratio != nil { + display.HdrRatio = daemonState.Ratio.Value + display.HdrKnown = true + display.HdrStale = true + } + } + if deps.AutoBrightness.Runner != nil { + display.AutoBrightness = deps.AutoBrightness.Enabled() + } else if hasState && daemonState.AutoBrightness != nil { + display.AutoBrightness = daemonState.AutoBrightness.Value + } + display.HdrSleep = hasState && daemonState.HdrSleep + st.Display = display + return st +} + +func readIntFile(path string) (int, error) { + data, err := os.ReadFile(path) + if err != nil { + return 0, err + } + text := strings.TrimSpace(string(data)) + v, err := strconv.Atoi(text) + if err != nil { + return 0, fmt.Errorf("节点内容不是整数: %q", text) + } + return v, nil +} diff --git a/go/internal/config/config.go b/go/internal/config/config.go index 7c75005..98ed851 100644 --- a/go/internal/config/config.go +++ b/go/internal/config/config.go @@ -227,8 +227,38 @@ func parseValue(s string) any { } // applyRaw 用原始键值填充强类型字段,未识别的键留在 extra。 +// 单个字段损坏时保留默认值,不阻断整体加载(与旧 get_cfg 的降级一致)。 func (c *Config) applyRaw(raw map[string]json.RawMessage) { - known := map[string]any{ + _ = c.apply(raw, false) +} + +// apply 填充字段;strict=true 时字段类型不匹配直接报错(用于写路径)。 +func (c *Config) apply(raw map[string]json.RawMessage, strict bool) error { + known := fieldTargets(c) + + c.extra = nil + for key, value := range raw { + dst, ok := known[key] + if !ok { + if c.extra == nil { + c.extra = map[string]json.RawMessage{} + } + c.extra[key] = value + continue + } + if err := json.Unmarshal(value, dst); err != nil && strict { + return fmt.Errorf("字段 %s 的值类型不正确: %w", key, err) + } + } + if c.BlacklistApps == nil { + c.BlacklistApps = []string{} + } + return nil +} + +// fieldTargets 返回已知字段名到目标字段指针的映射。 +func fieldTargets(c *Config) map[string]any { + return map[string]any{ "ui_max_bri": &c.UIMaxBri, "max_bri": &c.MaxBri, "steps_num": &c.StepsNum, @@ -246,22 +276,30 @@ func (c *Config) applyRaw(raw map[string]json.RawMessage) { "debug_mode": &c.DebugMode, "blacklist_apps": &c.BlacklistApps, } +} - c.extra = nil - for key, value := range raw { - if dst, ok := known[key]; ok { - // 单个字段损坏时保留默认值,不阻断整体加载。 - _ = json.Unmarshal(value, dst) - continue - } - if c.extra == nil { - c.extra = map[string]json.RawMessage{} - } - c.extra[key] = value +// JSON 返回完整配置(含全部已知字段,缺失项已补默认值)。 +func (c Config) JSON() ([]byte, error) { + return json.Marshal(c.toRawMap()) +} + +// Patch 用一份 JSON 对象浅合并配置并原子保存。 +// 与 Load 不同,这里对已知字段做严格类型校验,避免写坏配置。 +func Patch(path string, patch map[string]json.RawMessage) error { + c, err := Load(path) + if err != nil { + return err } - if c.BlacklistApps == nil { - c.BlacklistApps = []string{} + raw := c.toRawMap() + for key, value := range patch { + raw[key] = value } + + probe := Default() + if err := probe.apply(raw, true); err != nil { + return err + } + return probe.Save(path) } // toRawMap 导出为原始键值表(含未知键)。 diff --git a/go/internal/config/config_test.go b/go/internal/config/config_test.go index db53128..21a1380 100644 --- a/go/internal/config/config_test.go +++ b/go/internal/config/config_test.go @@ -166,6 +166,111 @@ func TestInitCreatesAndEnsureFills(t *testing.T) { } } +func TestPatchMergesShallowly(t *testing.T) { + path := filepath.Join(t.TempDir(), "config.json") + if err := Set(path, []string{"ui_max_bri=1000", "max_bri=3000", "sleep_time=2200-0700"}); err != nil { + t.Fatal(err) + } + // 注入一个未知字段,验证 patch 后仍保留 + raw, _ := os.ReadFile(path) + var withUnknown map[string]json.RawMessage + _ = json.Unmarshal(raw, &withUnknown) + withUnknown["future_field"] = json.RawMessage(`"keep-me"`) + merged, _ := json.Marshal(withUnknown) + if err := os.WriteFile(path, merged, 0o644); err != nil { + t.Fatal(err) + } + + patch := map[string]json.RawMessage{ + "ui_max_bri": json.RawMessage(`1500`), + "blacklist_apps": json.RawMessage(`["com.a","com.b"]`), + } + if err := Patch(path, patch); err != nil { + t.Fatal(err) + } + + c, err := Load(path) + if err != nil { + t.Fatal(err) + } + if c.UIMaxBri != 1500 { + t.Fatalf("patch 未生效: %d", c.UIMaxBri) + } + if c.MaxBri != 3000 || c.SleepTime != "2200-0700" { + t.Fatalf("未 patch 的字段被改动: %+v", c) + } + if len(c.BlacklistApps) != 2 { + t.Fatalf("数组字段未写入: %v", c.BlacklistApps) + } + + // 未知字段保留 + data, _ := os.ReadFile(path) + var check map[string]json.RawMessage + _ = json.Unmarshal(data, &check) + if _, ok := check["future_field"]; !ok { + t.Fatal("patch 后未知字段丢失") + } +} + +func TestPatchRejectsWrongTypeAndKeepsFile(t *testing.T) { + path := filepath.Join(t.TempDir(), "config.json") + if err := Set(path, []string{"ui_max_bri=1000"}); err != nil { + t.Fatal(err) + } + before, _ := os.ReadFile(path) + + err := Patch(path, map[string]json.RawMessage{ + "ui_max_bri": json.RawMessage(`"不是数字"`), + }) + if err == nil { + t.Fatal("类型错误应被拒绝") + } + after, _ := os.ReadFile(path) + if string(before) != string(after) { + t.Fatal("校验失败时不应改动配置文件") + } + + if err := Patch(path, map[string]json.RawMessage{ + "blacklist_apps": json.RawMessage(`{"not":"an array"}`), + }); err == nil { + t.Fatal("数组字段类型错误应被拒绝") + } +} + +func TestConfigJSONIsComplete(t *testing.T) { + path := filepath.Join(t.TempDir(), "config.json") + if err := os.WriteFile(path, []byte(`{"ui_max_bri":800}`), 0o644); err != nil { + t.Fatal(err) + } + c, err := Load(path) + if err != nil { + t.Fatal(err) + } + data, err := c.JSON() + if err != nil { + t.Fatal(err) + } + var raw map[string]json.RawMessage + if err := json.Unmarshal(data, &raw); err != nil { + t.Fatal(err) + } + for _, key := range []string{ + "ui_max_bri", "max_bri", "steps_num", "log_max_size", "auto_bri_sleep", + "display_hdr_sleep", "hdr_enter_ratio", "hdr_exit_ratio", "compatibility_mode", + "sleep_time", "inotify_events", "now_bri_file", "max_bri_file", "log_level", + "debug_mode", "blacklist_apps", + } { + if _, ok := raw[key]; !ok { + t.Errorf("JSON 缺少字段 %s", key) + } + } + var ui int + _ = json.Unmarshal(raw["ui_max_bri"], &ui) + if ui != 800 { + t.Fatalf("已有值未保留: %d", ui) + } +} + func TestInspectAndMigrateOldTxt(t *testing.T) { oldDir := t.TempDir() write := func(name, content string) { diff --git a/go/internal/daemon/daemon.go b/go/internal/daemon/daemon.go index 9f3c85c..2510b6d 100644 --- a/go/internal/daemon/daemon.go +++ b/go/internal/daemon/daemon.go @@ -8,13 +8,13 @@ import ( "fmt" "os" "os/signal" - "path/filepath" "strconv" "strings" "sync" "syscall" "time" + "github.com/YuleBest/LuminPro/go/internal/api" "github.com/YuleBest/LuminPro/go/internal/brightness" "github.com/YuleBest/LuminPro/go/internal/config" "github.com/YuleBest/LuminPro/go/internal/inotify" @@ -24,33 +24,10 @@ import ( ) // Paths 是模块内的文件布局(与 WebUI 的契约,不可随意改名)。 -type Paths struct { - ModuleDir string - PIDDir string - ConfigFile string - LogFile string - PIDFile string - StopFlag string - PauseFlag string - Oplock string - BoostFlag string -} +type Paths = api.Paths // DefaultPaths 按模块目录推导全部路径。 -func DefaultPaths(moduleDir string) Paths { - pidDir := filepath.Join(moduleDir, "pid") - return Paths{ - ModuleDir: moduleDir, - PIDDir: pidDir, - ConfigFile: filepath.Join(moduleDir, "config", "config.json"), - LogFile: filepath.Join(moduleDir, "service.log"), - PIDFile: filepath.Join(pidDir, "inotifyd.pid"), - StopFlag: filepath.Join(pidDir, "stop.flag"), - PauseFlag: filepath.Join(pidDir, "daemon.pause"), - Oplock: filepath.Join(pidDir, "oplock"), - BoostFlag: filepath.Join(pidDir, "boost.flag"), - } -} +func DefaultPaths(moduleDir string) Paths { return api.DefaultPaths(moduleDir) } // Deps 是守护进程的外部依赖,测试时可注入假实现。 type Deps struct { @@ -99,17 +76,30 @@ type Daemon struct { ratioCache float64 haveRatioCache bool nodeMissingLogged bool + + // 运行状态(供 WebUI 的 status 读取,避免前端反复调用 dumpsys) + stateMu sync.Mutex + state api.DaemonState } // New 创建守护进程并加载初始配置。 func New(paths Paths, deps Deps) (*Daemon, error) { deps.withDefaults() - d := &Daemon{paths: paths, deps: deps} + d := &Daemon{ + paths: paths, + deps: deps, + state: api.DaemonState{ + PID: os.Getpid(), + StartedAt: time.Now().Unix(), + Mode: "event", + }, + } cfg, err := config.Load(paths.ConfigFile) if err != nil { return nil, err } d.setConfig(cfg) + d.state.Node = cfg.NowBriFile return d, nil } @@ -132,6 +122,7 @@ func (d *Daemon) Run() error { defer d.cleanup() d.log().Info("守护进程已启动") + d.flushState() sigCh := make(chan os.Signal, 4) signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT) @@ -197,8 +188,10 @@ func (d *Daemon) serve(sigCh chan os.Signal, cfgCh chan struct{}) exitReason { if cfg.CompatibilityMode == 1 { d.log().Warn("兼容模式已开启 (轮询驱动)") + d.setStateMode("polling") go d.compatLoop(stop) } else { + d.setStateMode("event") w, err := inotify.New() if err != nil { d.log().Error("初始化 inotify 失败: " + err.Error()) @@ -223,6 +216,7 @@ func (d *Daemon) serve(sigCh chan os.Signal, cfgCh chan struct{}) exitReason { } return } + d.recordEvent(ev.Letters) d.evaluate() }, runStop) }() @@ -267,16 +261,20 @@ func (d *Daemon) compatLoop(stop <-chan struct{}) { // evaluate 执行一次完整判定;满足条件时执行亮度提升。 func (d *Daemon) evaluate() { + defer d.flushState() + // 服务暂停 / 守护进程挂起:静默跳过(与旧脚本一致) - if fileExists(d.paths.StopFlag) || fileExists(d.paths.PauseFlag) { + if api.FileExists(d.paths.StopFlag) || api.FileExists(d.paths.PauseFlag) { + d.setStatePaused(api.FileExists(d.paths.StopFlag)) return } + d.setStatePaused(false) cfg := d.currentConfig() if cfg.UIMaxBri <= 0 || cfg.MaxBri <= 0 { return // 未校准,等价于旧脚本的 `now >= 0 && now < 0` } - if !fileExists(cfg.NowBriFile) { + if !api.FileExists(cfg.NowBriFile) { return // 节点缺失由外层循环负责记录与重试,这里静默 } @@ -284,9 +282,13 @@ func (d *Daemon) evaluate() { d.log().Info(fmt.Sprintf("处于休眠时段 (%s),跳过提升", cfg.SleepTime)) return } - if cfg.AutoBriSleep == 1 && d.deps.AutoBrightness.Enabled() { - d.log().Info("自动亮度已启用,跳过提升") - return + if cfg.AutoBriSleep == 1 { + autoBri := d.deps.AutoBrightness.Enabled() + d.setStateAutoBrightness(autoBri) + if autoBri { + d.log().Info("自动亮度已启用,跳过提升") + return + } } if len(cfg.BlacklistApps) > 0 { focus := d.deps.Focus.CurrentFocus() @@ -311,6 +313,7 @@ func (d *Daemon) evaluateHdr(cfg config.Config) bool { } if ok { d.ratioCache, d.haveRatioCache = ratio, true + d.setStateRatio(ratio) } decision := d.hdr.Evaluate(ratio, ok, cfg.HdrEnterRatio, cfg.HdrExitRatio) @@ -322,6 +325,7 @@ func (d *Daemon) evaluateHdr(cfg config.Config) bool { case decision.Skip: d.log().Info("HDR 休眠中,跳过提升") } + d.setStateHdrSleep(d.hdr.InSleep()) return !decision.Skip } @@ -337,6 +341,7 @@ func (d *Daemon) boost(cfg config.Config) { d.log().Error("读取亮度节点失败: " + err.Error()) return } + d.setStateBrightness(now) if policy.ShouldBoost(now, cfg.UIMaxBri, cfg.MaxBri) { d.log().Info(fmt.Sprintf("触发提升: 当前亮度 %d ≥ 阈值 %d,目标 %d", now, cfg.UIMaxBri, cfg.MaxBri)) if err := d.ramp(cfg, now); err != nil { @@ -357,11 +362,15 @@ func (d *Daemon) boost(cfg config.Config) { // ramp 执行渐变写入,期间持操作锁。 func (d *Daemon) ramp(cfg config.Config, start int) error { d.log().Info(fmt.Sprintf("开始渐变调整: %d → %d (%d 步)", start, cfg.MaxBri, cfg.StepsNum)) - if err := d.writeOplock(); err != nil { + if err := api.WriteOplock(d.paths.Oplock, api.KindRamp); err != nil { d.log().Warn("写入操作锁失败: " + err.Error()) } - defer d.removeOplock() - return brightness.Ramp(cfg.NowBriFile, start, cfg.MaxBri, cfg.StepsNum, d.deps.StepDelay, nil) + defer api.RemoveOplock(d.paths.Oplock) + + err := brightness.Ramp(cfg.NowBriFile, start, cfg.MaxBri, cfg.StepsNum, d.deps.StepDelay, nil) + d.setStateAction(api.KindRamp, start, cfg.MaxBri) + d.setStateBrightness(cfg.MaxBri) + return err } // pollConfig 定期比对 config.json 的 mtime/大小,变更时通知主循环。 @@ -459,23 +468,73 @@ func (d *Daemon) writePID() error { return os.WriteFile(d.paths.PIDFile, []byte(strconv.Itoa(os.Getpid())), 0o644) } -func (d *Daemon) writeOplock() error { - if err := os.MkdirAll(d.paths.PIDDir, 0o755); err != nil { - return err - } - return os.WriteFile(d.paths.Oplock, []byte(strconv.Itoa(os.Getpid())), 0o644) -} - -func (d *Daemon) removeOplock() { - _ = os.Remove(d.paths.Oplock) -} - func (d *Daemon) cleanup() { _ = os.Remove(d.paths.PIDFile) _ = os.Remove(d.paths.Oplock) + _ = os.Remove(d.paths.StateFile) } -func fileExists(path string) bool { - info, err := os.Stat(path) - return err == nil && !info.IsDir() +// ── 运行状态维护(供 WebUI 的 status 子命令读取)──────────────────────────── + +func (d *Daemon) updateState(fn func(s *api.DaemonState)) { + d.stateMu.Lock() + defer d.stateMu.Unlock() + fn(&d.state) +} + +func (d *Daemon) flushState() { + d.stateMu.Lock() + snapshot := d.state + d.stateMu.Unlock() + if err := api.WriteState(d.paths.StateFile, snapshot); err != nil { + d.log().Warn("写入运行状态失败: " + err.Error()) + } +} + +func (d *Daemon) recordEvent(letters string) { + now := time.Now().Unix() + d.updateState(func(s *api.DaemonState) { + s.LastEvent = &api.EventInfo{Letters: letters, At: now} + }) +} + +func (d *Daemon) setStateMode(mode string) { + d.updateState(func(s *api.DaemonState) { s.Mode = mode }) + d.flushState() +} + +func (d *Daemon) setStatePaused(paused bool) { + d.updateState(func(s *api.DaemonState) { s.Paused = paused }) +} + +func (d *Daemon) setStateRatio(ratio float64) { + now := time.Now().Unix() + d.updateState(func(s *api.DaemonState) { + s.Ratio = &api.RatioInfo{Value: ratio, At: now} + }) +} + +func (d *Daemon) setStateAutoBrightness(on bool) { + now := time.Now().Unix() + d.updateState(func(s *api.DaemonState) { + s.AutoBrightness = &api.BoolInfo{Value: on, At: now} + }) +} + +func (d *Daemon) setStateHdrSleep(asleep bool) { + d.updateState(func(s *api.DaemonState) { s.HdrSleep = asleep }) +} + +func (d *Daemon) setStateBrightness(value int) { + now := time.Now().Unix() + d.updateState(func(s *api.DaemonState) { + s.Brightness = &api.IntInfo{Value: value, At: now} + }) +} + +func (d *Daemon) setStateAction(kind string, from, to int) { + now := time.Now().Unix() + d.updateState(func(s *api.DaemonState) { + s.LastAction = &api.ActionInfo{Kind: kind, From: from, To: to, At: now} + }) } diff --git a/go/internal/daemon/daemon_test.go b/go/internal/daemon/daemon_test.go index 987768e..296de24 100644 --- a/go/internal/daemon/daemon_test.go +++ b/go/internal/daemon/daemon_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/YuleBest/LuminPro/go/internal/api" "github.com/YuleBest/LuminPro/go/internal/config" "github.com/YuleBest/LuminPro/go/internal/logging" "github.com/YuleBest/LuminPro/go/internal/system" @@ -298,21 +299,21 @@ func TestBoostRejectsMissingNode(t *testing.T) { func TestReadDaemonPID(t *testing.T) { dir := t.TempDir() - pidFile := filepath.Join(dir, "inotifyd.pid") + pidFile := filepath.Join(dir, "daemon.pid") - if _, alive := readDaemonPID(pidFile); alive { + if _, alive := api.DaemonPID(pidFile); alive { t.Fatal("文件不存在应视为未运行") } _ = os.WriteFile(pidFile, []byte("notanumber"), 0o644) - if _, alive := readDaemonPID(pidFile); alive { + if _, alive := api.DaemonPID(pidFile); alive { t.Fatal("非法内容应视为未运行") } _ = os.WriteFile(pidFile, []byte("999999"), 0o644) - if _, alive := readDaemonPID(pidFile); alive { + if _, alive := api.DaemonPID(pidFile); alive { t.Fatal("不存在的 PID 应视为未运行") } _ = os.WriteFile(pidFile, []byte(strconv.Itoa(os.Getpid())), 0o644) - if pid, alive := readDaemonPID(pidFile); !alive || pid != os.Getpid() { + if pid, alive := api.DaemonPID(pidFile); !alive || pid != os.Getpid() { t.Fatal("当前进程 PID 应视为存活") } } diff --git a/go/internal/daemon/ops.go b/go/internal/daemon/ops.go index 98a47e7..fde3b74 100644 --- a/go/internal/daemon/ops.go +++ b/go/internal/daemon/ops.go @@ -10,6 +10,7 @@ import ( "syscall" "time" + "github.com/YuleBest/LuminPro/go/internal/api" "github.com/YuleBest/LuminPro/go/internal/brightness" "github.com/YuleBest/LuminPro/go/internal/config" "github.com/YuleBest/LuminPro/go/internal/logging" @@ -21,7 +22,7 @@ func Boost(paths Paths, log *logging.Logger) error { if err != nil { return err } - if !fileExists(cfg.NowBriFile) { + if !api.FileExists(cfg.NowBriFile) { return fmt.Errorf("亮度节点不存在: %s", cfg.NowBriFile) } @@ -57,10 +58,10 @@ func Boost(paths Paths, log *logging.Logger) error { // writeWithOplock 在持操作锁的前提下写一次亮度节点。 func writeWithOplock(paths Paths, log *logging.Logger, node string, value int) { _ = os.MkdirAll(paths.PIDDir, 0o755) - if err := os.WriteFile(paths.Oplock, []byte(strconv.Itoa(os.Getpid())), 0o644); err != nil && log != nil { + if err := api.WriteOplock(paths.Oplock, api.KindBoost); err != nil && log != nil { log.Warn("写入操作锁失败: " + err.Error()) } - defer func() { _ = os.Remove(paths.Oplock) }() + defer api.RemoveOplock(paths.Oplock) if err := brightness.WriteInt(node, value); err != nil && log != nil { log.Error("写入亮度节点失败: " + err.Error()) } @@ -73,12 +74,12 @@ func Restart(paths Paths, selfPath string, log *logging.Logger) error { return err } // 整个重启窗口持操作锁,WebUI 会据此暂停刷新 - if err := os.WriteFile(paths.Oplock, []byte(strconv.Itoa(os.Getpid())), 0o644); err != nil { + if err := api.WriteOplock(paths.Oplock, api.KindRestart); err != nil { return err } - defer func() { _ = os.Remove(paths.Oplock) }() + defer api.RemoveOplock(paths.Oplock) - if pid, alive := readDaemonPID(paths.PIDFile); alive { + if pid, alive := api.DaemonPID(paths.PIDFile); alive { start := time.Now() if err := syscall.Kill(pid, syscall.SIGHUP); err != nil { return fmt.Errorf("通知守护进程失败: %w", err) @@ -92,7 +93,7 @@ func Restart(paths Paths, selfPath string, log *logging.Logger) error { if err != nil { return err } - if !fileExists(cfg.NowBriFile) { + if !api.FileExists(cfg.NowBriFile) { return fmt.Errorf("亮度节点不存在: %s,无法启动服务,请先在配置页填写正确路径", cfg.NowBriFile) } @@ -105,22 +106,6 @@ func Restart(paths Paths, selfPath string, log *logging.Logger) error { return cmd.Process.Release() } -// readDaemonPID 读取 PID 文件并确认进程存活(/proc 检测,等价于旧脚本的 [ -d /proc/$pid ])。 -func readDaemonPID(pidFile string) (int, bool) { - data, err := os.ReadFile(pidFile) - if err != nil { - return 0, false - } - pid, err := strconv.Atoi(strings.TrimSpace(string(data))) - if err != nil || pid <= 0 { - return 0, false - } - if _, err := os.Stat(fmt.Sprintf("/proc/%d", pid)); err != nil { - return 0, false - } - return pid, true -} - // waitForPIDRewrite 等待 PID 文件在 start 之后被重写。 func waitForPIDRewrite(pidFile string, start time.Time, timeout time.Duration) bool { deadline := time.Now().Add(timeout) diff --git a/service.sh b/service.sh index 85c0930..2eb5672 100755 --- a/service.sh +++ b/service.sh @@ -26,7 +26,7 @@ _log() { sleep 30 # 清理上次遗留的标记文件 -rm -f "$MODDIR/pid/"*.flag "$MODDIR/pid/"*.pause "$MODDIR/pid/"*.lock "$MODDIR/pid/oplock" "$MODDIR/pid/.hdr_ratio_cache" +rm -f "$MODDIR/pid/"*.flag "$MODDIR/pid/"*.pause "$MODDIR/pid/"*.lock "$MODDIR/pid/oplock" "$MODDIR/pid/state.json" "$MODDIR/pid/.hdr_ratio_cache" _log "LuminPro 服务启动" "INFO" From 90928d3aeb3368309164d35b93d1524a26587b66 Mon Sep 17 00:00:00 2001 From: Yule Date: Thu, 10 Sep 2026 09:29:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor(webui)!:=20=E5=85=A8=E9=87=8F?= =?UTF-8?q?=E9=87=8D=E5=86=99=E4=B8=BA=20Material=20Design=203=EF=BC=88@ma?= =?UTF-8?q?terial/web=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 组件层改为 Material Web Components:按钮/输入/开关/滑条/复选/下拉/对话框/ 菜单/导航栏/过滤芯片,移除 shadcn 风格组件与 Tailwind 全家桶 - 新增完整 MD3 token 体系(颜色全角色、字阶、形状、动效、状态层), 颜色沿用既有 Google Blue;字体保持 Geist 不变 - 壳层重构:M3 固定顶栏(滚动加容器色)+ 标准导航栏(去掉拖拽手势)、 toast 改为 M3 snackbar、原生 confirm/prompt 改为 md-dialog - 数据层改走 Go JSON API(status/oplock/brightness/config/log/focus), 一次调用取代多条 shell 命令;命令参数统一 shellQuote,不再拼接未校验输入 - 懒加载 markdown-it 与拼音库;删除 apps.js 等死代码 - 体积:JS 454KB(gzip 115KB) + CSS 30KB(原 318KB+58KB),懒加载分块另计 --- go/cmd/luminpro/main.go | 17 +- package.json | 8 +- pnpm-lock.yaml | 322 ++-------- webui/components.json | 20 - webui/src/App.vue | 311 ++++----- webui/src/about.css | 330 ---------- webui/src/api/devMock.js | 80 +++ webui/src/api/ksu.js | 51 ++ webui/src/api/luminpro.js | 85 +++ webui/src/apps.css | 562 ----------------- webui/src/apps.js | 734 ---------------------- webui/src/components.css | 663 -------------------- webui/src/components/ActionMenu.vue | 40 ++ webui/src/components/AppBottomNav.vue | 31 + webui/src/components/AppSwitch.vue | 28 + webui/src/components/AppTextField.vue | 36 ++ webui/src/components/AppTopBar.vue | 59 ++ webui/src/components/BottomNav.vue | 143 ----- webui/src/components/ConfirmDialog.vue | 54 ++ webui/src/components/OpLockBanner.vue | 17 + webui/src/components/PromptDialog.vue | 68 ++ webui/src/components/SnackbarHost.vue | 15 + webui/src/components/ui/Badge.vue | 32 - webui/src/components/ui/Button.vue | 53 -- webui/src/components/ui/Card.vue | 17 - webui/src/components/ui/Input.vue | 38 -- webui/src/components/ui/Label.vue | 22 - webui/src/components/ui/Separator.vue | 21 - webui/src/components/ui/Switch.vue | 43 -- webui/src/components/ui/Textarea.vue | 30 - webui/src/composables/useApps.js | 133 ++-- webui/src/composables/useConfig.js | 392 ++++-------- webui/src/composables/useLog.js | 90 +-- webui/src/composables/useOplock.js | 23 - webui/src/composables/useSnackbar.js | 70 +++ webui/src/composables/useStatus.js | 202 +++--- webui/src/header.css | 220 ------- webui/src/index.css | 175 ------ webui/src/lib/utils.js | 6 - webui/src/log.css | 265 -------- webui/src/main.js | 14 +- webui/src/mwc.js | 31 + webui/src/style.css | 131 ---- webui/src/theme/app.css | 274 ++++++++ webui/src/theme/base.css | 214 +++++++ webui/src/theme/components.css | 160 +++++ webui/src/theme/tokens.css | 286 +++++++++ webui/src/utils.js | 113 ---- webui/src/views/AboutView.vue | 312 ++++++--- webui/src/views/AppsView.vue | 836 ++++++++++++++----------- webui/src/views/ConfigView.vue | 749 +++++++++++----------- webui/src/views/LogView.vue | 187 +++--- webui/src/views/StatusView.vue | 216 ++++--- webui/vite.config.js | 12 +- 54 files changed, 3400 insertions(+), 5641 deletions(-) delete mode 100644 webui/components.json delete mode 100644 webui/src/about.css create mode 100644 webui/src/api/devMock.js create mode 100644 webui/src/api/ksu.js create mode 100644 webui/src/api/luminpro.js delete mode 100644 webui/src/apps.css delete mode 100644 webui/src/apps.js delete mode 100644 webui/src/components.css create mode 100644 webui/src/components/ActionMenu.vue create mode 100644 webui/src/components/AppBottomNav.vue create mode 100644 webui/src/components/AppSwitch.vue create mode 100644 webui/src/components/AppTextField.vue create mode 100644 webui/src/components/AppTopBar.vue delete mode 100644 webui/src/components/BottomNav.vue create mode 100644 webui/src/components/ConfirmDialog.vue create mode 100644 webui/src/components/OpLockBanner.vue create mode 100644 webui/src/components/PromptDialog.vue create mode 100644 webui/src/components/SnackbarHost.vue delete mode 100644 webui/src/components/ui/Badge.vue delete mode 100644 webui/src/components/ui/Button.vue delete mode 100644 webui/src/components/ui/Card.vue delete mode 100644 webui/src/components/ui/Input.vue delete mode 100644 webui/src/components/ui/Label.vue delete mode 100644 webui/src/components/ui/Separator.vue delete mode 100644 webui/src/components/ui/Switch.vue delete mode 100644 webui/src/components/ui/Textarea.vue delete mode 100644 webui/src/composables/useOplock.js create mode 100644 webui/src/composables/useSnackbar.js delete mode 100644 webui/src/header.css delete mode 100644 webui/src/index.css delete mode 100644 webui/src/lib/utils.js delete mode 100644 webui/src/log.css create mode 100644 webui/src/mwc.js delete mode 100644 webui/src/style.css create mode 100644 webui/src/theme/app.css create mode 100644 webui/src/theme/base.css create mode 100644 webui/src/theme/components.css create mode 100644 webui/src/theme/tokens.css delete mode 100644 webui/src/utils.js diff --git a/go/cmd/luminpro/main.go b/go/cmd/luminpro/main.go index e0e67aa..de54a6f 100644 --- a/go/cmd/luminpro/main.go +++ b/go/cmd/luminpro/main.go @@ -63,6 +63,9 @@ func run(args []string) error { return runStatus(paths, args[1:]) case "oplock": return emitJSON(api.ReadOplock(paths.Oplock)) + case "focus": + focus := system.Focus{Runner: system.ExecRunner{}} + return emitJSON(map[string]any{"focus": focus.CurrentFocus()}) case "brightness": return runBrightness(paths, args[1:]) case "config": @@ -86,6 +89,7 @@ func usage() error { luminpro status [--no-display] 聚合状态(JSON) luminpro oplock 操作锁状态(JSON) + luminpro focus 当前前台 Activity(JSON) luminpro brightness set <值> 设置亮度(JSON) luminpro config <操作> 配置管理(JSON) @@ -245,9 +249,16 @@ func runConfig(paths api.Paths, args []string) error { _, err = os.Stdout.Write(append(data, '\n')) return err case "patch": - input, err := io.ReadAll(os.Stdin) - if err != nil { - return err + // 支持两种传参:命令行参数(WebUI 用,exec 无 stdin)或标准输入(脚本用) + var input []byte + var err error + if len(args) >= 2 { + input = []byte(args[1]) + } else { + input, err = io.ReadAll(os.Stdin) + if err != nil { + return err + } } var patch map[string]json.RawMessage if err := json.Unmarshal(input, &patch); err != nil { diff --git a/package.json b/package.json index 494dd0f..1b5a488 100644 --- a/package.json +++ b/package.json @@ -14,25 +14,19 @@ "fmt:check": "oxfmt webui/ --check" }, "devDependencies": { - "@tailwindcss/vite": "^4.2.2", "archiver": "^7.0.1", "kernelsu": "^3.0.2", "oxfmt": "^0.44.0", "oxlint": "^1.59.0", - "tailwindcss": "^4.2.2", - "tw-animate-css": "^1.4.0", "vite": "^8.0.3" }, "dependencies": { + "@material/web": "^2.5.0", "@tanstack/vue-virtual": "^3.13.37", "@vitejs/plugin-vue": "^6.0.5", - "class-variance-authority": "^0.7.1", - "clsx": "^2.1.1", - "lucide": "^1.7.0", "lucide-vue-next": "^1.0.0", "markdown-it": "^14.1.1", "pinyin-match": "^1.2.10", - "tailwind-merge": "^3.5.0", "vue": "^3.5.32" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0694a99..fa728db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,21 +8,15 @@ importers: .: dependencies: + '@material/web': + specifier: ^2.5.0 + version: 2.5.0 '@tanstack/vue-virtual': specifier: ^3.13.37 version: 3.13.37(vue@3.5.32) '@vitejs/plugin-vue': specifier: ^6.0.5 version: 6.0.5(vite@8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1))(vue@3.5.32) - class-variance-authority: - specifier: ^0.7.1 - version: 0.7.1 - clsx: - specifier: ^2.1.1 - version: 2.1.1 - lucide: - specifier: ^1.7.0 - version: 1.7.0 lucide-vue-next: specifier: ^1.0.0 version: 1.0.0(vue@3.5.32) @@ -32,16 +26,10 @@ importers: pinyin-match: specifier: ^1.2.10 version: 1.2.10 - tailwind-merge: - specifier: ^3.5.0 - version: 3.5.0 vue: specifier: ^3.5.32 version: 3.5.32 devDependencies: - '@tailwindcss/vite': - specifier: ^4.2.2 - version: 4.2.2(vite@8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1)) archiver: specifier: ^7.0.1 version: 7.0.1 @@ -54,12 +42,6 @@ importers: oxlint: specifier: ^1.59.0 version: 1.59.0 - tailwindcss: - specifier: ^4.2.2 - version: 4.2.2 - tw-animate-css: - specifier: ^1.4.0 - version: 1.4.0 vite: specifier: ^8.0.3 version: 8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1) @@ -96,21 +78,20 @@ packages: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} - '@jridgewell/gen-mapping@0.3.13': - resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==} - - '@jridgewell/remapping@2.3.5': - resolution: {integrity: sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==} - - '@jridgewell/resolve-uri@3.1.2': - resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} - engines: {node: '>=6.0.0'} - '@jridgewell/sourcemap-codec@1.5.5': resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==} - '@jridgewell/trace-mapping@0.3.31': - resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} + '@lit-labs/ssr-dom-shim@1.6.0': + resolution: {integrity: sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ==} + + '@lit/context@1.1.6': + resolution: {integrity: sha512-M26qDE6UkQbZA2mQ3RjJ3Gzd8TxP+/0obMgE5HfkfLhEEyYE3Bui4A5XHiGPjy0MUGAyxB3QgVuw2ciS0kHn6A==} + + '@lit/reactive-element@2.1.2': + resolution: {integrity: sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==} + + '@material/web@2.5.0': + resolution: {integrity: sha512-x2Uovyq8E/Zc1xHXd9s1eBMXF5pMHVAt70pISKd0fL3Ajj4L6zQaQUY/awcfR2RDAMKXC7i4+vr0arv1YaOR/g==} '@napi-rs/wasm-runtime@1.1.2': resolution: {integrity: sha512-sNXv5oLJ7ob93xkZ1XnxisYhGYXfaG9f65/ZgYuAu3qt7b3NadcOEhLvx28hv31PgX8SZJRYrAIPQilQmFpLVw==} @@ -470,100 +451,6 @@ packages: '@rolldown/pluginutils@1.0.0-rc.2': resolution: {integrity: sha512-izyXV/v+cHiRfozX62W9htOAvwMo4/bXKDrQ+vom1L1qRuexPock/7VZDAhnpHCLNejd3NJ6hiab+tO0D44Rgw==} - '@tailwindcss/node@4.2.2': - resolution: {integrity: sha512-pXS+wJ2gZpVXqFaUEjojq7jzMpTGf8rU6ipJz5ovJV6PUGmlJ+jvIwGrzdHdQ80Sg+wmQxUFuoW1UAAwHNEdFA==} - - '@tailwindcss/oxide-android-arm64@4.2.2': - resolution: {integrity: sha512-dXGR1n+P3B6748jZO/SvHZq7qBOqqzQ+yFrXpoOWWALWndF9MoSKAT3Q0fYgAzYzGhxNYOoysRvYlpixRBBoDg==} - engines: {node: '>= 20'} - cpu: [arm64] - os: [android] - - '@tailwindcss/oxide-darwin-arm64@4.2.2': - resolution: {integrity: sha512-iq9Qjr6knfMpZHj55/37ouZeykwbDqF21gPFtfnhCCKGDcPI/21FKC9XdMO/XyBM7qKORx6UIhGgg6jLl7BZlg==} - engines: {node: '>= 20'} - cpu: [arm64] - os: [darwin] - - '@tailwindcss/oxide-darwin-x64@4.2.2': - resolution: {integrity: sha512-BlR+2c3nzc8f2G639LpL89YY4bdcIdUmiOOkv2GQv4/4M0vJlpXEa0JXNHhCHU7VWOKWT/CjqHdTP8aUuDJkuw==} - engines: {node: '>= 20'} - cpu: [x64] - os: [darwin] - - '@tailwindcss/oxide-freebsd-x64@4.2.2': - resolution: {integrity: sha512-YUqUgrGMSu2CDO82hzlQ5qSb5xmx3RUrke/QgnoEx7KvmRJHQuZHZmZTLSuuHwFf0DJPybFMXMYf+WJdxHy/nQ==} - engines: {node: '>= 20'} - cpu: [x64] - os: [freebsd] - - '@tailwindcss/oxide-linux-arm-gnueabihf@4.2.2': - resolution: {integrity: sha512-FPdhvsW6g06T9BWT0qTwiVZYE2WIFo2dY5aCSpjG/S/u1tby+wXoslXS0kl3/KXnULlLr1E3NPRRw0g7t2kgaQ==} - engines: {node: '>= 20'} - cpu: [arm] - os: [linux] - - '@tailwindcss/oxide-linux-arm64-gnu@4.2.2': - resolution: {integrity: sha512-4og1V+ftEPXGttOO7eCmW7VICmzzJWgMx+QXAJRAhjrSjumCwWqMfkDrNu1LXEQzNAwz28NCUpucgQPrR4S2yw==} - engines: {node: '>= 20'} - cpu: [arm64] - os: [linux] - libc: [glibc] - - '@tailwindcss/oxide-linux-arm64-musl@4.2.2': - resolution: {integrity: sha512-oCfG/mS+/+XRlwNjnsNLVwnMWYH7tn/kYPsNPh+JSOMlnt93mYNCKHYzylRhI51X+TbR+ufNhhKKzm6QkqX8ag==} - engines: {node: '>= 20'} - cpu: [arm64] - os: [linux] - libc: [musl] - - '@tailwindcss/oxide-linux-x64-gnu@4.2.2': - resolution: {integrity: sha512-rTAGAkDgqbXHNp/xW0iugLVmX62wOp2PoE39BTCGKjv3Iocf6AFbRP/wZT/kuCxC9QBh9Pu8XPkv/zCZB2mcMg==} - engines: {node: '>= 20'} - cpu: [x64] - os: [linux] - libc: [glibc] - - '@tailwindcss/oxide-linux-x64-musl@4.2.2': - resolution: {integrity: sha512-XW3t3qwbIwiSyRCggeO2zxe3KWaEbM0/kW9e8+0XpBgyKU4ATYzcVSMKteZJ1iukJ3HgHBjbg9P5YPRCVUxlnQ==} - engines: {node: '>= 20'} - cpu: [x64] - os: [linux] - libc: [musl] - - '@tailwindcss/oxide-wasm32-wasi@4.2.2': - resolution: {integrity: sha512-eKSztKsmEsn1O5lJ4ZAfyn41NfG7vzCg496YiGtMDV86jz1q/irhms5O0VrY6ZwTUkFy/EKG3RfWgxSI3VbZ8Q==} - engines: {node: '>=14.0.0'} - cpu: [wasm32] - bundledDependencies: - - '@napi-rs/wasm-runtime' - - '@emnapi/core' - - '@emnapi/runtime' - - '@tybys/wasm-util' - - '@emnapi/wasi-threads' - - tslib - - '@tailwindcss/oxide-win32-arm64-msvc@4.2.2': - resolution: {integrity: sha512-qPmaQM4iKu5mxpsrWZMOZRgZv1tOZpUm+zdhhQP0VhJfyGGO3aUKdbh3gDZc/dPLQwW4eSqWGrrcWNBZWUWaXQ==} - engines: {node: '>= 20'} - cpu: [arm64] - os: [win32] - - '@tailwindcss/oxide-win32-x64-msvc@4.2.2': - resolution: {integrity: sha512-1T/37VvI7WyH66b+vqHj/cLwnCxt7Qt3WFu5Q8hk65aOvlwAhs7rAp1VkulBJw/N4tMirXjVnylTR72uI0HGcA==} - engines: {node: '>= 20'} - cpu: [x64] - os: [win32] - - '@tailwindcss/oxide@4.2.2': - resolution: {integrity: sha512-qEUA07+E5kehxYp9BVMpq9E8vnJuBHfJEC0vPC5e7iL/hw7HR61aDKoVoKzrG+QKp56vhNZe4qwkRmMC0zDLvg==} - engines: {node: '>= 20'} - - '@tailwindcss/vite@4.2.2': - resolution: {integrity: sha512-mEiF5HO1QqCLXoNEfXVA1Tzo+cYsrqV7w9Juj2wdUFyW07JRenqMG225MvPwr3ZD9N1bFQj46X7r33iHxLUW0w==} - peerDependencies: - vite: ^5.2.0 || ^6 || ^7 || ^8 - '@tanstack/virtual-core@3.17.9': resolution: {integrity: sha512-M8Bzy7CCMvUjRiuoHVH9mRjyUVczRs8v8RcUEphLFGc445ZP4KQ15Y1sLqhQqJi/HgGJrxfCHnEnIX0x9mVrBg==} @@ -575,6 +462,9 @@ packages: '@tybys/wasm-util@0.10.1': resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==} + '@types/trusted-types@2.0.7': + resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==} + '@vitejs/plugin-vue@6.0.5': resolution: {integrity: sha512-bL3AxKuQySfk1iGcBsQnoRVexTPJq0Z/ixFVM8OhVJAP6ZXXXLtM7NFKWhLl30Kg7uTBqIaPXbh+nuQCuBDedg==} engines: {node: ^20.19.0 || >=22.12.0} @@ -710,13 +600,6 @@ packages: buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - class-variance-authority@0.7.1: - resolution: {integrity: sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==} - - clsx@2.1.1: - resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==} - engines: {node: '>=6'} - color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} @@ -760,10 +643,6 @@ packages: emoji-regex@9.2.2: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} - enhanced-resolve@5.20.1: - resolution: {integrity: sha512-Qohcme7V1inbAfvjItgw0EaxVX5q2rdVEZHRBrEQdRZTssLDGsL8Lwrznl8oQ/6kuTJONLaDcGjkNP247XEhcA==} - engines: {node: '>=10.13.0'} - entities@4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} @@ -925,6 +804,15 @@ packages: linkify-it@5.0.0: resolution: {integrity: sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==} + lit-element@4.2.2: + resolution: {integrity: sha512-aFKhNToWxoyhkNDmWZwEva2SlQia+jfG0fjIWV//YeTaWrVnOxD89dPKfigCUspXFmjzOEUQpOkejH5Ly6sG0w==} + + lit-html@3.3.3: + resolution: {integrity: sha512-el8M6jK2o3RXBnrSHX3ZKrsN8zEV63pSExTO1wYJz7QndGYZ8353e2a5PPX+qHe2aGayfnchQmkAojaWAREOIA==} + + lit@3.3.3: + resolution: {integrity: sha512-fycuvZg/hkpozL00lm1pEJH5nN/lr9ZXd6mJI2HSN4+Bzc+LDNdEApJ6HFbPkdFNHLvOplIIuJvxkS4XUxqirw==} + lodash@4.18.1: resolution: {integrity: sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==} @@ -937,9 +825,6 @@ packages: peerDependencies: vue: '>=3.0.1' - lucide@1.7.0: - resolution: {integrity: sha512-aYNogbuIxea3a8offpKjdMGf2FsUk9GECFh0B4iJgXlJOX41+7/ncvLVluKki8477SoybEdyGGf+qGYLBDiEsA==} - magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} @@ -1084,16 +969,6 @@ packages: resolution: {integrity: sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==} engines: {node: '>=12'} - tailwind-merge@3.5.0: - resolution: {integrity: sha512-I8K9wewnVDkL1NTGoqWmVEIlUcB9gFriAEkXkfCjX5ib8ezGxtR3xD7iZIxrfArjEsH7F1CHD4RFUtxefdqV/A==} - - tailwindcss@4.2.2: - resolution: {integrity: sha512-KWBIxs1Xb6NoLdMVqhbhgwZf2PGBpPEiwOqgI4pFIYbNTfBXiKYyWoTsXgBQ9WFg/OlhnvHaY+AEpW7wSmFo2Q==} - - tapable@2.3.2: - resolution: {integrity: sha512-1MOpMXuhGzGL5TTCZFItxCc0AARf1EZFQkGqMm7ERKj8+Hgr5oLvJOVFcC+lRmR8hCe2S3jC4T5D7Vg/d7/fhA==} - engines: {node: '>=6'} - tar-stream@3.1.8: resolution: {integrity: sha512-U6QpVRyCGHva435KoNWy9PRoi2IFYCgtEhq9nmrPPpbRacPs9IH4aJ3gbrFC8dPcXvdSZ4XXfXT5Fshbp2MtlQ==} @@ -1114,9 +989,6 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tw-animate-css@1.4.0: - resolution: {integrity: sha512-7bziOlRqH0hJx80h/3mbicLW7o8qLsH5+RaLR2t+OHM3D0JlWGODQKQ4cxbK7WlvmUxpcj6Kgu6EKqjrGFe3QQ==} - uc.micro@2.1.0: resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} @@ -1231,24 +1103,23 @@ snapshots: wrap-ansi: 8.1.0 wrap-ansi-cjs: wrap-ansi@7.0.0 - '@jridgewell/gen-mapping@0.3.13': - dependencies: - '@jridgewell/sourcemap-codec': 1.5.5 - '@jridgewell/trace-mapping': 0.3.31 - - '@jridgewell/remapping@2.3.5': - dependencies: - '@jridgewell/gen-mapping': 0.3.13 - '@jridgewell/trace-mapping': 0.3.31 - - '@jridgewell/resolve-uri@3.1.2': {} - '@jridgewell/sourcemap-codec@1.5.5': {} - '@jridgewell/trace-mapping@0.3.31': + '@lit-labs/ssr-dom-shim@1.6.0': {} + + '@lit/context@1.1.6': dependencies: - '@jridgewell/resolve-uri': 3.1.2 - '@jridgewell/sourcemap-codec': 1.5.5 + '@lit/reactive-element': 2.1.2 + + '@lit/reactive-element@2.1.2': + dependencies: + '@lit-labs/ssr-dom-shim': 1.6.0 + + '@material/web@2.5.0': + dependencies: + '@lit/context': 1.1.6 + lit: 3.3.3 + tslib: 2.8.1 '@napi-rs/wasm-runtime@1.1.2(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)': dependencies: @@ -1430,74 +1301,6 @@ snapshots: '@rolldown/pluginutils@1.0.0-rc.2': {} - '@tailwindcss/node@4.2.2': - dependencies: - '@jridgewell/remapping': 2.3.5 - enhanced-resolve: 5.20.1 - jiti: 2.6.1 - lightningcss: 1.32.0 - magic-string: 0.30.21 - source-map-js: 1.2.1 - tailwindcss: 4.2.2 - - '@tailwindcss/oxide-android-arm64@4.2.2': - optional: true - - '@tailwindcss/oxide-darwin-arm64@4.2.2': - optional: true - - '@tailwindcss/oxide-darwin-x64@4.2.2': - optional: true - - '@tailwindcss/oxide-freebsd-x64@4.2.2': - optional: true - - '@tailwindcss/oxide-linux-arm-gnueabihf@4.2.2': - optional: true - - '@tailwindcss/oxide-linux-arm64-gnu@4.2.2': - optional: true - - '@tailwindcss/oxide-linux-arm64-musl@4.2.2': - optional: true - - '@tailwindcss/oxide-linux-x64-gnu@4.2.2': - optional: true - - '@tailwindcss/oxide-linux-x64-musl@4.2.2': - optional: true - - '@tailwindcss/oxide-wasm32-wasi@4.2.2': - optional: true - - '@tailwindcss/oxide-win32-arm64-msvc@4.2.2': - optional: true - - '@tailwindcss/oxide-win32-x64-msvc@4.2.2': - optional: true - - '@tailwindcss/oxide@4.2.2': - optionalDependencies: - '@tailwindcss/oxide-android-arm64': 4.2.2 - '@tailwindcss/oxide-darwin-arm64': 4.2.2 - '@tailwindcss/oxide-darwin-x64': 4.2.2 - '@tailwindcss/oxide-freebsd-x64': 4.2.2 - '@tailwindcss/oxide-linux-arm-gnueabihf': 4.2.2 - '@tailwindcss/oxide-linux-arm64-gnu': 4.2.2 - '@tailwindcss/oxide-linux-arm64-musl': 4.2.2 - '@tailwindcss/oxide-linux-x64-gnu': 4.2.2 - '@tailwindcss/oxide-linux-x64-musl': 4.2.2 - '@tailwindcss/oxide-wasm32-wasi': 4.2.2 - '@tailwindcss/oxide-win32-arm64-msvc': 4.2.2 - '@tailwindcss/oxide-win32-x64-msvc': 4.2.2 - - '@tailwindcss/vite@4.2.2(vite@8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1))': - dependencies: - '@tailwindcss/node': 4.2.2 - '@tailwindcss/oxide': 4.2.2 - tailwindcss: 4.2.2 - vite: 8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1) - '@tanstack/virtual-core@3.17.9': {} '@tanstack/vue-virtual@3.13.37(vue@3.5.32)': @@ -1510,6 +1313,8 @@ snapshots: tslib: 2.8.1 optional: true + '@types/trusted-types@2.0.7': {} + '@vitejs/plugin-vue@6.0.5(vite@8.0.3(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(jiti@2.6.1))(vue@3.5.32)': dependencies: '@rolldown/pluginutils': 1.0.0-rc.2 @@ -1661,12 +1466,6 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 - class-variance-authority@0.7.1: - dependencies: - clsx: 2.1.1 - - clsx@2.1.1: {} - color-convert@2.0.1: dependencies: color-name: 1.1.4 @@ -1706,11 +1505,6 @@ snapshots: emoji-regex@9.2.2: {} - enhanced-resolve@5.20.1: - dependencies: - graceful-fs: 4.2.11 - tapable: 2.3.2 - entities@4.5.0: {} entities@7.0.1: {} @@ -1770,7 +1564,8 @@ snapshots: optionalDependencies: '@pkgjs/parseargs': 0.11.0 - jiti@2.6.1: {} + jiti@2.6.1: + optional: true kernelsu@3.0.2: {} @@ -1831,6 +1626,22 @@ snapshots: dependencies: uc.micro: 2.1.0 + lit-element@4.2.2: + dependencies: + '@lit-labs/ssr-dom-shim': 1.6.0 + '@lit/reactive-element': 2.1.2 + lit-html: 3.3.3 + + lit-html@3.3.3: + dependencies: + '@types/trusted-types': 2.0.7 + + lit@3.3.3: + dependencies: + '@lit/reactive-element': 2.1.2 + lit-element: 4.2.2 + lit-html: 3.3.3 + lodash@4.18.1: {} lru-cache@10.4.3: {} @@ -1839,8 +1650,6 @@ snapshots: dependencies: vue: 3.5.32 - lucide@1.7.0: {} - magic-string@0.30.21: dependencies: '@jridgewell/sourcemap-codec': 1.5.5 @@ -2040,12 +1849,6 @@ snapshots: dependencies: ansi-regex: 6.2.2 - tailwind-merge@3.5.0: {} - - tailwindcss@4.2.2: {} - - tapable@2.3.2: {} - tar-stream@3.1.8: dependencies: b4a: 1.8.0 @@ -2077,10 +1880,7 @@ snapshots: tinypool@2.1.0: {} - tslib@2.8.1: - optional: true - - tw-animate-css@1.4.0: {} + tslib@2.8.1: {} uc.micro@2.1.0: {} diff --git a/webui/components.json b/webui/components.json deleted file mode 100644 index fbaeef5..0000000 --- a/webui/components.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "https://shadcn-vue.com/schema.json", - "style": "default", - "typescript": false, - "tailwind": { - "config": "", - "css": "src/index.css", - "baseColor": "slate", - "cssVariables": true, - "prefix": "" - }, - "aliases": { - "components": "@/components", - "utils": "@/lib/utils", - "ui": "@/components/ui", - "lib": "@/lib", - "composables": "@/composables" - }, - "registries": [] -} diff --git a/webui/src/App.vue b/webui/src/App.vue index 48b9184..aa58506 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -1,12 +1,17 @@ diff --git a/webui/src/about.css b/webui/src/about.css deleted file mode 100644 index bae008a..0000000 --- a/webui/src/about.css +++ /dev/null @@ -1,330 +0,0 @@ -/* ========================================== - About View Styles - ========================================== */ -.about-hero { - display: flex; - flex-direction: column; - align-items: center; - padding: var(--spacing-l) 0 var(--spacing-m); - gap: 8px; -} -.about-logo { - width: 72px; - height: 72px; - border-radius: 20px; - background: linear-gradient( - 135deg, - var(--md-sys-color-primary-container), - var(--md-sys-color-secondary-container) - ); - display: flex; - align-items: center; - justify-content: center; - color: var(--md-sys-color-primary); - margin-bottom: 4px; -} -.about-name { - margin: 0; - font-size: 1.5rem; - font-weight: 700; - color: var(--md-sys-color-on-surface); -} -.about-desc { - margin: 0; - font-size: 0.875rem; - color: var(--md-sys-color-on-surface-variant); -} -.about-version-badge { - display: inline-block; - padding: 2px 10px; - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - border-radius: 100px; - font-size: 0.75rem; - font-weight: 600; - letter-spacing: 0.3px; -} -.about-section-title { - font-size: 0.75rem; - font-weight: 600; - color: var(--md-sys-color-primary); - text-transform: uppercase; - letter-spacing: 1px; - margin: var(--spacing-l) 0 var(--spacing-s); -} -.about-list { - display: flex; - flex-direction: column; - gap: 2px; - background-color: var(--md-sys-color-surface-container); - border-radius: var(--border-radius-m); - overflow: hidden; -} -.about-list-item { - display: flex; - align-items: center; - gap: 12px; - padding: 14px 16px; - background: transparent; - border: none; - color: var(--md-sys-color-on-surface); - font-size: 0.9375rem; - font-family: inherit; - cursor: pointer; - text-decoration: none; - transition: background-color 0.15s; - text-align: left; - width: 100%; -} -.about-list-item + .about-list-item { - border-top: 1px solid rgba(var(--md-sys-color-on-surface-rgb, 0, 0, 0), 0.06); -} -.about-list-item:active { - background-color: var(--md-sys-color-surface-container-high); -} -.about-list-icon { - color: var(--md-sys-color-primary); - flex-shrink: 0; -} -.about-list-chevron { - margin-left: auto; - color: var(--md-sys-color-on-surface-variant); - opacity: 0.5; - flex-shrink: 0; -} -.about-footer { - text-align: center; - color: var(--md-sys-color-on-surface-variant); - font-size: 0.8125rem; - margin-top: var(--spacing-l); - padding-top: var(--spacing-m); - border-top: 1px solid rgba(var(--md-sys-color-outline-variant-rgb, 142, 144, 153), 0.15); -} - -/* ========================================== - Doc Sheet (Bottom drawer) - ========================================== */ -.doc-sheet-backdrop { - position: fixed; - inset: 0; - background: rgba(0, 0, 0, 0.5); - backdrop-filter: blur(4px); - z-index: 1999; - opacity: 0; - pointer-events: none; - transition: opacity 0.3s ease; -} -.doc-sheet-backdrop.show { - opacity: 1; - pointer-events: auto; -} -.doc-sheet { - position: fixed; - left: 0; - right: 0; - bottom: 0; - max-height: 90vh; - background-color: var(--md-sys-color-surface-container-high); - border-radius: 28px 28px 0 0; - z-index: 2000; - display: flex; - flex-direction: column; - transform: translateY(100%); - transition: transform 0.35s cubic-bezier(0.19, 1, 0.22, 1); - box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3); - overflow: hidden; -} -.doc-sheet.show { - transform: translateY(0); -} -.doc-sheet-header { - display: flex; - align-items: center; - padding: 16px 16px 12px; - border-bottom: 1px solid rgba(var(--md-sys-color-on-surface-rgb, 0, 0, 0), 0.07); - gap: 12px; - flex-shrink: 0; -} -.doc-sheet-title { - font-size: 1.0625rem; - font-weight: 600; - color: var(--md-sys-color-on-surface); - flex: 1; -} -.doc-sheet-close { - display: flex; - align-items: center; - justify-content: center; - width: 32px; - height: 32px; - border-radius: 50%; - border: none; - background: transparent; - color: var(--md-sys-color-on-surface-variant); - cursor: pointer; - transition: background-color 0.15s; -} -.doc-sheet-close:active { - background-color: var(--md-sys-color-surface-container); -} -.doc-sheet-body { - flex: 1; - overflow-y: auto; - padding: 20px 20px 48px; - scrollbar-width: none; -} -.doc-sheet-body::-webkit-scrollbar { - display: none; -} -.doc-sheet-loading { - text-align: center; - padding: 48px 20px; - color: var(--md-sys-color-on-surface-variant); -} -.doc-sheet-content { - font-size: 0.9rem; - line-height: 1.75; - color: var(--md-sys-color-on-surface); - word-break: break-word; -} -.doc-sheet-content h1, -.doc-sheet-content h2 { - color: var(--md-sys-color-primary); - margin-top: 1.4em; - margin-bottom: 0.4em; -} -.doc-sheet-content h3, -.doc-sheet-content h4 { - color: var(--md-sys-color-on-primary-container); - margin-top: 1.2em; - margin-bottom: 0.3em; -} -.doc-sheet-content p { - margin: 0.6em 0; -} -.doc-sheet-content a { - color: var(--md-sys-color-primary); - text-decoration: underline; - word-break: break-all; -} -.doc-sheet-content ul, -.doc-sheet-content ol { - padding-left: 1.4em; - margin: 0.5em 0; -} -.doc-sheet-content li { - margin: 0.25em 0; -} -.doc-sheet-content code { - background-color: var(--md-sys-color-surface-container); - padding: 2px 6px; - border-radius: 4px; - font-family: 'Geist Mono', monospace; - font-size: 0.85em; -} -.doc-sheet-content pre { - background-color: var(--md-sys-color-surface-container); - border-radius: 8px; - padding: 12px 14px; - overflow-x: auto; - margin: 0.75em 0; -} -.doc-sheet-content pre code { - background: none; - padding: 0; - border-radius: 0; - font-size: 0.82em; - line-height: 1.6; -} -.doc-sheet-content blockquote { - border-left: 3px solid var(--md-sys-color-primary-container); - margin: 0.75em 0; - padding: 0.2em 0.75em; - color: var(--md-sys-color-on-surface-variant); - background-color: rgba(var(--md-sys-color-primary-rgb), 0.06); - border-radius: 0 4px 4px 0; -} -.doc-sheet-content hr { - border: none; - border-top: 1px solid var(--md-sys-color-outline-variant); - margin: 1.2em 0; -} -.doc-sheet-content table { - border-collapse: collapse; - width: 100%; - margin: 0.75em 0; - font-size: 0.85em; -} -.doc-sheet-content th, -.doc-sheet-content td { - border: 1px solid var(--md-sys-color-outline-variant); - padding: 6px 10px; - text-align: left; -} -.doc-sheet-content th { - background-color: var(--md-sys-color-surface-container); - font-weight: 600; -} - -/* ========================================== - Log Filter Tabs - ========================================== */ -.log-filter-container { - display: flex; - align-items: center; - gap: var(--spacing-s); -} -.log-filter-tabs { - display: flex; - gap: 4px; - background-color: var(--md-sys-color-surface-container); - padding: 4px; - border-radius: var(--border-radius-s); -} -.log-filter-tab { - padding: 4px 12px; - border-radius: calc(var(--border-radius-s) - 2px); - border: none; - background: transparent; - color: var(--md-sys-color-on-surface-variant); - font-size: 0.8125rem; - font-weight: 500; - font-family: inherit; - cursor: pointer; - transition: all 0.2s; -} -.log-filter-tab.active { - background-color: var(--md-sys-color-surface-container-high); - color: var(--md-sys-color-primary); - font-weight: 600; -} - -/* ========================================== - Theme Segmented Button - ========================================== */ -.theme-seg { - display: flex; - gap: 2px; - background-color: var(--md-sys-color-surface-container); - padding: 3px; - border-radius: var(--border-radius-s); - flex-shrink: 0; -} -.theme-seg-btn { - padding: 4px 12px; - border-radius: calc(var(--border-radius-s) - 2px); - border: none; - background: transparent; - color: var(--md-sys-color-on-surface-variant); - font-size: 0.8125rem; - font-weight: 500; - font-family: inherit; - cursor: pointer; - transition: all 0.18s ease; - white-space: nowrap; -} -.theme-seg-btn.active { - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - font-weight: 600; -} diff --git a/webui/src/api/devMock.js b/webui/src/api/devMock.js new file mode 100644 index 0000000..8b9c504 --- /dev/null +++ b/webui/src/api/devMock.js @@ -0,0 +1,80 @@ +/** + * 开发环境(浏览器直开、无 KernelSU bridge)下返回模拟数据, + * 便于在电脑上调试界面。真机永远不会走到这里。 + */ + +const mockStatus = (display) => ({ + module: { id: 'LuminPro', name: 'LuminPro', version: 'V2.5.0-beta.2', versionCode: 2050052, channel: 'beta' }, + daemon: { pid: 12345, running: true, state: 'S', mode: 'event', paused: false, uptimeSec: 3620 }, + brightness: { current: 1200, max: 4095, percent: 29, node: '/sys/mock/brightness', maxNode: '/sys/mock/max_brightness' }, + display: display + ? { hdrRatio: 1.02, hdrKnown: true, hdrStale: false, hdrSleep: false, autoBrightness: false } + : undefined, + sleep: { window: '2300-0700', active: false }, + oplock: { locked: false, seconds: 0 }, + config: { + uiMaxBri: 1000, + maxBri: 3500, + stepsNum: 50, + sleepTime: '2300-0700', + autoBriSleep: 1, + displayHdrSleep: 0, + hdrEnterRatio: 1.15, + hdrExitRatio: 1.05, + compatibilityMode: 0, + logLevel: 'info', + logMaxSize: 512, + debugMode: 0, + nowBriFile: '/sys/class/backlight/panel0-backlight/brightness', + maxBriFile: '/sys/class/backlight/panel0-backlight/max_brightness', + blacklistCount: 3, + }, + log: { path: '/data/adb/modules/LuminPro/service.log', sizeKB: 12 }, +}) + +const mockConfig = () => ({ + ui_max_bri: 1000, + max_bri: 3500, + steps_num: 50, + log_max_size: 512, + auto_bri_sleep: 1, + display_hdr_sleep: 0, + hdr_enter_ratio: 1.15, + hdr_exit_ratio: 1.05, + compatibility_mode: 0, + sleep_time: '2300-0700', + inotify_events: 'c', + now_bri_file: '/sys/mock/brightness', + max_bri_file: '/sys/mock/max_brightness', + log_level: 'info', + debug_mode: 0, + blacklist_apps: ['com.example.video'], +}) + +const mockLogEntries = [ + { time: '09-10 12:00:01', tag: 'luminpro', level: 'INFO', message: '守护进程已启动' }, + { time: '09-10 12:00:03', tag: 'luminpro', level: 'INFO', message: '正在监听: /sys/mock/brightness, 事件: c' }, + { time: '09-10 12:01:12', tag: 'luminpro', level: 'INFO', message: '触发提升: 当前亮度 1200 ≥ 阈值 1000,目标 3500' }, + { time: '09-10 12:01:12', tag: 'luminpro', level: 'WARN', message: 'HDR 比率读取为空,使用缓存值: 1.02' }, + { time: '09-10 12:01:13', tag: 'luminpro', level: 'SUCCESS', message: '亮度提升完成 (3500)' }, +] + +const ok = (obj) => ({ ok: true, errno: 0, stdout: JSON.stringify(obj), stderr: '' }) + +/** 依据命令内容返回模拟响应;无法识别时返回 null */ +export function devMock(command) { + if (command.includes(' config read')) return ok(mockConfig()) + if (command.includes(' config patch') || command.includes(' config set')) return ok({ ok: true }) + if (command.includes(' status')) return ok(mockStatus(!command.includes('--no-display'))) + if (command.includes(' oplock')) return ok({ locked: false, seconds: 0 }) + if (command.includes(' focus')) return ok({ focus: 'com.example.video/.MainActivity' }) + if (command.includes(' brightness set')) return ok({ ok: true, value: 2000 }) + if (command.includes(' log tail')) { + return ok({ entries: mockLogEntries, sizeKB: 12, total: mockLogEntries.length }) + } + if (command.includes(' log clear') || command.includes(' log export')) return ok({ ok: true }) + if (command.includes('boost') || command.includes('restart') || command.includes('action.sh')) { + return { ok: true, errno: 0, stdout: 'LuminPro: 服务已启用', stderr: '' } + } + return null +} diff --git a/webui/src/api/ksu.js b/webui/src/api/ksu.js new file mode 100644 index 0000000..8f4500c --- /dev/null +++ b/webui/src/api/ksu.js @@ -0,0 +1,51 @@ +import { exec, moduleInfo } from 'kernelsu' +import { devMock } from './devMock.js' + +export const MODULE_DIR = '/data/adb/modules/LuminPro' +export const BIN = `${MODULE_DIR}/bin/luminpro` + +/** 是否为 KernelSU 环境(exec 可用) */ +let available = true + +export function isKsuAvailable() { + return available +} + +/** + * 执行 shell 命令。所有命令都是固定字符串或经 shellQuote 处理过的参数, + * 不把未校验的用户输入直接拼进命令。 + */ +export async function runCmd(command) { + try { + const res = await exec(command) + available = true + return { + ok: res.errno === 0, + errno: res.errno, + stdout: res.stdout ?? '', + stderr: res.stderr ?? '', + } + } catch (err) { + available = false + // 仅开发环境回退到模拟数据,真机上失败就是失败 + if (import.meta.env.DEV) { + const mocked = devMock(command) + if (mocked) return mocked + } + return { ok: false, errno: -1, stdout: '', stderr: String(err) } + } +} + +/** 把任意字符串安全地包成 shell 单引号参数 */ +export function shellQuote(value) { + return `'${String(value).replace(/'/g, "'\\''")}'` +} + +/** 读取模块版本(module.prop 的 version) */ +export function moduleVersion() { + try { + return JSON.parse(moduleInfo()).version || '' + } catch { + return import.meta.env.DEV ? 'V2.5.0-dev.0' : '' + } +} diff --git a/webui/src/api/luminpro.js b/webui/src/api/luminpro.js new file mode 100644 index 0000000..c945bda --- /dev/null +++ b/webui/src/api/luminpro.js @@ -0,0 +1,85 @@ +/** + * Go 侧 JSON API 客户端。所有读写都经由 `luminpro` 子命令: + * 一次调用拿回结构化数据,避免前端拼多条 shell 命令与字符串转义。 + */ +import { BIN, MODULE_DIR, runCmd, shellQuote } from './ksu.js' + +/** 调用返回 JSON 的子命令 */ +async function callJSON(subcommand, args = []) { + const command = [BIN, subcommand, ...args.map(shellQuote)].join(' ') + const res = await runCmd(command) + if (!res.ok) { + throw new Error(res.stderr.trim() || `命令执行失败: luminpro ${subcommand}`) + } + try { + return JSON.parse(res.stdout) + } catch { + throw new Error(`输出不是合法 JSON: luminpro ${subcommand}`) + } +} + +/** 聚合状态;display=false 时跳过 dumpsys/settings 读取 */ +export function fetchStatus({ display = true } = {}) { + return callJSON('status', display ? [] : ['--no-display']) +} + +/** 操作锁状态(轻量,供高频轮询) */ +export function fetchOplock() { + return callJSON('oplock') +} + +/** 当前前台 Activity(活动抓取向导用) */ +export function fetchFocus() { + return callJSON('focus') +} + +/** 设置亮度 */ +export function setBrightness(value) { + return callJSON('brightness', ['set', String(value)]) +} + +/** 读取完整配置 */ +export function fetchConfig() { + return callJSON('config', ['read']) +} + +/** 浅合并写入配置(只传变化字段) */ +export function patchConfig(patch) { + return callJSON('config', ['patch', JSON.stringify(patch)]) +} + +/** 读取日志 */ +export function fetchLog(lines = 200) { + return callJSON('log', ['tail', '-n', String(lines)]) +} + +/** 清空日志 */ +export function clearLog() { + return callJSON('log', ['clear']) +} + +/** 导出日志到 /sdcard */ +export function exportLog(dir = '/sdcard') { + return callJSON('log', ['export', dir]) +} + +/** 一键提升 / 恢复 */ +export function boost() { + return runCmd(`${BIN} boost`) +} + +/** 重启模块 */ +export function restart() { + return runCmd(`${BIN} restart`) +} + +/** 启停切换(沿用 action.sh,管理器「操作」按钮与之共用同一实现) */ +export function toggleService() { + return runCmd(`sh ${MODULE_DIR}/action.sh`) +} + +/** 模块文档内容(关于页) */ +export async function readModuleFile(name) { + const res = await runCmd(`cat ${shellQuote(`${MODULE_DIR}/${name}`)} 2>/dev/null`) + return res.ok ? res.stdout : '' +} diff --git a/webui/src/apps.css b/webui/src/apps.css deleted file mode 100644 index be2b7e3..0000000 --- a/webui/src/apps.css +++ /dev/null @@ -1,562 +0,0 @@ -.app-list-hint { - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface-variant); - margin-top: 0; - margin-bottom: var(--spacing-m); -} - -/* App Search */ -.app-search-container { - display: flex; - align-items: center; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-m); - padding: 8px 12px; - margin-bottom: var(--spacing-m); - transition: - border-color 0.2s, - box-shadow 0.2s; -} - -.app-search-container:focus-within { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.3); -} - -.search-icon { - width: 18px; - height: 18px; - color: var(--md-sys-color-on-surface-variant); - margin-right: 8px; -} - -.app-search-input { - flex: 1; - width: 100%; - min-width: 0; - background: transparent; - border: none; - color: var(--md-sys-color-on-surface); - font-size: 0.875rem; - outline: none; - font-family: inherit; -} - -.app-search-input::placeholder { - color: var(--md-sys-color-on-surface-variant); -} - -.count-badge { - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - font-size: 0.75rem; - font-weight: 600; - padding: 2px 8px; - border-radius: 20px; - margin-left: 8px; - white-space: nowrap; - opacity: 0.85; -} - -/* App List */ -.app-list-container { - max-height: 60vh; - overflow-y: auto; - border-radius: var(--border-radius-m); - padding: 0; -} - -.app-list-container::-webkit-scrollbar { - display: none; -} - -/* 虚拟滚动:spacer 撑起总高度,行绝对定位; - 行间距由 item 的 padding-bottom 提供,保证测量行高包含间距 */ -.app-virtual-spacer { - position: relative; - width: 100%; -} - -.app-virtual-item { - position: absolute; - top: 0; - left: 0; - width: 100%; - padding-bottom: var(--spacing-s); -} - -.app-list-item { - display: flex; - flex-direction: column; - background-color: var(--md-sys-color-surface-container-high); - border-radius: var(--border-radius-s); - transition: background-color 0.2s; - overflow: hidden; - flex-shrink: 0; -} - -.app-item-main-row { - display: flex; - align-items: center; - gap: var(--spacing-m); - padding: var(--spacing-s) var(--spacing-m); -} - -.app-item-main-row:active { - background-color: var(--md-sys-color-surface-container); -} - -.app-checkbox-label { - display: flex; - align-items: center; - cursor: pointer; - position: relative; -} - -.app-checkbox { - opacity: 0; - position: absolute; - width: 0; - height: 0; -} - -.app-checkbox-custom { - width: 20px; - height: 20px; - border: 2px solid var(--md-sys-color-outline); - border-radius: 4px; - display: flex; - align-items: center; - justify-content: center; - transition: all 0.2s; -} - -.app-checkbox:checked + .app-checkbox-custom { - background-color: var(--md-sys-color-primary); - border-color: var(--md-sys-color-primary); -} - -.app-checkbox.unsaved:checked + .app-checkbox-custom { - background-color: #4caf50; - border-color: #4caf50; -} - -.app-checkbox:checked + .app-checkbox-custom::after { - content: ''; - width: 5px; - height: 10px; - border: solid var(--md-sys-color-on-primary); - border-width: 0 2px 2px 0; - transform: rotate(45deg); - margin-bottom: 2px; -} - -.app-info { - display: flex; - flex-direction: column; - flex: 1; - overflow: hidden; -} - -.app-name { - font-size: 1rem; - font-weight: 500; - color: var(--md-sys-color-on-surface); - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.app-pkg { - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface-variant); - font-family: 'Geist Mono', monospace; - display: flex; - flex-wrap: wrap; - align-items: center; - gap: 6px; - word-break: break-all; - line-height: 1.4; -} - -.app-badge { - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - padding: 0 4px; - border-radius: 4px; - font-size: 0.65rem; - font-weight: bold; -} - -.app-icon { - width: 40px; - height: 40px; - border-radius: 8px; - object-fit: cover; - flex-shrink: 0; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.app-icon-fallback { - width: 40px; - height: 40px; - border-radius: 8px; - background: linear-gradient( - 135deg, - var(--md-sys-color-primary-container), - rgba(168, 199, 250, 0.5) - ); - color: var(--md-sys-color-on-primary-container); - display: flex; - align-items: center; - justify-content: center; - font-size: 1.25rem; - font-weight: bold; - flex-shrink: 0; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.app-uid { - font-size: 0.65rem; - color: var(--md-sys-color-on-surface-variant); - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - padding: 0 4px; - border-radius: 4px; - font-family: 'Geist Mono', monospace; - margin-left: 6px; - vertical-align: middle; -} - -/* 部分选中状态(有活动条目但包未完全选中)*/ -.app-checkbox-custom.partial { - background-color: var(--md-sys-color-primary-container); - border-color: var(--md-sys-color-primary); -} - -.app-checkbox-custom.partial::after { - content: ''; - display: block; - width: 8px; - height: 8px; - background-color: var(--md-sys-color-primary); - border-radius: 1px; -} - -/* 活动列表展开箭头 */ -.app-activities-chevron { - flex-shrink: 0; - display: flex; - align-items: center; - justify-content: center; - width: 28px; - height: 28px; - background: none; - border: none; - border-radius: var(--border-radius-s); - color: var(--md-sys-color-on-surface-variant); - cursor: pointer; - transition: - transform 0.2s, - background-color 0.2s; - padding: 0; -} - -.app-activities-chevron:hover { - background-color: var(--md-sys-color-surface-container); -} - -.app-activities-chevron.expanded { - transform: rotate(180deg); -} - -/* 活动列表容器 */ -.app-activities-list { - display: none; - flex-direction: column; - padding: 0 var(--spacing-m) var(--spacing-s); - border-top: 1px solid var(--md-sys-color-outline-variant); - gap: 2px; -} - -.app-activities-list.show { - display: flex; -} - -/* 单条活动条目 */ -.activity-entry-item { - display: flex; - align-items: center; - gap: 8px; - padding: 5px 4px; - border-radius: var(--border-radius-s); -} - -.activity-entry-path { - flex: 1; - font-family: 'Geist Mono', 'Roboto Mono', monospace; - font-size: 0.75rem; - color: var(--md-sys-color-on-surface-variant); - word-break: break-all; - line-height: 1.4; -} - -.activity-entry-delete { - flex-shrink: 0; - display: flex; - align-items: center; - justify-content: center; - width: 24px; - height: 24px; - background: none; - border: none; - border-radius: 50%; - color: var(--md-sys-color-error); - cursor: pointer; - padding: 0; - transition: background-color 0.2s; -} - -.activity-entry-delete:hover { - background-color: var(--md-sys-color-error-container); -} - -/* 按活动屏蔽输入卡片 */ -.activity-block-card { - background-color: var(--md-sys-color-surface-container-high); - border-radius: var(--border-radius-m); - padding: var(--spacing-s) var(--spacing-m); - margin-bottom: var(--spacing-m); - display: flex; - flex-direction: column; - gap: 8px; -} - -.activity-block-header { - display: flex; - align-items: center; - justify-content: space-between; -} - -.activity-block-label { - font-size: 0.8125rem; - font-weight: 500; - color: var(--md-sys-color-on-surface); -} - -.btn-picker-trigger { - display: flex; - align-items: center; - gap: 4px; - background: none; - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - color: var(--md-sys-color-primary); - font-size: 0.75rem; - font-weight: 500; - padding: 3px 8px; - cursor: pointer; - transition: - background-color 0.2s, - border-color 0.2s; - white-space: nowrap; - font-family: inherit; -} - -.btn-picker-trigger:hover { - background-color: var(--md-sys-color-primary-container); - border-color: var(--md-sys-color-primary); -} - -.activity-block-row { - display: flex; - gap: 8px; - align-items: stretch; -} - -.activity-block-input { - flex: 1; - background: var(--md-sys-color-surface-container); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - padding: 7px 10px; - font-family: 'Geist Mono', 'Roboto Mono', monospace; - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface); - outline: none; - transition: - border-color 0.2s, - box-shadow 0.2s; -} - -.activity-block-input:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.3); -} - -/* ======================== - 获取活动名向导覆盖层 - ======================== */ -.activity-picker-overlay { - position: fixed; - inset: 0; - background: var(--md-sys-color-background); - z-index: 950; - display: flex; - flex-direction: column; - transform: translateX(100%); - transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1); -} - -.activity-picker-overlay.show { - transform: translateX(0); -} - -.activity-picker-header { - display: flex; - align-items: center; - gap: 12px; - padding: calc(var(--safe-area-inset-top, 0px) + 16px) 16px 12px; - border-bottom: 1px solid var(--md-sys-color-outline-variant); - flex-shrink: 0; -} - -.picker-back-btn { - display: flex; - align-items: center; - justify-content: center; - width: 36px; - height: 36px; - background: none; - border: none; - border-radius: 50%; - color: var(--md-sys-color-on-surface); - cursor: pointer; - transition: background-color 0.2s; - flex-shrink: 0; -} - -.picker-back-btn:hover { - background-color: var(--md-sys-color-surface-container); -} - -.picker-title { - font-size: 1.0625rem; - font-weight: 600; - color: var(--md-sys-color-on-surface); -} - -.picker-steps-indicator { - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - padding: 16px 0 0; - flex-shrink: 0; -} - -.picker-step-dot { - width: 6px; - height: 6px; - border-radius: 50%; - background-color: var(--md-sys-color-outline-variant); - transition: - background-color 0.3s, - transform 0.3s, - width 0.3s; -} - -.picker-step-dot.active { - background-color: var(--md-sys-color-primary); - transform: scale(1.2); - width: 18px; - border-radius: 4px; -} - -.activity-picker-body { - flex: 1; - overflow-y: auto; - display: flex; - flex-direction: column; -} - -.picker-step { - flex: 1; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 32px 32px calc(var(--safe-area-inset-bottom, 0px) + 48px); - text-align: center; - gap: 14px; -} - -.picker-step-icon { - color: var(--md-sys-color-primary); - opacity: 0.9; - margin-bottom: 4px; -} - -.picker-step-title { - font-size: 1.25rem; - font-weight: 600; - color: var(--md-sys-color-on-background); - margin: 0; -} - -.picker-step-desc { - font-size: 0.9375rem; - color: var(--md-sys-color-on-surface-variant); - line-height: 1.65; - max-width: 300px; - margin: 0; -} - -.picker-action-btn { - margin-top: 12px; - padding: 12px 32px; - border-radius: 24px; - font-size: 0.9375rem; -} - -.picker-status-text { - display: inline-block; - font-weight: 500; - color: var(--md-sys-color-primary); -} - -.picker-status-text.polling { - animation: picker-pulse 1.2s ease-in-out infinite; -} - -@keyframes picker-pulse { - 0%, - 100% { - opacity: 1; - } - 50% { - opacity: 0.35; - } -} - -.picker-result-box { - background: var(--md-sys-color-surface-container-high); - border: 1.5px solid var(--md-sys-color-primary); - border-radius: var(--border-radius-m); - padding: 14px 18px; - font-family: 'Geist Mono', 'Roboto Mono', monospace; - font-size: 0.875rem; - color: var(--md-sys-color-on-surface); - word-break: break-all; - line-height: 1.55; - max-width: 320px; - width: 100%; - text-align: left; -} - -.picker-result-actions { - display: flex; - gap: 12px; - margin-top: 4px; -} diff --git a/webui/src/apps.js b/webui/src/apps.js deleted file mode 100644 index 5903129..0000000 --- a/webui/src/apps.js +++ /dev/null @@ -1,734 +0,0 @@ -// oxlint-disable no-unused-expressions -import { listPackages, getPackagesInfo } from 'kernelsu' -import { createIcons, Eye, EyeOff } from 'lucide' -import PinyinMatch from 'pinyin-match' -import { showToast, runCmd, readConfig, updateConfig } from './utils.js' - -let showingSystemApps = true -let savedBlacklist = new Set() -let activityEntries = new Set() // 活动级黑名单条目(格式:pkg/ActivityClass) - -export function updateUnsavedStyling() { - const items = document.querySelectorAll('.app-list-item') - items.forEach((item) => { - const cb = item.querySelector('.app-checkbox') - const custom = item.querySelector('.app-checkbox-custom') - if (!cb || !custom) return - const pkg = cb.dataset.pkg - const hasActivities = pkg && [...activityEntries].some((e) => e.startsWith(pkg + '/')) - // 部分选中:有活动条目但包名未完全选中 - if (!cb.checked && hasActivities) { - custom.classList.add('partial') - } else { - custom.classList.remove('partial') - } - // 未保存高亮 - if (cb.checked && !savedBlacklist.has(pkg)) { - cb.classList.add('unsaved') - } else { - cb.classList.remove('unsaved') - } - // 箭头可见性 - const chevron = item.querySelector('.app-activities-chevron') - if (chevron) { - chevron.style.display = hasActivities ? '' : 'none' - if (!hasActivities) { - const actList = item.querySelector('.app-activities-list') - if (actList) { - actList.classList.remove('show') - chevron.classList.remove('expanded') - } - } - } - }) -} - -export function reorderDOMApps() { - const container = document.getElementById('app-list-container') - if (!container) return - const items = Array.from(container.children) - const getState = (item) => { - const cb = item.querySelector('.app-checkbox') - if (cb?.checked) return 2 // 完全选中 - const pkg = cb?.dataset.pkg - if (pkg && [...activityEntries].some((e) => e.startsWith(pkg + '/'))) return 1 // 部分选中 - return 0 - } - items.sort((a, b) => getState(b) - getState(a)) - items.forEach((item) => container.appendChild(item)) -} - -export function renderActivityList(pkg, container) { - const entries = [...activityEntries].filter((e) => e.startsWith(pkg + '/')) - container.innerHTML = '' - entries.forEach((entry) => { - const entryDiv = document.createElement('div') - entryDiv.className = 'activity-entry-item' - const actPath = document.createElement('span') - actPath.className = 'activity-entry-path' - actPath.textContent = entry.slice(pkg.length + 1) - const delBtn = document.createElement('button') - delBtn.className = 'activity-entry-delete' - delBtn.innerHTML = - '' - delBtn.addEventListener('click', (e) => { - e.stopPropagation() - activityEntries.delete(entry) - renderActivityList(pkg, container) - const actItem = container.closest('.app-list-item') - if (actItem) { - const chevron = actItem.querySelector('.app-activities-chevron') - const remaining = [...activityEntries].filter((e) => e.startsWith(pkg + '/')) - if (chevron) chevron.style.display = remaining.length > 0 ? '' : 'none' - if (remaining.length === 0) { - container.classList.remove('show') - if (chevron) chevron.classList.remove('expanded') - } - } - updateUnsavedStyling() - reorderDOMApps() - }) - entryDiv.appendChild(actPath) - entryDiv.appendChild(delBtn) - container.appendChild(entryDiv) - }) -} - -export async function loadApps() { - const container = document.getElementById('app-list-container') - if (!container) return - container.innerHTML = - '
加载中...
' - - try { - // 读取已保存的黑名单(从 JSON 配置读取) - const cfg = await readConfig() - const allSaved = Array.isArray(cfg.blacklist_apps) ? cfg.blacklist_apps : [] - savedBlacklist = new Set(allSaved) - const savedPkgEntries = new Set(allSaved.filter((e) => !e.includes('/'))) - activityEntries = new Set(allSaved.filter((e) => e.includes('/'))) - - let infoList = [] - try { - const pkgs = await listPackages() - if (pkgs && pkgs.length > 0) { - infoList = await getPackagesInfo(pkgs) - } else { - throw new Error('No packages found') - } - } catch { - // 模拟 150 个应用包数据用于调试 - console.log('[DEBUG] 使用模拟应用列表数据') - infoList = Array.from({ length: 150 }, (_, i) => ({ - packageName: `com.mock.app${i}`, - appLabel: i % 10 === 0 ? `测试应用 ${i} (含抖音关键字)` : `模拟应用 ${i}`, - isSystem: i % 5 === 0, - uid: 10000 + i, - })) - } - - // 过滤系统应用 - if (!showingSystemApps) { - infoList = infoList.filter((app) => !app.isSystem) - } - - container.innerHTML = '' - - // 排序:非系统优先,按名称 - infoList.sort((a, b) => { - if (a.isSystem !== b.isSystem) return a.isSystem ? 1 : -1 - return (a.appLabel || '').localeCompare(b.appLabel || '') - }) - - if (infoList.length === 0) { - infoList.push( - { - packageName: 'com.example.app1', - appLabel: '示例 1', - isSystem: false, - uid: 10123, - }, - { - packageName: 'com.example.app2', - appLabel: '示例 2', - isSystem: false, - uid: 10124, - }, - { - packageName: 'com.example.sys1', - appLabel: '系统示例 1', - isSystem: true, - uid: 1000, - }, - { - packageName: 'com.example.sys2', - appLabel: '系统示例 2', - isSystem: true, - uid: 1001, - }, - ) - if (!showingSystemApps) { - infoList = infoList.filter((app) => !app.isSystem) - } - } - - // uid 去重 - const seenUids = new Set() - infoList = infoList.filter((app) => { - if (app.uid === undefined || app.uid === null) return true - if (seenUids.has(app.uid)) return false - seenUids.add(app.uid) - return true - }) - - infoList.forEach((app) => { - const item = document.createElement('div') - item.className = 'app-list-item' - - const checkboxLabel = document.createElement('label') - checkboxLabel.className = 'app-checkbox-label' - - const checkbox = document.createElement('input') - checkbox.type = 'checkbox' - checkbox.className = 'app-checkbox' - checkbox.dataset.pkg = app.packageName - - // 依据已保存包名条目勾选(不含活动条目) - checkbox.checked = savedPkgEntries.has(app.packageName) - checkbox.addEventListener('change', () => { - updateUnsavedStyling() - reorderDOMApps() - }) - - const customCheckbox = document.createElement('span') - customCheckbox.className = 'app-checkbox-custom' - checkboxLabel.appendChild(checkbox) - checkboxLabel.appendChild(customCheckbox) - - const infoDiv = document.createElement('div') - infoDiv.className = 'app-info' - - const nameSpan = document.createElement('span') - nameSpan.className = 'app-name' - nameSpan.appendChild(document.createTextNode(app.appLabel || 'Unknown')) - - if (app.uid !== undefined) { - const uidBadge = document.createElement('span') - uidBadge.className = 'app-uid' - uidBadge.textContent = String(app.uid) - nameSpan.appendChild(uidBadge) - } - - const pkgSpan = document.createElement('span') - pkgSpan.className = 'app-pkg' - pkgSpan.textContent = app.packageName || '' - - if (app.isSystem) { - const sysBadge = document.createElement('span') - sysBadge.className = 'app-badge' - sysBadge.textContent = '系统' - pkgSpan.appendChild(sysBadge) - } - - infoDiv.appendChild(nameSpan) - infoDiv.appendChild(pkgSpan) - - // 活动展开箭头 - const chevronBtn = document.createElement('button') - chevronBtn.className = 'app-activities-chevron' - chevronBtn.innerHTML = - '' - const pkgActivities = [...activityEntries].filter((e) => e.startsWith(app.packageName + '/')) - chevronBtn.style.display = pkgActivities.length > 0 ? '' : 'none' - - const mainRow = document.createElement('div') - mainRow.className = 'app-item-main-row' - mainRow.appendChild(checkboxLabel) - mainRow.appendChild(infoDiv) - mainRow.appendChild(chevronBtn) - - // 活动列表(初始折叠) - const actListDiv = document.createElement('div') - actListDiv.className = 'app-activities-list' - actListDiv.dataset.pkg = app.packageName - renderActivityList(app.packageName, actListDiv) - - chevronBtn.addEventListener('click', (e) => { - e.stopPropagation() - actListDiv.classList.toggle('show') - chevronBtn.classList.toggle('expanded') - }) - - item.appendChild(mainRow) - item.appendChild(actListDiv) - container.appendChild(item) - }) - - updateUnsavedStyling() - reorderDOMApps() - - const badge = document.getElementById('app-count-badge') - if (badge) badge.textContent = infoList.length - - if (infoList.length === 0) { - container.innerHTML = - '
无应用
' - } - } catch (e) { - container.innerHTML = `
加载失败: ${e.message || String(e)}
` - } -} - -export function setupAppsEvents() { - // 下拉菜单控制 - const btnAppsMenu = document.getElementById('btn-apps-menu') - const appsDropdownMenu = document.getElementById('apps-dropdown-menu') - - if (btnAppsMenu && appsDropdownMenu) { - btnAppsMenu.addEventListener('click', (e) => { - e.stopPropagation() - appsDropdownMenu.classList.toggle('show') - }) - document.addEventListener('click', (e) => { - if (!btnAppsMenu.contains(e.target) && !appsDropdownMenu.contains(e.target)) { - appsDropdownMenu.classList.remove('show') - } - }) - } - - // 切换系统应用显示 - const btnToggleSysApps = document.getElementById('btn-toggle-sys-apps') - if (btnToggleSysApps) { - btnToggleSysApps.addEventListener('click', () => { - showingSystemApps = !showingSystemApps - - const textSpan = document.getElementById('sys-apps-text') - const iconWrap = document.getElementById('sys-apps-icon') - - if (textSpan) textSpan.textContent = showingSystemApps ? '隐藏系统应用' : '显示系统应用' - - if (iconWrap) { - const p = iconWrap.parentNode - const newIcon = document.createElement('i') - newIcon.setAttribute('data-lucide', showingSystemApps ? 'eye-off' : 'eye') - newIcon.id = 'sys-apps-icon' - p.replaceChild(newIcon, iconWrap) - createIcons({ icons: { Eye, EyeOff }, nameAttr: 'data-lucide' }) - } - - loadApps() - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - }) - } - - // 智能选择 - const btnSmartSelect = document.getElementById('btn-smart-select') - if (btnSmartSelect) { - const smartKeywords = [ - '相册', - '抖音', - '快手', - '视频', - '哔哩哔哩', - 'bili', - 'pili', - 'netflix', - 'youtube', - 'tiktok', - 'x', - ] - btnSmartSelect.addEventListener('click', () => { - const items = document.querySelectorAll('.app-list-item') - items.forEach((item) => { - const name = item.querySelector('.app-name').textContent.toLowerCase() - const checkbox = item.querySelector('.app-checkbox') - let match = false - for (const kw of smartKeywords) { - if (kw === 'x') { - if (name === 'x' || name === 'x (twitter)') { - match = true - break - } - } else if (name.includes(kw)) { - match = true - break - } - } - if (match) checkbox.checked = true - }) - updateUnsavedStyling() - reorderDOMApps() - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - }) - } - - // 手动添加包名 - const btnManualAdd = document.getElementById('btn-manual-add') - if (btnManualAdd) { - btnManualAdd.addEventListener('click', async () => { - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - const pkg = prompt('请输入你要彻底屏蔽的完整应用包名(例如: com.example.app):') - if (!pkg || !pkg.trim()) return - - const realPkg = pkg.trim() - const existing = document.querySelector(`.app-checkbox[data-pkg="${realPkg}"]`) - if (existing) { - existing.checked = true - updateUnsavedStyling() - reorderDOMApps() - showToast('该应用已在列表中,已为你自动勾选并置顶') - return - } - - showToast('正在尝试获取应用信息...') - let appData = { - packageName: realPkg, - appLabel: '未知 (手动添加)', - isSystem: false, - uid: '自定义', - } - try { - const info = await getPackagesInfo([realPkg]) - if (info && info.length > 0) appData = info[0] - } catch { - /* ignore */ - } - - const container = document.getElementById('app-list-container') - const item = document.createElement('div') - item.className = 'app-list-item' - - const checkboxLabel = document.createElement('label') - checkboxLabel.className = 'app-checkbox-label' - - const checkbox = document.createElement('input') - checkbox.type = 'checkbox' - checkbox.className = 'app-checkbox' - checkbox.dataset.pkg = realPkg - checkbox.checked = true - checkbox.addEventListener('change', () => { - updateUnsavedStyling() - reorderDOMApps() - }) - - const customCheckbox = document.createElement('span') - customCheckbox.className = 'app-checkbox-custom' - checkboxLabel.appendChild(checkbox) - checkboxLabel.appendChild(customCheckbox) - - const infoDiv = document.createElement('div') - infoDiv.className = 'app-info' - - const nameSpan = document.createElement('span') - nameSpan.className = 'app-name' - nameSpan.appendChild(document.createTextNode(appData.appLabel || 'Unknown')) - - if (appData.uid !== undefined) { - const uidBadge = document.createElement('span') - uidBadge.className = 'app-uid' - uidBadge.textContent = String(appData.uid) - nameSpan.appendChild(uidBadge) - } - - const pkgSpan = document.createElement('span') - pkgSpan.className = 'app-pkg' - pkgSpan.textContent = realPkg - - if (appData.isSystem) { - const sysBadge = document.createElement('span') - sysBadge.className = 'app-badge' - sysBadge.textContent = '系统' - pkgSpan.appendChild(sysBadge) - } - - infoDiv.appendChild(nameSpan) - infoDiv.appendChild(pkgSpan) - - const chevronBtn = document.createElement('button') - chevronBtn.className = 'app-activities-chevron' - chevronBtn.innerHTML = - '' - chevronBtn.style.display = 'none' - - const mainRow = document.createElement('div') - mainRow.className = 'app-item-main-row' - mainRow.appendChild(checkboxLabel) - mainRow.appendChild(infoDiv) - mainRow.appendChild(chevronBtn) - - const actListDiv = document.createElement('div') - actListDiv.className = 'app-activities-list' - actListDiv.dataset.pkg = realPkg - - chevronBtn.addEventListener('click', (e) => { - e.stopPropagation() - actListDiv.classList.toggle('show') - chevronBtn.classList.toggle('expanded') - }) - - item.appendChild(mainRow) - item.appendChild(actListDiv) - container.appendChild(item) - - updateUnsavedStyling() - reorderDOMApps() - showToast('已成功添加并勾选') - }) - } - - // 全选 - const btnSelectAll = document.getElementById('btn-select-all') - if (btnSelectAll) { - btnSelectAll.addEventListener('click', () => { - document.querySelectorAll('.app-checkbox').forEach((cb) => { - cb.checked = true - }) - updateUnsavedStyling() - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - }) - } - - // 全不选 - const btnSelectNone = document.getElementById('btn-select-none') - if (btnSelectNone) { - btnSelectNone.addEventListener('click', () => { - document.querySelectorAll('.app-checkbox').forEach((cb) => { - cb.checked = false - }) - updateUnsavedStyling() - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - }) - } - - // 反选 - const btnInvertSelection = document.getElementById('btn-invert-selection') - if (btnInvertSelection) { - btnInvertSelection.addEventListener('click', () => { - document.querySelectorAll('.app-checkbox').forEach((cb) => { - cb.checked = !cb.checked - }) - updateUnsavedStyling() - appsDropdownMenu && appsDropdownMenu.classList.remove('show') - }) - } - - // 刷新(重排) - const btnAppsRefresh = document.getElementById('btn-apps-refresh') - if (btnAppsRefresh) { - btnAppsRefresh.addEventListener('click', () => { - reorderDOMApps() - }) - } - - // 保存黑名单 - const btnSaveBlacklist = document.getElementById('btn-save-blacklist') - if (btnSaveBlacklist) { - btnSaveBlacklist.addEventListener('click', async () => { - showToast('保存中...') - const selectedPkgs = [] - document.querySelectorAll('.app-checkbox').forEach((cb) => { - if (cb.checked) selectedPkgs.push(cb.dataset.pkg) - }) - const allEntries = [...selectedPkgs, ...activityEntries] - const res = await updateConfig({ blacklist_apps: allEntries }) - if (res.errno === 0 || res.stdout?.includes('OK')) { - showToast('黑名单保存成功') - savedBlacklist = new Set(allEntries) - updateUnsavedStyling() - reorderDOMApps() - } else { - showToast('保存失败: ' + res.stderr) - } - }) - } - - // 按活动屏蔽 - const btnAddActivity = document.getElementById('btn-add-activity') - const inputActivityEntry = document.getElementById('input-activity-entry') - if (btnAddActivity && inputActivityEntry) { - const doAddActivity = () => { - const val = inputActivityEntry.value.trim() - if (!val) return - const parts = val.split('/') - if (parts.length !== 2 || !parts[0] || !parts[1]) { - showToast('格式错误,请输入 包名/完整活动类名') - return - } - activityEntries.add(val) - inputActivityEntry.value = '' - const pkg = parts[0] - document.querySelectorAll('.app-list-item').forEach((appItem) => { - const cb = appItem.querySelector('.app-checkbox') - if (cb && cb.dataset.pkg === pkg) { - const actList = appItem.querySelector('.app-activities-list') - const chevron = appItem.querySelector('.app-activities-chevron') - if (actList) { - renderActivityList(pkg, actList) - actList.classList.add('show') - } - if (chevron) { - chevron.style.display = '' - chevron.classList.add('expanded') - } - } - }) - updateUnsavedStyling() - reorderDOMApps() - showToast(`已添加: ${val}`) - } - btnAddActivity.addEventListener('click', doAddActivity) - inputActivityEntry.addEventListener('keydown', (e) => { - if (e.key === 'Enter') doAddActivity() - }) - } - - // 搜索 - const inputAppSearch = document.getElementById('input-app-search') - if (inputAppSearch) { - inputAppSearch.addEventListener('input', (e) => { - const keyword = e.target.value.trim().toLowerCase() - const items = document.querySelectorAll('.app-list-item') - let visibleCount = 0 - items.forEach((item) => { - const name = item.querySelector('.app-name').textContent - const pkg = item.querySelector('.app-pkg').textContent.toLowerCase() - if (!keyword || pkg.includes(keyword) || PinyinMatch.match(name, keyword)) { - item.style.display = 'flex' - visibleCount++ - } else { - item.style.display = 'none' - } - }) - const badge = document.getElementById('app-count-badge') - if (badge) badge.textContent = visibleCount - }) - } - - setupActivityPicker() -} - -function setupActivityPicker() { - const overlay = document.getElementById('activity-picker-overlay') - if (!overlay) return - - const btnPickActivity = document.getElementById('btn-pick-activity') - const btnPickerBack = document.getElementById('btn-picker-back') - const step1 = document.getElementById('picker-step-1') - const step2 = document.getElementById('picker-step-2') - const step3 = document.getElementById('picker-step-3') - const dots = [ - document.getElementById('picker-dot-1'), - document.getElementById('picker-dot-2'), - document.getElementById('picker-dot-3'), - ] - const btnStep1Next = document.getElementById('btn-picker-step1-next') - const btnPickerStart = document.getElementById('btn-picker-start') - const btnPickerRetry = document.getElementById('btn-picker-retry') - const btnPickerConfirm = document.getElementById('btn-picker-confirm') - const pickerStatusText = document.getElementById('picker-status-text') - const pickerResultText = document.getElementById('picker-result-text') - - let pollingTimer = null - let detectedActivity = null - - function showStep(n) { - ;[step1, step2, step3].forEach((s, i) => { - if (s) s.style.display = i + 1 === n ? 'flex' : 'none' - }) - dots.forEach((d, i) => { - d?.classList.toggle('active', i + 1 === n) - }) - } - - function stopPolling() { - if (pollingTimer) { - clearInterval(pollingTimer) - pollingTimer = null - } - } - - function openPicker() { - stopPolling() - detectedActivity = null - if (btnPickerStart) btnPickerStart.disabled = false - if (pickerStatusText) { - pickerStatusText.textContent = '等待中...' - pickerStatusText.classList.remove('polling') - } - showStep(1) - overlay.classList.add('show') - } - - function closePicker() { - stopPolling() - overlay.classList.remove('show') - } - - btnPickActivity?.addEventListener('click', openPicker) - btnPickerBack?.addEventListener('click', closePicker) - btnStep1Next?.addEventListener('click', () => showStep(2)) - - btnPickerStart?.addEventListener('click', () => { - btnPickerStart.disabled = true - if (pickerStatusText) { - pickerStatusText.textContent = '检测中,请切换到目标界面...' - pickerStatusText.classList.add('polling') - } - stopPolling() - pollingTimer = setInterval(async () => { - try { - const res = await runCmd( - `dumpsys window 2>/dev/null | grep mCurrentFocus | sed 's/.*u[0-9][0-9]* //' | sed 's/}.*//'`, - ) - if (res.errno !== 0) return - const activity = res.stdout.trim() - // 空值或仍在 WebUI 内则继续等待 - if (!activity || activity.toLowerCase().includes('webui')) return - stopPolling() - detectedActivity = activity - if (pickerStatusText) pickerStatusText.classList.remove('polling') - if (pickerResultText) pickerResultText.textContent = activity - if (btnPickerStart) btnPickerStart.disabled = false - showStep(3) - } catch { - /* 忽略,继续轮询 */ - } - }, 600) - }) - - btnPickerRetry?.addEventListener('click', () => { - stopPolling() - detectedActivity = null - if (btnPickerStart) btnPickerStart.disabled = false - if (pickerStatusText) { - pickerStatusText.textContent = '等待中...' - pickerStatusText.classList.remove('polling') - } - showStep(2) - }) - - btnPickerConfirm?.addEventListener('click', () => { - if (!detectedActivity) return - activityEntries.add(detectedActivity) - const pkg = detectedActivity.split('/')[0] - document.querySelectorAll('.app-list-item').forEach((appItem) => { - const cb = appItem.querySelector('.app-checkbox') - if (cb && cb.dataset.pkg === pkg) { - const actList = appItem.querySelector('.app-activities-list') - const chevron = appItem.querySelector('.app-activities-chevron') - if (actList) { - renderActivityList(pkg, actList) - actList.classList.add('show') - } - if (chevron) { - chevron.style.display = '' - chevron.classList.add('expanded') - } - } - }) - updateUnsavedStyling() - reorderDOMApps() - showToast(`已添加: ${detectedActivity}`) - closePicker() - }) -} diff --git a/webui/src/components.css b/webui/src/components.css deleted file mode 100644 index 26af26f..0000000 --- a/webui/src/components.css +++ /dev/null @@ -1,663 +0,0 @@ -/* Cards */ -.card { - background-color: var(--md-sys-color-surface); - border-radius: var(--border-radius-m); - padding: var(--spacing-l); - box-shadow: - 0 1px 3px 0 rgba(0, 0, 0, 0.3), - 0 4px 8px 3px rgba(0, 0, 0, 0.15); - display: flex; - flex-direction: column; -} - -/* Collapsible card header */ -.card-header-toggle { - cursor: pointer; - user-select: none; - -webkit-user-select: none; - border-radius: var(--border-radius-s); - transition: background-color 0.15s; - margin: calc(-1 * var(--spacing-l)); - padding: var(--spacing-l); -} -.card-header-toggle:active { - background-color: rgba(var(--md-sys-color-primary-rgb), 0.06); -} -.collapse-chevron { - color: var(--md-sys-color-on-surface-variant); - transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1); - flex-shrink: 0; -} -.collapse-chevron.open { - transform: rotate(180deg); -} - -/* grid-template-rows collapse animation */ -.collapsible-body { - display: grid; - grid-template-rows: 0fr; - transition: grid-template-rows 0.35s cubic-bezier(0.25, 1, 0.5, 1); -} -.collapsible-body.open { - grid-template-rows: 1fr; -} -.collapsible-body > div { - overflow: hidden; - padding-top: 0; - transition: padding-top 0.35s cubic-bezier(0.25, 1, 0.5, 1); -} -.collapsible-body.open > div { - padding-top: var(--spacing-l); - overflow: visible; -} - -/* Page Transitions */ -.card-animate-in { - animation: cardFadeIn 0.4s cubic-bezier(0.2, 0, 0, 1) forwards; -} - -.navbar-slider { - left: 0; -} - -@keyframes cardFadeIn { - from { - opacity: 0; - transform: translateY(12px) scale(0.985); - } - to { - opacity: 1; - transform: translateY(0) scale(1); - } -} - -#log-section { - flex: 1; - min-height: calc(100vh - 220px); -} - -.card-header { - display: flex; - align-items: center; - gap: var(--spacing-s); -} - -.card-header h2 { - margin: 0; - font-size: 1.125rem; - font-weight: 500; - color: var(--md-sys-color-on-surface); - flex-grow: 1; -} - -/* Config Items */ -.config-group { - margin-top: 12px; - margin-bottom: 0; - padding: 12px; - background-color: var(--md-sys-color-surface-container); - border-radius: var(--border-radius-m); - border: 1px solid rgba(var(--md-sys-color-on-surface-rgb, 0, 0, 0), 0.05); -} - -.group-title { - margin: 0 0 10px 0; - color: var(--md-sys-color-primary); - font-size: 0.875rem; - font-weight: 600; - display: flex; - align-items: center; - gap: 8px; -} - -.group-title i, -.group-title svg { - width: 16px; - height: 16px; -} - -.config-item { - display: flex; - justify-content: space-between; - align-items: center; - padding: 4px 0; -} - -#advanced-section .config-item { - flex-direction: column; - align-items: flex-start; - gap: 12px; - width: 100%; -} - -#advanced-section .config-value { - width: 100%; -} - -.config-item + .config-item { - margin-top: 10px; - border-top: 1px solid rgba(var(--md-sys-color-outline-variant-rgb, 142, 144, 153), 0.1); - padding-top: 10px; -} - -.config-label { - display: flex; - flex-direction: column; -} - -.config-name { - font-size: 1rem; - color: var(--md-sys-color-on-surface); -} - -.config-desc { - font-size: 0.875rem; - color: var(--md-sys-color-on-surface-variant); -} - -.config-input { - width: 100px; - padding: 8px 12px; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - color: var(--md-sys-color-on-surface); - font-size: 1rem; - font-family: inherit; - text-align: right; - outline: none; - transition: all 0.2s ease; -} - -.config-input:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); - background-color: var(--md-sys-color-surface); -} - -.config-select { - padding: 8px 12px; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - color: var(--md-sys-color-on-surface); - font-size: 1rem; - font-family: inherit; - outline: none; - cursor: pointer; - transition: all 0.2s ease; -} - -.config-select:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); - background-color: var(--md-sys-color-surface); -} - -#advanced-section .config-input { - width: 100%; - text-align: left; -} - -.config-textarea { - background-color: var(--md-sys-color-surface-container-high); - width: 100%; - min-height: 60px; - max-height: 300px; - color: var(--md-sys-color-on-surface); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-m); - resize: vertical; - padding: 10px 14px; - font-family: 'Geist Mono', system-ui, monospace; - font-size: 0.875rem; - line-height: 1.4; - transition: all 0.2s ease; - outline: none; -} - -.config-textarea:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); - background-color: var(--md-sys-color-surface); -} - -.config-input-wide { - width: 140px; -} - -.config-item-expand { - display: flex; - justify-content: flex-end; - margin-top: var(--spacing-s); - max-height: 0; - overflow: hidden; - opacity: 0; - transition: all 0.3s ease; -} - -.config-item-expand.show { - max-height: 100px; /* 调整为适合内容的高度 */ - opacity: 1; - margin-bottom: var(--spacing-m); -} - -/* Custom Time Picker Styles */ -.custom-time-picker { - display: flex; - align-items: center; - gap: 8px; -} - -.time-unit { - display: flex; - align-items: center; - gap: 2px; - background-color: var(--md-sys-color-surface-container-high); - padding: 2px 6px; - border-radius: var(--border-radius-s); - border: 1px solid var(--md-sys-color-outline); -} - -.time-input { - width: 32px; - background-color: transparent; - color: var(--md-sys-color-on-surface); - border: none; - font-size: 0.875rem; - text-align: center; - font-family: 'Geist Mono', monospace; - outline: none; - -moz-appearance: textfield; -} - -.time-input-wide { - width: 48px; -} - -.time-input::-webkit-outer-spin-button, -.time-input::-webkit-inner-spin-button { - -webkit-appearance: none; - margin: 0; -} - -.time-sep { - color: var(--md-sys-color-on-surface-variant); - font-size: 0.875rem; -} - -/* Switch Styles */ -.switch { - position: relative; - display: inline-block; - width: 52px; - height: 32px; -} - -.switch input { - opacity: 0; - width: 0; - height: 0; -} - -.slider { - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: var(--md-sys-color-surface-container-high); - transition: 0.4s; - border-radius: 34px; - border: 2px solid var(--md-sys-color-outline); -} - -.slider:before { - position: absolute; - content: ''; - height: 24px; - width: 24px; - left: 2px; - bottom: 2px; - background-color: var(--md-sys-color-outline); - transition: 0.4s; - border-radius: 50%; -} - -input:checked + .slider { - background-color: var(--md-sys-color-primary-container); - border-color: var(--md-sys-color-primary); -} - -input:checked + .slider:before { - transform: translateX(20px); - background-color: var(--md-sys-color-primary); -} - -/* Status Grid */ -.status-grid { - display: grid; - grid-template-columns: 1fr 1fr; - gap: var(--spacing-m); - margin-top: var(--spacing-m); -} - -.status-item { - background-color: var(--md-sys-color-surface-container); - padding: var(--spacing-m); - border-radius: var(--border-radius-m); - display: flex; - flex-direction: column; - gap: 8px; - border: 1px solid rgba(var(--md-sys-color-on-surface-rgb, 0, 0, 0), 0.04); - transition: transform 0.2s ease; -} - -.status-item:active { - transform: scale(0.98); -} - -.status-item-header { - display: flex; - align-items: center; - gap: 6px; - color: var(--md-sys-color-on-surface-variant); -} - -.status-item-header svg { - width: 14px; - height: 14px; - opacity: 0.7; -} - -.status-label { - font-size: 0.75rem; - font-weight: 500; -} - -.status-value { - font-size: 1.125rem; - font-weight: 600; - color: var(--md-sys-color-primary); - word-break: break-all; -} - -/* Brightness Section */ -.brightness-section { - margin-top: var(--spacing-l); - padding: var(--spacing-m); - background: linear-gradient( - 135deg, - var(--md-sys-color-surface-container-high) 0%, - var(--md-sys-color-surface-container) 100% - ); - border-radius: var(--border-radius-m); - border: 1px solid var(--md-sys-color-outline-variant); -} - -.brightness-header { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: var(--spacing-m); -} - -.brightness-title { - font-size: 1rem; - font-weight: 600; - color: var(--md-sys-color-on-surface); - letter-spacing: 0.5px; -} - -.brightness-percent { - font-size: 1.25rem; - font-weight: 700; - color: var(--md-sys-color-primary); - min-width: 50px; - text-align: right; -} - -/* Brightness Slider Container */ -.brightness-container { - position: relative; - display: flex; - align-items: center; - gap: 8px; - margin-bottom: var(--spacing-m); - padding: var(--spacing-s) 0; -} - -.brightness-label { - font-size: 0.75rem; - color: var(--md-sys-color-on-surface-variant); - min-width: 24px; - text-align: center; - font-weight: 500; -} - -/* Brightness Slider (Progress Bar Style) */ -.brightness-slider { - flex: 1; - height: 24px; - border-radius: 12px; - /* 背景将由 JS 通过 linear-gradient 动态更新实现进度条效果 */ - background: var(--md-sys-color-surface-container-high); - outline: none; - -webkit-appearance: none; - appearance: none; - cursor: grab; - transition: - background 0.35s ease, - height 0.2s, - box-shadow 0.2s; - border: 1px solid rgba(255, 255, 255, 0.03); - box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2); - overflow: hidden; /* 确保进度条颜色不溢出圆角 */ -} - -.brightness-slider:hover { - height: 28px; -} - -.brightness-slider:disabled { - opacity: 0.5; - cursor: not-allowed; -} - -.brightness-slider:disabled:hover { - height: 24px; -} - -.brightness-slider::-webkit-slider-thumb { - -webkit-appearance: none; - appearance: none; - width: 0; - height: 0; - background: transparent; - cursor: grab; - border: none; -} - -.brightness-slider::-webkit-slider-thumb:active { - cursor: grabbing; -} - -.brightness-slider::-moz-range-thumb { - width: 28px; - height: 28px; - border-radius: 50%; - background: var(--md-sys-color-primary); - cursor: grab; - border: 2px solid var(--md-sys-color-surface); - box-shadow: - 0 2px 8px rgba(0, 0, 0, 0.4), - inset 0 1px 2px rgba(255, 255, 255, 0.3); - transition: all 0.2s; -} - -.brightness-slider::-moz-range-thumb:hover { - box-shadow: - 0 4px 12px rgba(0, 0, 0, 0.5), - inset 0 1px 2px rgba(255, 255, 255, 0.3); - transform: scale(1.1); -} - -.brightness-slider::-moz-range-thumb:active { - cursor: grabbing; - box-shadow: 0 0 0 10px rgba(168, 199, 250, 0.2); -} - -.brightness-slider::-moz-range-track { - background: transparent; - border: none; -} - -/* Actions */ -.save-badge { - margin-left: auto; - flex-shrink: 0; - padding: 2px 10px; - border-radius: 999px; - font-size: 0.75rem; - font-weight: 600; - line-height: 1.5; -} - -.save-badge.unsaved { - color: var(--color-warning); - background: color-mix(in srgb, var(--color-warning) 15%, transparent); -} - -.save-badge.saved { - color: #2f9e63; - background: rgba(47, 158, 99, 0.14); -} - -.card-actions { - display: flex; - justify-content: flex-end; - gap: 12px; - margin-top: 16px; - padding-top: 12px; - border-top: 1px solid var(--md-sys-color-outline-variant); -} - -/* Buttons */ -.btn { - display: inline-flex; - align-items: center; - justify-content: center; - gap: 8px; - padding: 10px 24px; - border-radius: 100px; - border: none; - font-size: 0.875rem; - font-weight: 500; - font-family: inherit; - cursor: pointer; - transition: - background-color 0.2s, - opacity 0.2s; -} - -.btn:active { - opacity: 0.8; -} - -.btn-primary { - background-color: var(--md-sys-color-primary); - color: var(--md-sys-color-on-primary); -} - -.btn-outline { - background-color: transparent; - border: 1px solid var(--md-sys-color-outline); - color: var(--md-sys-color-primary); -} - -.btn-outline-s, -.btn-text-s { - background-color: transparent; - border: 1px solid var(--md-sys-color-outline-variant); - color: var(--md-sys-color-primary); - padding: 4px 10px; - min-width: 50px; - height: 28px; - font-size: 0.75rem; - border-radius: var(--border-radius-s); - cursor: pointer; - display: inline-flex; - align-items: center; - justify-content: center; - transition: all 0.2s; - white-space: nowrap; -} - -.btn-text-s:active { - background-color: var(--md-sys-color-surface-container-high); -} - -.btn-danger { - background-color: var(--md-sys-color-error) !important; - color: var(--md-sys-color-on-error) !important; - border: none !important; -} - -/* Header Actions container */ -.header-actions { - display: flex; - align-items: center; - gap: 8px; -} - -.btn-icon-only { - background: transparent; - border: none; - color: var(--md-sys-color-on-surface-variant); - font-size: 1.25rem; - cursor: pointer; - padding: 4px; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; -} - -.btn-icon-only-s { - display: flex; - align-items: center; - justify-content: center; - width: 32px; - height: 32px; - border-radius: 8px; - border: none; - background-color: var(--md-sys-color-surface-container-high); - color: var(--md-sys-color-primary); - cursor: pointer; - transition: all 0.2s ease; -} - -.btn-icon-only-s:active { - background-color: var(--md-sys-color-primary-container); - transform: scale(0.9); -} - -.btn-icon-only-s i, -.btn-icon-only-s svg { - width: 16px; - height: 16px; -} - -.animate-spin { - animation: spin 1s linear infinite; -} - -@keyframes spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/webui/src/components/ActionMenu.vue b/webui/src/components/ActionMenu.vue new file mode 100644 index 0000000..2dc8317 --- /dev/null +++ b/webui/src/components/ActionMenu.vue @@ -0,0 +1,40 @@ + + + diff --git a/webui/src/components/AppBottomNav.vue b/webui/src/components/AppBottomNav.vue new file mode 100644 index 0000000..67fb7cc --- /dev/null +++ b/webui/src/components/AppBottomNav.vue @@ -0,0 +1,31 @@ + + + diff --git a/webui/src/components/AppSwitch.vue b/webui/src/components/AppSwitch.vue new file mode 100644 index 0000000..d3c8a0c --- /dev/null +++ b/webui/src/components/AppSwitch.vue @@ -0,0 +1,28 @@ + + + diff --git a/webui/src/components/AppTextField.vue b/webui/src/components/AppTextField.vue new file mode 100644 index 0000000..35a59e1 --- /dev/null +++ b/webui/src/components/AppTextField.vue @@ -0,0 +1,36 @@ + + + diff --git a/webui/src/components/AppTopBar.vue b/webui/src/components/AppTopBar.vue new file mode 100644 index 0000000..a980a77 --- /dev/null +++ b/webui/src/components/AppTopBar.vue @@ -0,0 +1,59 @@ + + + diff --git a/webui/src/components/BottomNav.vue b/webui/src/components/BottomNav.vue deleted file mode 100644 index 102dbc6..0000000 --- a/webui/src/components/BottomNav.vue +++ /dev/null @@ -1,143 +0,0 @@ - - - diff --git a/webui/src/components/ConfirmDialog.vue b/webui/src/components/ConfirmDialog.vue new file mode 100644 index 0000000..0b85872 --- /dev/null +++ b/webui/src/components/ConfirmDialog.vue @@ -0,0 +1,54 @@ + + + + + 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 @@ + + + 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 @@ + + + + + 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 @@ + + + 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 @@ - - -