mirror of
https://github.com/YuleBest/LuminPro.git
synced 2026-12-04 00:54:42 +08:00
- 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 死标记、统一文案
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
// 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()
|
|
}
|