8 Commits
7 changed files with 84 additions and 30 deletions

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# 更新日志
## V2.5.0-beta.6
- 修复: 亮度滑条的低亮度保护失效——现在拖动中即拦在 5% 安全下限,确认后才放开
- 修复: 高级设置「支持的事件」弹窗的「知道了」按钮无法关闭
## V2.5.0-beta.5
- 修复: 导航栏容器阴影在手势条区域露出一条边(关闭该阴影,与色块填充保持一致)
+19 -7
View File
@@ -155,13 +155,22 @@ func (w *Watcher) Add(path, letters string) error {
return nil
}
// Close 释放资源。
// Close 释放资源。重复调用安全。
func (w *Watcher) Close() error {
w.mu.Lock()
defer w.mu.Unlock()
_ = unix.Close(w.wakeR)
_ = unix.Close(w.wakeW)
w.wakeR, w.wakeW = -1, -1
// 先唤醒 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
}
if w.fd >= 0 {
err := unix.Close(w.fd)
w.fd = -1
@@ -170,10 +179,13 @@ func (w *Watcher) Close() error {
return nil
}
// wake 唤醒正在 poll 的 Run。
// wake 唤醒正在 poll 的 Run。并发/重复调用安全。
func (w *Watcher) wake() {
if w.wakeW >= 0 {
_, _ = unix.Write(w.wakeW, []byte{1})
w.mu.Lock()
fd := w.wakeW
w.mu.Unlock()
if fd >= 0 {
_, _ = unix.Write(fd, []byte{1})
}
}
+9 -11
View File
@@ -80,6 +80,8 @@ 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 {
@@ -87,6 +89,7 @@ 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
}
@@ -113,7 +116,6 @@ 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)
}
@@ -144,7 +146,6 @@ 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)
}
@@ -181,7 +182,6 @@ 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,25 +216,26 @@ 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{}
startRunner(t, w, 200*time.Millisecond, c.add)
// 防抖窗口取大一些:CI 上单次写文件可能耗时数十毫秒,
// 窗口过短会让连写跨越窗口边界,产生第 2 次触发(测试因此偶发失败)
const debounceWindow = 800 * time.Millisecond
startRunner(t, w, debounceWindow, 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, 2*time.Second, func() bool { return len(c.snapshot()) > 0 }) {
if !waitFor(t, 3*time.Second, func() bool { return len(c.snapshot()) > 0 }) {
t.Fatal("未收到事件")
}
time.Sleep(300 * time.Millisecond) // 等超过一个防抖窗口
time.Sleep(debounceWindow + 400*time.Millisecond) // 等超过一个防抖窗口
if got := len(c.snapshot()); got != 1 {
t.Fatalf("防抖后应只触发 1 次, 实际 %d 次", got)
}
@@ -251,7 +252,6 @@ 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,7 +287,6 @@ 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)
}
@@ -317,7 +316,6 @@ 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("监听不存在的路径应报错")
}
+2 -2
View File
@@ -1,7 +1,7 @@
id=LuminPro
name=LuminPro丨日用屏幕亮度强化
version=V2.5.0-beta.5
versionCode=2050055
version=V2.5.0-beta.6
versionCode=2050056
author=酷安@Yule
description=本模块旨在让你的 Android 设备随时可以使用高亮度显示屏幕内容。无论设备当前亮度如何,只要满足设定的前台触发亮度条件,模块便会自动且平滑地提升屏幕亮度至硬件支持的峰值状态,确保你在强光室外也能获得清晰的显示效果
updateJson=https://raw.githubusercontent.com/YuleBest/LuminPro/main/update.json
+3 -3
View File
@@ -1,6 +1,6 @@
{
"versionCode": 2050055,
"version": "V2.5.0-beta.5",
"zipUrl": "https://github.com/YuleBest/LuminPro/releases/download/v2.5.0-beta.5/LuminPro_V2.5.0-beta.5.zip",
"versionCode": 2050056,
"version": "V2.5.0-beta.6",
"zipUrl": "https://github.com/YuleBest/LuminPro/releases/download/v2.5.0-beta.6/LuminPro_V2.5.0-beta.6.zip",
"changelog": "https://raw.githubusercontent.com/YuleBest/LuminPro/beta/changelog.md"
}
+6 -1
View File
@@ -41,6 +41,11 @@ 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])
@@ -316,7 +321,7 @@ async function confirmReset() {
<div slot="headline">支持的事件字母</div>
<pre slot="content" class="help-text">{{ INOTIFY_HELP }}</pre>
<div slot="actions">
<md-filled-button @click="helpOpen = false">知道了</md-filled-button>
<md-filled-button @click="closeHelp">知道了</md-filled-button>
</div>
</md-dialog>
</template>
+40 -6
View File
@@ -49,20 +49,48 @@ 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 } = {}) {
try {
await status.setBrightness(value)
lastApplied = value
// 回到安全区以上后重置确认状态:下次再往下滑会重新提醒
// 注意用严格大于:确认后应用的就是下限值本身,等于时不应重置
if (value > lowFloor.value) lowConfirmed.value = false
if (!silent) snackbar(`亮度已设为 ${value}`)
} catch (e) {
if (!silent) snackbar(`设置失败: ${e.message}`)
}
}
/** 拖动过程中(input 事件)按比例阈值应用 */
/** 拖动过程中(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
}
@@ -73,23 +101,29 @@ async function onSliderInput(event) {
async function onSliderChange(event) {
const value = Number(event.target.value)
const pct = Math.round((value / maxBrightness.value) * 100)
if (pct < 5) {
pendingValue.value = value
// 未确认低亮度时,松手也不允许落在安全下限之下
if (!lowConfirmed.value && value < lowFloor.value) {
pendingValue.value = lowFloor.value
snapToFloor()
confirmLowOpen.value = true
return
}
await applyBrightness(value)
lastApplied = value
}
/** 取消:保持在安全下限,不写节点 */
function cancelLow() {
confirmLowOpen.value = false
if (sliderEl.value) sliderEl.value.value = currentBrightness.value
if (sliderEl.value) sliderEl.value.value = lowFloor.value
}
/** 确认:本次会话放开低亮度限制,并应用目标值 */
async function confirmLow() {
confirmLowOpen.value = false
lowConfirmed.value = true
await applyBrightness(pendingValue.value)
}
</script>
@@ -150,7 +184,7 @@ async function confirmLow() {
<ConfirmDialog
:open="confirmLowOpen"
headline="亮度低于 5%"
description="继续可能让屏幕接近黑屏,确定要设置吗?"
:description="`低于 ${MIN_PERCENT}% 可能让屏幕看起来像黑屏。\n确认后将临时放开该限制。`"
confirm-text="仍然设置"
danger
@confirm="confirmLow"