8 Commits
14 changed files with 56 additions and 274 deletions

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
=======================================
LuminPro — 日用屏幕亮度强化
=======================================
LuminPro V2.3 — 日用屏幕亮度强化
作者: 酷安@Yule
=======================================
+3 -7
View File
@@ -211,10 +211,6 @@ func TestReadModuleInfo(t *testing.T) {
}
}
// fixedNow 是状态聚合测试的基准时间:运行时长等字段依赖「当前时间」,
// 必须与写入 state 的 startedAt 用同一基准,否则测试会随执行时机漂移。
var fixedNow = time.Date(2026, 9, 10, 12, 0, 0, 0, time.Local)
func TestBuildStatus(t *testing.T) {
dir := t.TempDir()
paths := DefaultPaths(dir)
@@ -251,9 +247,9 @@ func TestBuildStatus(t *testing.T) {
}
if err := WriteState(paths.StateFile, DaemonState{
PID: os.Getpid(),
StartedAt: fixedNow.Add(-90 * time.Second).Unix(),
StartedAt: time.Now().Add(-90 * time.Second).Unix(),
Mode: "event",
Ratio: &RatioInfo{Value: 1.08, At: fixedNow.Unix()},
Ratio: &RatioInfo{Value: 1.08, At: time.Now().Unix()},
HdrSleep: true,
}); err != nil {
t.Fatal(err)
@@ -269,7 +265,7 @@ func TestBuildStatus(t *testing.T) {
status := BuildStatus(paths, cfg, StatusDeps{
AutoBrightness: system.AutoBrightness{Runner: runner},
HDR: system.HdrRatio{Runner: runner},
Now: func() time.Time { return fixedNow },
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" {
+7 -19
View File
@@ -155,22 +155,13 @@ func (w *Watcher) Add(path, letters string) error {
return nil
}
// Close 释放资源。重复调用安全。
// Close 释放资源。
func (w *Watcher) Close() error {
w.mu.Lock()
defer w.mu.Unlock()
// 先唤醒 Run:直接关闭 fd 会让阻塞中的 poll 拿不到退出信号
if w.wakeW >= 0 {
_, _ = unix.Write(w.wakeW, []byte{1})
}
if w.wakeR >= 0 {
_ = unix.Close(w.wakeR)
w.wakeR = -1
}
if w.wakeW >= 0 {
_ = unix.Close(w.wakeW)
w.wakeW = -1
}
_ = unix.Close(w.wakeR)
_ = unix.Close(w.wakeW)
w.wakeR, w.wakeW = -1, -1
if w.fd >= 0 {
err := unix.Close(w.fd)
w.fd = -1
@@ -179,13 +170,10 @@ func (w *Watcher) Close() error {
return nil
}
// wake 唤醒正在 poll 的 Run。并发/重复调用安全。
// wake 唤醒正在 poll 的 Run。
func (w *Watcher) wake() {
w.mu.Lock()
fd := w.wakeW
w.mu.Unlock()
if fd >= 0 {
_, _ = unix.Write(fd, []byte{1})
if w.wakeW >= 0 {
_, _ = unix.Write(w.wakeW, []byte{1})
}
}
+11 -9
View File
@@ -80,8 +80,6 @@ func startRunner(t *testing.T, w *Watcher, debounce time.Duration, handler func(
_ = w.NewRunner(debounce, nil).Run(handler, stop)
}()
t.Cleanup(func() {
// 必须先让 Run 退出,再关闭 watcher:反过来会先关掉唤醒管道,
// Stop 的唤醒丢失,Run 会卡在 poll 里直到超时(CI 上偶发)
close(stop)
w.Stop()
select {
@@ -89,7 +87,6 @@ func startRunner(t *testing.T, w *Watcher, debounce time.Duration, handler func(
case <-time.After(2 * time.Second):
t.Error("Run 未能退出")
}
w.Close()
})
return stop
}
@@ -116,6 +113,7 @@ func TestWatchModifyDeliversEvent(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "c"); err != nil {
t.Fatal(err)
}
@@ -146,6 +144,7 @@ func TestCloseWriteLetter(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "w"); err != nil {
t.Fatal(err)
}
@@ -182,6 +181,7 @@ func TestCloseNoWriteLetter(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "0"); err != nil {
t.Fatal(err)
}
@@ -216,26 +216,25 @@ func TestDebounceCoalescesBurst(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "c"); err != nil {
t.Fatal(err)
}
c := &collector{}
// 防抖窗口取大一些:CI 上单次写文件可能耗时数十毫秒,
// 窗口过短会让连写跨越窗口边界,产生第 2 次触发(测试因此偶发失败)
const debounceWindow = 800 * time.Millisecond
startRunner(t, w, debounceWindow, c.add)
startRunner(t, w, 200*time.Millisecond, c.add)
for i := 0; i < 5; i++ {
if err := os.WriteFile(path, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
}
if !waitFor(t, 3*time.Second, func() bool { return len(c.snapshot()) > 0 }) {
if !waitFor(t, 2*time.Second, func() bool { return len(c.snapshot()) > 0 }) {
t.Fatal("未收到事件")
}
time.Sleep(debounceWindow + 400*time.Millisecond) // 等超过一个防抖窗口
time.Sleep(300 * time.Millisecond) // 等超过一个防抖窗口
if got := len(c.snapshot()); got != 1 {
t.Fatalf("防抖后应只触发 1 次, 实际 %d 次", got)
}
@@ -252,6 +251,7 @@ func TestDrainPreventsRecursion(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "c"); err != nil {
t.Fatal(err)
}
@@ -287,6 +287,7 @@ func TestStopExitsBlockingRun(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(path, "c"); err != nil {
t.Fatal(err)
}
@@ -316,6 +317,7 @@ func TestAddMissingPathFails(t *testing.T) {
if err != nil {
t.Skipf("当前环境不支持 inotify: %v", err)
}
defer w.Close()
if err := w.Add(filepath.Join(t.TempDir(), "不存在"), "c"); err == nil {
t.Fatal("监听不存在的路径应报错")
}
+6
View File
@@ -0,0 +1,6 @@
{
"versionCode": 2050052,
"version": "V2.5.0-beta.2",
"zipUrl": "https://github.com/YuleBest/LuminPro/releases/download/v2.5.0-beta.2/LuminPro_V2.5.0-beta.2.zip",
"changelog": "https://raw.githubusercontent.com/YuleBest/LuminPro/beta/changelog.md"
}
+1 -1
View File
@@ -2,7 +2,7 @@
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>LuminPro</title>
<link rel="stylesheet" type="text/css" href="/internal/insets.css" />
</head>
-19
View File
@@ -41,25 +41,6 @@ export function shellQuote(value) {
return `'${String(value).replace(/'/g, "'\\''")}'`
}
/**
* 启用 edge-to-edge:内容延伸至状态栏/手势条区域,insets.css 的
* --window-inset-* / --safe-area-inset-* 随之生效。
*
* 注意:不能直接调用从 npm 包 import 的 enableEdgeToEdge——该绑定总是存在,
* 不支持时是包内部调用 ksu 对象时抛错,会打断后续脚本(FontMM 踩过同样的坑)。
* 这里改为探测全局 ksu 对象,并兼容 KernelSU-Next 的 enableInsets 命名。
*/
export function applyEdgeToEdge() {
try {
const ksuApi = globalThis.ksu
if (!ksuApi) return
const fn = ksuApi.enableEdgeToEdge ?? ksuApi.enableInsets
if (typeof fn === 'function') fn.call(ksuApi, true)
} catch {
/* 老版本没有该 API:布局仍可用,只是安全区取 0 */
}
}
/** 读取模块版本(module.prop 的 version) */
export function moduleVersion() {
try {
+12 -14
View File
@@ -16,18 +16,16 @@ const tabs = [
</script>
<template>
<nav class="bottom-nav">
<md-navigation-bar>
<md-navigation-tab
v-for="tab in tabs"
:key="tab.key"
:label="tab.label"
:active="modelValue === tab.key"
@click="emit('update:modelValue', tab.key)"
>
<component :is="tab.icon" slot="active-icon" :size="24" />
<component :is="tab.icon" slot="inactive-icon" :size="24" />
</md-navigation-tab>
</md-navigation-bar>
</nav>
<md-navigation-bar>
<md-navigation-tab
v-for="tab in tabs"
:key="tab.key"
:label="tab.label"
:active="modelValue === tab.key"
@click="emit('update:modelValue', tab.key)"
>
<component :is="tab.icon" slot="active-icon" :size="24" />
<component :is="tab.icon" slot="inactive-icon" :size="24" />
</md-navigation-tab>
</md-navigation-bar>
</template>
-2
View File
@@ -1,5 +1,4 @@
import { createApp } from 'vue'
import { applyEdgeToEdge } from './api/ksu.js'
import './mwc.js'
import './theme/tokens.css'
@@ -9,5 +8,4 @@ import './theme/app.css'
import App from './App.vue'
applyEdgeToEdge()
createApp(App).mount('#app')
+3 -12
View File
@@ -138,20 +138,11 @@
}
/* ── M3 导航栏 ────────────────────────────────────────────────────── */
/* 底栏容器:色块填充法——容器背景延伸至屏幕最底部,手势导航条区域
与导航栏同色;内边距把导航内容抬到手势条之上。
安全区变量在不同 KernelSU 版本命名不同,最后兜底 env()。 */
.bottom-nav {
flex: 0 0 auto;
background-color: var(--md-sys-color-surface-container);
padding-bottom: var(--safe-area-inset-bottom, var(--window-inset-bottom, env(safe-area-inset-bottom, 0px)));
}
md-navigation-bar {
flex: 0 0 auto;
/* 背景延伸到屏幕底部,内容抬到手势条之上 */
padding-bottom: var(--safe-area-inset-bottom, var(--window-inset-bottom, 0px));
--md-navigation-bar-container-color: var(--md-sys-color-surface-container);
/* 去掉容器阴影:手势条区域用同色填充,阴影会在底部露出一条边 */
--md-navigation-bar-container-elevation: 0;
box-shadow: none;
--md-navigation-bar-active-indicator-color: var(--md-sys-color-secondary-container);
--md-navigation-bar-active-icon-color: var(--md-sys-color-on-secondary-container);
--md-navigation-bar-active-label-text-color: var(--md-sys-color-on-surface);
+1 -99
View File
@@ -12,58 +12,11 @@ let renderMarkdown = null
async function ensureMarkdown() {
if (renderMarkdown) return renderMarkdown
const { default: MarkdownIt } = await import('markdown-it')
// README 使用了 HTML 与 GitHub 提示块(> [!TIP]),需要一并支持
const md = new MarkdownIt({ html: true, linkify: true, breaks: true })
md.core.ruler.push('github-alerts', (state) => {
const tokens = state.tokens
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i]
if (token.type !== 'blockquote_open') continue
const inline = tokens[i + 2]
if (!inline || inline.type !== 'inline') continue
const match = /^\[!([A-Z]+)\]\s*/.exec(inline.content)
if (!match) continue
const kind = match[1].toLowerCase()
const label = ALERT_LABELS[kind]
if (!label) continue
token.attrJoin('class', `md-alert md-alert--${kind}`)
inline.content = inline.content.replace(match[0], '')
inline.children[0].content = inline.children[0].content.replace(match[0], '')
const marker = new state.Token('html_block', '', 0)
marker.content = `<p class="md-alert__title">${label}</p>`
const closeIdx = findBlockquoteClose(tokens, i)
if (closeIdx > 0) tokens.splice(closeIdx, 0, marker)
}
return true
})
const md = new MarkdownIt({ html: false, linkify: true, breaks: true })
renderMarkdown = (text) => md.render(text)
return renderMarkdown
}
/** GitHub 提示块的标题文案 */
const ALERT_LABELS = {
note: '备注',
tip: '提示',
important: '重要',
warning: '警告',
caution: '注意',
}
/** 找到与 openIdx 配对的 blockquote_close 下标 */
function findBlockquoteClose(tokens, openIdx) {
let depth = 0
for (let i = openIdx; i < tokens.length; i++) {
if (tokens[i].type === 'blockquote_open') depth++
else if (tokens[i].type === 'blockquote_close') {
depth--
if (depth === 0) return i
}
}
return -1
}
const docs = [
{ key: 'README.md', label: '模块说明', icon: BookOpen },
{ key: 'changelog.md', label: '更新日志', icon: ScrollText },
@@ -191,57 +144,6 @@ async function openLink(url) {
</template>
<style scoped>
/* GitHub 提示块(> [!TIP] 等) */
.markdown :deep(.md-alert) {
margin: 0 0 var(--md-sys-spacing-3);
padding: var(--md-sys-spacing-3);
border-radius: var(--md-sys-shape-corner-small);
border-inline-start: 4px solid var(--md-sys-color-primary);
background-color: var(--md-sys-color-surface-container);
}
.markdown :deep(.md-alert__title) {
margin: 0 0 4px;
font-weight: 600;
color: var(--md-sys-color-primary);
}
.markdown :deep(.md-alert--tip) {
border-inline-start-color: var(--lp-color-success);
}
.markdown :deep(.md-alert--tip .md-alert__title) {
color: var(--lp-color-success);
}
.markdown :deep(.md-alert--warning),
.markdown :deep(.md-alert--caution) {
border-inline-start-color: var(--lp-color-warning);
}
.markdown :deep(.md-alert--warning .md-alert__title),
.markdown :deep(.md-alert--caution .md-alert__title) {
color: var(--lp-color-warning);
}
.markdown :deep(.md-alert--important) {
border-inline-start-color: var(--md-sys-color-error);
}
.markdown :deep(.md-alert--important .md-alert__title) {
color: var(--md-sys-color-error);
}
/* README 的居中容器与徽章 */
.markdown :deep([align='center']) {
text-align: center;
}
.markdown :deep(img) {
max-width: 100%;
height: auto;
}
.about-meta {
display: flex;
flex-wrap: wrap;
+1 -22
View File
@@ -156,26 +156,6 @@ function stopPolling() {
}
}
/**
* 需要忽略的前台活动:WebUI 自身、系统桌面(切换应用的瞬间会被抓到)、
* 输入法、权限弹窗等系统界面。
*/
const IGNORED_ACTIVITY_PATTERNS = [
/webui/i,
// 系统桌面(各厂商 launcher)
/(^|\.)launcher/i,
/com\.android\.systemui/i,
/\/com\.android\.internal\.app\.Launcher/i,
// 输入法与系统弹窗
/\.inputmethod\./i,
/com\.android\.permissioncontroller/i,
/com\.android\.settings\/com\.android\.settings\.(FallbackHome|Settings)/i,
]
function isIgnoredActivity(activity) {
return IGNORED_ACTIVITY_PATTERNS.some((pattern) => pattern.test(activity))
}
function startPolling() {
pickerPolling.value = true
pickerStatus.value = '检测中,请切换到目标界面...'
@@ -184,8 +164,7 @@ function startPolling() {
try {
const res = await fetchFocus()
const activity = (res.focus || '').trim()
// 空值、WebUI 自身、桌面等系统界面都继续等待
if (!activity || isIgnoredActivity(activity)) return
if (!activity || activity.toLowerCase().includes('webui')) return
stopPolling()
pickerPolling.value = false
pickerResult.value = activity
+1 -6
View File
@@ -41,11 +41,6 @@ async function openHelp() {
helpDialog.value?.show()
}
function closeHelp() {
helpDialog.value?.close()
helpOpen.value = false
}
// ── 定时休眠:HHMM 起止时间 ────────────────────────────────────────
const sleepStart = computed(() => config.sleepParts.value[0] + config.sleepParts.value[1])
const sleepEnd = computed(() => config.sleepParts.value[2] + config.sleepParts.value[3])
@@ -321,7 +316,7 @@ async function confirmReset() {
<div slot="headline">支持的事件字母</div>
<pre slot="content" class="help-text">{{ INOTIFY_HELP }}</pre>
<div slot="actions">
<md-filled-button @click="closeHelp">知道了</md-filled-button>
<md-filled-button @click="helpOpen = false">知道了</md-filled-button>
</div>
</md-dialog>
</template>
+8 -62
View File
@@ -44,86 +44,33 @@ async function refresh() {
snackbar('已刷新')
}
let lastApplied = null
/** 拖动中节流:距上次应用超过 3% 才写一次节点,避免每个像素都 exec */
const DRAG_APPLY_STEP_PERCENT = 3
/** 低亮度保护:低于该比例视为伪黑屏风险,需用户确认后才允许 */
const MIN_PERCENT = 5
/** 用户确认过本次会话的低亮度设置(确认后不再重复拦截) */
const lowConfirmed = ref(false)
/** 5% 对应的亮度值,向上取整 */
const lowFloor = computed(() => Math.ceil(((maxBrightness.value || 255) * MIN_PERCENT) / 100))
/** 把滑条与已应用值拉回安全下限 */
function snapToFloor() {
if (sliderEl.value) sliderEl.value.value = lowFloor.value
return lowFloor.value
}
async function applyBrightness(value, { silent = false } = {}) {
async function applyBrightness(value) {
try {
await status.setBrightness(value)
lastApplied = value
// 回到安全区以上后重置确认状态:下次再往下滑会重新提醒
// 注意用严格大于:确认后应用的就是下限值本身,等于时不应重置
if (value > lowFloor.value) lowConfirmed.value = false
if (!silent) snackbar(`亮度已设为 ${value}`)
snackbar(`亮度已设为 ${value}`)
} catch (e) {
if (!silent) snackbar(`设置失败: ${e.message}`)
snackbar(`设置失败: ${e.message}`)
}
}
/** 拖动过程中(input 事件):先做低亮度拦截,再按比例节流应用 */
async function onSliderInput(event) {
const value = Number(event.target.value)
const max = maxBrightness.value || 255
// 低亮度保护:未确认前直接拦在安全下限,避免滑到伪黑屏
if (!lowConfirmed.value && value < lowFloor.value) {
const floored = snapToFloor()
if (!confirmLowOpen.value) {
pendingValue.value = floored
confirmLowOpen.value = true
}
return
}
if (lastApplied === null) {
lastApplied = currentBrightness.value
}
const step = (max * DRAG_APPLY_STEP_PERCENT) / 100
if (Math.abs(value - lastApplied) < step) return
await applyBrightness(value, { silent: true })
}
async function onSliderChange(event) {
const value = Number(event.target.value)
// 未确认低亮度时,松手也不允许落在安全下限之下
if (!lowConfirmed.value && value < lowFloor.value) {
pendingValue.value = lowFloor.value
snapToFloor()
const pct = Math.round((value / maxBrightness.value) * 100)
if (pct < 5) {
pendingValue.value = value
confirmLowOpen.value = true
return
}
await applyBrightness(value)
lastApplied = value
}
/** 取消:保持在安全下限,不写节点 */
function cancelLow() {
confirmLowOpen.value = false
if (sliderEl.value) sliderEl.value.value = lowFloor.value
if (sliderEl.value) sliderEl.value.value = currentBrightness.value
}
/** 确认:本次会话放开低亮度限制,并应用目标值 */
async function confirmLow() {
confirmLowOpen.value = false
lowConfirmed.value = true
await applyBrightness(pendingValue.value)
}
</script>
@@ -171,7 +118,6 @@ async function confirmLow() {
:max="maxBrightness"
:value="currentBrightness"
labeled
@input="onSliderInput"
@change="onSliderChange"
></md-slider>
</div>
@@ -184,7 +130,7 @@ async function confirmLow() {
<ConfirmDialog
:open="confirmLowOpen"
headline="亮度低于 5%"
:description="`低于 ${MIN_PERCENT}% 可能让屏幕看起来像黑屏。\n确认后将临时放开该限制。`"
description="继续可能让屏幕接近黑屏,确定要设置吗?"
confirm-text="仍然设置"
danger
@confirm="confirmLow"