diff --git a/build-module.js b/build-module.js index 7c76b05..0541dbe 100644 --- a/build-module.js +++ b/build-module.js @@ -10,7 +10,7 @@ const version = versionMatch ? versionMatch[1].trim() : 'Unknown'; const versionCodeStr = versionCodeMatch ? versionCodeMatch[1].trim() : '0000'; const versionCode = parseInt(versionCodeStr, 10); -const zipName = `LuminPro_${version}-${versionCode}.zip`; +const zipName = `LuminPro_${version}.zip`; // --- 新增: 自动同步 update.json --- const updateJsonPath = 'update.json'; diff --git a/changelog.md b/changelog.md index b2ab26c..8ba7836 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +## v2.2-2208 + +- 新增: 黑名单功能,可在指定应用内禁止模块工作 +- 新增: Web UI 日志导出、复制功能 +- 优化: Web UI 外观 +- 优化: 日志信息 + ## V2.2-2204 - 新增: `boost.sh` 脚本,支持一键将亮度提升至峰值极限 diff --git a/config/display_hdr_sleep.txt b/config/display_hdr_sleep.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/config/display_hdr_sleep.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/customize.sh b/customize.sh index e79cb97..151773e 100755 --- a/customize.sh +++ b/customize.sh @@ -294,6 +294,7 @@ IMPORT_OLD_CONFIG() { [ -s "$old_config/steps_num.txt" ] && cp -f "$old_config/steps_num.txt" "$mod_config/" [ -s "$old_config/log_max_size.txt" ] && cp -f "$old_config/log_max_size.txt" "$mod_config/" [ -s "$old_config/blacklist_apps.txt" ] && cp -f "$old_config/blacklist_apps.txt" "$mod_config/" + [ -s "$old_config/display_hdr_sleep.txt" ] && cp -f "$old_config/display_hdr_sleep.txt" "$mod_config/" # 迁移旧的路径配置(如果存在) mkdir -p "$mod_path_config" @@ -340,6 +341,7 @@ INIT_CONFIG() { [ ! -f "$mod_config/steps_num.txt" ] && touch "$mod_config/steps_num.txt" [ ! -f "$mod_config/log_max_size.txt" ] && touch "$mod_config/log_max_size.txt" [ ! -f "$mod_config/blacklist_apps.txt" ] && touch "$mod_config/blacklist_apps.txt" + [ ! -f "$mod_config/display_hdr_sleep.txt" ] && touch "$mod_config/display_hdr_sleep.txt" # 初始化设备路径配置 (仅在文件不存在时使用默认值,保留用户自定义配置) [ ! -f "$mod_path_config/now_bri_file.txt" ] && echo -n "$DEFAULT_NOW_BRI_FILE" >"$mod_path_config/now_bri_file.txt" @@ -384,6 +386,7 @@ CREATE_BACKUP() { cp -f "$mod_config/steps_num.txt" "$mod_config/.backup/" cp -f "$mod_config/log_max_size.txt" "$mod_config/.backup/" cp -f "$mod_config/blacklist_apps.txt" "$mod_config/.backup/" + cp -f "$mod_config/display_hdr_sleep.txt" "$mod_config/.backup/" } # 主函数 diff --git a/module.prop b/module.prop index c017290..baebe9c 100755 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=LuminPro name=LuminPro丨日用屏幕亮度强化 -version=V2.2 -versionCode=2204 +version=V2.2-2208 +versionCode=2208 author=酷安@Yule description=本模块旨在让你的 Android 设备随时可以使用高亮度显示屏幕内容。无论设备当前亮度如何,只要满足设定的前台触发亮度条件,模块便会自动且平滑地提升屏幕亮度至硬件支持的峰值状态,确保你在强光室外也能获得清晰的显示效果 updateJson=https://share.yule.ink/magisk/mod/luminpro/update.json \ No newline at end of file diff --git a/script/up.sh b/script/up.sh index 9e55930..cd670b2 100644 --- a/script/up.sh +++ b/script/up.sh @@ -77,6 +77,7 @@ ui_max_bri="$(cat "$CONFIG_DIR/ui_max_bri.txt")" max_bri="$(cat "$CONFIG_DIR/max_bri.txt")" sleep_time="$(cat "$CONFIG_DIR/sleep_time.txt" 2>/dev/null)" auto_bri_sleep="$(cat "$CONFIG_DIR/auto_bri_sleep.txt" 2>/dev/null)" +display_hdr_sleep="$(cat "$CONFIG_DIR/display_hdr_sleep.txt" 2>/dev/null)" # 解析休眠时间 (格式: HHMM-HHMM, 例如 1900-0600) sleep_start="${sleep_time%-*}" # 1900 @@ -161,7 +162,7 @@ MAIN() { # 解析并判断休眠 if IS_SLEEP_TIME; then _log "处于休眠时段 ($sleep_start-$sleep_end),跳过提升" "INFO" - rm -f "$flag_file" + rm -f "$flag_file" "$pause_file" return fi @@ -169,23 +170,63 @@ MAIN() { mode="$(settings get system screen_brightness_mode 2>/dev/null)" if [ "$mode" = "1" ]; then _log "自动亮度已启用,跳过提升" "INFO" - rm -f "$flag_file" + rm -f "$flag_file" "$pause_file" return fi fi - # 黑名单应用检测 + # 黑名单应用检测(支持包名和完整 package/activity 两种格式) local blacklist_file="$CONFIG_DIR/blacklist_apps.txt" if [ -f "$blacklist_file" ] && [ -s "$blacklist_file" ]; then - local current_app - current_app="$(dumpsys window | grep mCurrentFocus | sed 's/.*u0 \(.*\)\/.*/\1/')" - if [ -n "$current_app" ] && grep -qxF "$current_app" "$blacklist_file"; then - _log "当前前台应用 ($current_app) 在黑名单中,跳过提升" "INFO" - rm -f "$flag_file" + local current_focus current_app + current_focus="$(dumpsys window | grep mCurrentFocus | sed 's/.*u0 \(.*\)}/\1/')" + current_app="${current_focus%%/*}" + if [ -n "$current_focus" ] && { grep -qxF "$current_focus" "$blacklist_file" || grep -qxF "$current_app" "$blacklist_file"; }; then + _log "当前前台 ($current_focus) 在黑名单中,跳过提升" "INFO" + rm -f "$flag_file" "$pause_file" return fi fi + # 显示 HDR 内容时休眠 + if [ "$display_hdr_sleep" = "1" ]; then + local hdr_flag_file="$PID_DIR/hdr.flag" + # 冷却期检查:读取写入时间戳,判断是否在 2 秒内 + if [ -f "$hdr_flag_file" ]; then + local flag_time now + flag_time="$(cat "$hdr_flag_file")" + now="$(date +%s)" + if awk "BEGIN{exit !(($now - $flag_time) < 2)}" 2>/dev/null; then + _log "HDR 冷却期内,跳过提升" "INFO" + rm -f "$flag_file" "$pause_file" + return + else + rm -f "$hdr_flag_file" # 冷却期已过,清理 + fi + fi + local hdr_ratio hdr_ratio_rounded + local hdr_cache_file="$PID_DIR/.hdr_ratio_cache" + hdr_ratio="$(dumpsys display 2>/dev/null | sed -n 's/.*hdrSdrRatio \([0-9.]*\).*/\1/p' | head -n 1)" + if echo "$hdr_ratio" | grep -qE '^[0-9]+\.[0-9]+$'; then + # 读取成功,更新缓存 + echo -n "$hdr_ratio" >"$hdr_cache_file" + elif [ -f "$hdr_cache_file" ]; then + # 读取为空,使用上次缓存 + hdr_ratio="$(cat "$hdr_cache_file")" + _log "HDR 比率读取为空,使用缓存值: $hdr_ratio" "INFO" + fi + if echo "$hdr_ratio" | grep -qE '^[0-9]+\.[0-9]+$'; then + hdr_ratio_rounded="$(awk "BEGIN{printf \"%.2f\", $hdr_ratio}")" + if awk "BEGIN{exit !($hdr_ratio_rounded > 1.00)}" 2>/dev/null; then + _log "检测到 HDR 内容 (比率: $hdr_ratio_rounded),跳过提升" "INFO" + # 写入当前时间戳作为冷却期起点(2 秒内再次触发直接跳过) + date +%s >"$hdr_flag_file" + rm -f "$flag_file" "$pause_file" + return + fi + fi + fi + _log "正在检测亮度变化..." "INFO" # sleep 0.5 CHECK_BRI diff --git a/service.sh b/service.sh index 19a3f23..25b240a 100755 --- a/service.sh +++ b/service.sh @@ -29,6 +29,9 @@ _log() { # 等待系统就绪 sleep 30 +# 清理上次遗留的标记文件 +rm -f "$MODDIR/pid/"*.flag "$MODDIR/pid/"*.pause "$MODDIR/pid/.hdr_ratio_cache" + _log "LuminPro 服务启动" "INFO" _log "前台最大亮度: $(cat "$CONFIG_DIR/ui_max_bri.txt")" "INFO" _log "峰值最大亮度: $(cat "$CONFIG_DIR/max_bri.txt")" "INFO" diff --git a/update.json b/update.json index c1f8139..6732032 100644 --- a/update.json +++ b/update.json @@ -1,6 +1,6 @@ { - "versionCode": 2204, - "version": "V2.2", - "zipUrl": "https://share.yule.ink/magisk/mod/luminpro/module/LuminPro_V2.2-2204.zip", + "versionCode": 2208, + "version": "V2.2-2208", + "zipUrl": "https://share.yule.ink/magisk/mod/luminpro/module/LuminPro_V2.2-2208.zip", "changelog": "https://share.yule.ink/magisk/mod/luminpro/changelog.md" } \ No newline at end of file diff --git a/webroot/index.html b/webroot/index.html index 3ccc179..29d4edd 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -6,8 +6,8 @@ LuminPro - - + + @@ -21,7 +21,7 @@

LuminPro

日用屏幕亮度强化

-

V2.2-2204

+

V2.2-2208

@@ -46,32 +46,46 @@
- + 当前亮度
—
- + 系统最大亮度
—
- + inotifyd PID
—
- + + inotifyd 状态 +
+ — +
+
+
+ 休眠状态
—
+
+
+ + HDR/SDR 比率 +
+ — +
@@ -148,6 +162,19 @@
+
+
+ 显示 HDR 内容时休眠 + HDR/SDR 比率 > 1 时不提升 + 建议配合去温控使用(部分系统温控策略较严格,高温时可能不显示 HDR 但仍提升亮度,导致闪屏。出现此情况时,可以使用活动黑名单/应用黑名单功能) +
+
+ +
+
定时休眠 @@ -213,6 +240,7 @@
inotifyd 监听事件 默认 c。修改需重启服务 + 为避免性能消耗,修改为 c 以外的事件时建议关闭 Web UI 配置 - 自动刷新
@@ -255,6 +283,15 @@

界面设置

+
+ 自动刷新 + 定时刷新状态和日志。监听非 c 事件时建议关闭 +
+
+ +
+
+
状态/日志刷新间隔 单位: 毫秒 (最小100ms) @@ -325,6 +362,15 @@ 推荐选择视频类、相册等需展示 HDR 内容的应用

+ +
+ 按活动屏蔽 +
+ + +
+
+
@@ -344,7 +390,7 @@

运行日志

-
+
加载中...
diff --git a/webui/index.html b/webui/index.html index c136183..067c975 100644 --- a/webui/index.html +++ b/webui/index.html @@ -20,7 +20,7 @@

LuminPro

日用屏幕亮度强化

-

V2.2-2204

+

V2.2-2208

@@ -45,32 +45,46 @@
- + 当前亮度
—
- + 系统最大亮度
—
- + inotifyd PID
—
- + + inotifyd 状态 +
+ — +
+
+
+ 休眠状态
—
+
+
+ + HDR/SDR 比率 +
+ — +
@@ -147,6 +161,19 @@
+
+
+ 显示 HDR 内容时休眠 + HDR/SDR 比率 > 1 时不提升 + 建议配合去温控使用(部分系统温控策略较严格,高温时可能不显示 HDR 但仍提升亮度,导致闪屏。出现此情况时,可以使用活动黑名单/应用黑名单功能) +
+
+ +
+
定时休眠 @@ -212,6 +239,7 @@
inotifyd 监听事件 默认 c。修改需重启服务 + 为避免性能消耗,修改为 c 以外的事件时建议关闭 Web UI 配置 - 自动刷新
@@ -254,6 +282,15 @@

界面设置

+
+ 自动刷新 + 定时刷新状态和日志。监听非 c 事件时建议关闭 +
+
+ +
+
+
状态/日志刷新间隔 单位: 毫秒 (最小100ms) @@ -324,6 +361,15 @@ 推荐选择视频类、相册等需展示 HDR 内容的应用

+ +
+ 按活动屏蔽 +
+ + +
+
+
diff --git a/webui/src/main.js b/webui/src/main.js index de02941..1a523d0 100644 --- a/webui/src/main.js +++ b/webui/src/main.js @@ -26,6 +26,7 @@ let configRefreshInterval = 5000; // 配置卡片刷新间隔(默认5秒) let autoRefreshStatusLogTimer = null; // 状态/日志刷新定时器 let autoRefreshConfigTimer = null; // 配置刷新定时器 let uiZoom = 100; // 界面缩放百分比 (50-150) +let autoRefresh = true; // 自动刷新开关(默认开启) // ========================== // 工具函数 @@ -102,13 +103,14 @@ async function loadConfig() { // 然后加载其他配置 - const [uiRes, maxRes, sleepRes, autoRes, stepsRes, logSizeRes] = await Promise.all([ + const [uiRes, maxRes, sleepRes, autoRes, stepsRes, logSizeRes, hdrSleepRes] = await Promise.all([ runCmd(`cat "${CONFIG_DIR}/ui_max_bri.txt"`), runCmd(`cat "${CONFIG_DIR}/max_bri.txt"`), runCmd(`cat "${CONFIG_DIR}/sleep_time.txt"`), runCmd(`cat "${CONFIG_DIR}/auto_bri_sleep.txt"`), runCmd(`cat "${CONFIG_DIR}/steps_num.txt"`), - runCmd(`cat "${CONFIG_DIR}/log_max_size.txt"`) + runCmd(`cat "${CONFIG_DIR}/log_max_size.txt"`), + runCmd(`cat "${CONFIG_DIR}/display_hdr_sleep.txt"`) ]); if (uiRes.errno === 0) document.getElementById('input-ui-max-bri').value = uiRes.stdout.trim(); @@ -147,6 +149,7 @@ async function loadConfig() { } if (autoRes.errno === 0) document.getElementById('input-auto-bri-sleep').checked = autoRes.stdout.trim() === '1'; + if (hdrSleepRes.errno === 0) document.getElementById('input-display-hdr-sleep').checked = hdrSleepRes.stdout.trim() === '1'; if (stepsRes.errno === 0) { const v = stepsRes.stdout.trim(); document.getElementById('input-steps-num').value = v ? v : '50'; @@ -174,6 +177,14 @@ async function loadConfig() { document.getElementById('input-status-refresh-interval').value = statusLogRefreshInterval; document.getElementById('input-config-refresh-interval').value = configRefreshInterval; + const savedAutoRefresh = localStorage.getItem('autoRefresh'); + if (savedAutoRefresh !== null) autoRefresh = savedAutoRefresh !== 'false'; + const autoRefreshToggle = document.getElementById('input-auto-refresh'); + if (autoRefreshToggle) { + autoRefreshToggle.checked = autoRefresh; + document.getElementById('item-status-refresh-interval').style.display = autoRefresh ? '' : 'none'; + } + const uiZoomInput = document.getElementById('input-ui-zoom'); if (uiZoomInput) uiZoomInput.value = uiZoom; applyUIZoom(uiZoom); @@ -197,6 +208,7 @@ async function saveConfig() { } const autoBriSleep = document.getElementById('input-auto-bri-sleep').checked ? '1' : '0'; + const displayHdrSleep = document.getElementById('input-display-hdr-sleep').checked ? '1' : '0'; const stepsNum = document.getElementById('input-steps-num').value || '50'; const logMaxSize = document.getElementById('input-log-max-size').value || '500'; @@ -212,6 +224,7 @@ async function saveConfig() { await writeFile(`${CONFIG_DIR}/max_bri.txt`, maxBri); await writeFile(`${CONFIG_DIR}/sleep_time.txt`, sleepTime); await writeFile(`${CONFIG_DIR}/auto_bri_sleep.txt`, autoBriSleep); + await writeFile(`${CONFIG_DIR}/display_hdr_sleep.txt`, displayHdrSleep); await writeFile(`${CONFIG_DIR}/steps_num.txt`, stepsNum); await writeFile(`${CONFIG_DIR}/log_max_size.txt`, logMaxSize); @@ -254,12 +267,13 @@ async function saveAdvancedConfig() { // 2.3 保存 Web UI 配置 function saveWebUIConfig() { + const newAutoRefresh = document.getElementById('input-auto-refresh').checked; const statusRefresh = parseInt(document.getElementById('input-status-refresh-interval').value, 10) || 1000; const configRefresh = parseInt(document.getElementById('input-config-refresh-interval').value, 10) || 5000; const zoom = parseInt(document.getElementById('input-ui-zoom').value, 10) || 100; // 验证最小值 - if (statusRefresh < 100) { + if (newAutoRefresh && statusRefresh < 100) { showToast('状态/日志刷新间隔最小为100ms'); document.getElementById('input-status-refresh-interval').value = 100; return; @@ -271,18 +285,20 @@ function saveWebUIConfig() { } // 保存到 localStorage + localStorage.setItem('autoRefresh', newAutoRefresh); localStorage.setItem('statusLogRefreshInterval', statusRefresh); localStorage.setItem('configRefreshInterval', configRefresh); localStorage.setItem('uiZoom', zoom); // 更新全局变量 + autoRefresh = newAutoRefresh; statusLogRefreshInterval = statusRefresh; configRefreshInterval = configRefresh; uiZoom = zoom; // 重启刷新循环 stopAutoRefresh(); - startAutoRefresh(); + if (autoRefresh) startAutoRefresh(); applyUIZoom(zoom); showToast('Web UI 配置已保存'); @@ -425,14 +441,29 @@ async function loadStatus(forceFull = false) { else cachedSysMaxBri = '255'; } - const [pidRes, stopRes, autoBriRes] = await Promise.all([ + const [pidRes, stopRes, autoBriRes, hdrRes] = await Promise.all([ runCmd(`cat "${PID_FILE}"`), runCmd(`[ -f "${STOP_FLAG_FILE}" ] && echo "1" || echo "0"`), - runCmd(`settings get system screen_brightness_mode`) + runCmd(`settings get system screen_brightness_mode`), + runCmd(`dumpsys display 2>/dev/null | sed -n 's/.*hdrSdrRatio \\([0-9.]*\\).*/\\1/p' | head -n 1`) ]); const isPaused = stopRes.errno === 0 && stopRes.stdout.trim() === '1'; const running = pidRes.errno === 0 && pidRes.stdout.trim(); + + // 获取 inotifyd 进程状态 + let inotifydState = '—'; + if (running) { + const pid = pidRes.stdout.trim(); + const stateRes = await runCmd(`cat /proc/${pid}/status 2>/dev/null | grep "State:" | sed 's/.*(\(.*\))/\\1/'`); + if (stateRes.errno === 0 && stateRes.stdout.trim()) { + inotifydState = stateRes.stdout.trim(); + } else { + inotifydState = '已退出'; + } + } else { + inotifydState = '离线'; + } const statusDot = document.querySelector('.header-status .status-dot'); const statusText = document.querySelector('.header-status .status-text'); @@ -467,6 +498,16 @@ async function loadStatus(forceFull = false) { document.getElementById('status-current-bri').textContent = currentBri; document.getElementById('status-sys-max-bri').textContent = cachedSysMaxBri || '—'; document.getElementById('status-inotifyd-pid').textContent = running ? pidRes.stdout.trim() : '离线'; + document.getElementById('status-inotifyd-state').textContent = inotifydState; + + // HDR/SDR 比率 + const hdrRaw = hdrRes.errno === 0 ? hdrRes.stdout.trim() : ''; + const hdrEl = document.getElementById('status-hdr-ratio'); + if (hdrRaw && /^\d+(\.\d+)?$/.test(hdrRaw)) { + hdrEl.textContent = parseFloat(hdrRaw).toFixed(2); + } else { + hdrEl.textContent = '-'; + } // 更新亮度滑条 const brightnessSlider = document.getElementById('brightness-slider'); @@ -747,6 +788,8 @@ async function startAutoRefresh() { // 立即执行一次状态/日志刷新 await Promise.all([loadStatus(true), loadLogs()]); + if (!autoRefresh) return; + // 启动定时刷新 autoRefreshStatusLogTimer = setTimeout(startAutoRefreshStatusLog, statusLogRefreshInterval); autoRefreshConfigTimer = setTimeout(startAutoRefreshConfig, configRefreshInterval); @@ -934,15 +977,37 @@ function setupNavbar() { let showingSystemApps = true; let savedBlacklist = new Set(); +let activityEntries = new Set(); // 活动级黑名单条目(格式:pkg/ActivityClass) function updateUnsavedStyling() { - const checkboxes = document.querySelectorAll('.app-checkbox'); - checkboxes.forEach(cb => { - if (cb.checked && !savedBlacklist.has(cb.dataset.pkg)) { + 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'); } + } + } }); } @@ -950,31 +1015,61 @@ function reorderDOMApps() { const container = document.getElementById('app-list-container'); if (!container) return; const items = Array.from(container.children); - - items.sort((a, b) => { - const aChecked = a.querySelector('.app-checkbox')?.checked || false; - const bChecked = b.querySelector('.app-checkbox')?.checked || false; - if (aChecked && !bChecked) return -1; - if (!aChecked && bChecked) return 1; + 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)); } +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); + }); +} + async function loadApps() { const container = document.getElementById('app-list-container'); if (!container) return; container.innerHTML = '
加载中...
'; try { - // 读取已保存的黑名单 + // 读取已保存的黑名单(包名条目 + 活动条目分开存储) const blRes = await runCmd(`cat "${CONFIG_DIR}/blacklist_apps.txt"`); - if (blRes.errno === 0) { - savedBlacklist = new Set(blRes.stdout.trim().split('\n').filter(Boolean)); - } else { - savedBlacklist = new Set(); - } + const allSaved = blRes.errno === 0 ? blRes.stdout.trim().split('\n').filter(Boolean) : []; + savedBlacklist = new Set(allSaved); + const savedPkgEntries = new Set(allSaved.filter(e => !e.includes('/'))); + activityEntries = new Set(allSaved.filter(e => e.includes('/'))); let infoList = []; try { @@ -1044,30 +1139,18 @@ async function loadApps() { checkbox.className = 'app-checkbox'; checkbox.dataset.pkg = app.packageName; - // 初始渲染时依据已保存状态勾选 - checkbox.checked = savedBlacklist.has(app.packageName); - + // 依据已保存包名条目勾选(不含活动条目) + checkbox.checked = savedPkgEntries.has(app.packageName); checkbox.addEventListener('change', () => { - updateUnsavedStyling(); + updateUnsavedStyling(); + reorderDOMApps(); }); - + const customCheckbox = document.createElement('span'); customCheckbox.className = 'app-checkbox-custom'; - checkboxLabel.appendChild(checkbox); checkboxLabel.appendChild(customCheckbox); - - const iconImg = document.createElement('img'); - iconImg.className = 'app-icon'; - iconImg.src = `ksu://icon/${app.packageName}`; - iconImg.loading = 'lazy'; // 性能优化 - iconImg.onerror = () => { - const fallback = document.createElement('div'); - fallback.className = 'app-icon-fallback'; - fallback.textContent = (app.appLabel || app.packageName || '?').charAt(0).toUpperCase(); - iconImg.replaceWith(fallback); - }; - + const infoDiv = document.createElement('div'); infoDiv.className = 'app-info'; @@ -1097,14 +1180,37 @@ async function loadApps() { infoDiv.appendChild(nameSpan); infoDiv.appendChild(pkgSpan); - - item.appendChild(checkboxLabel); - item.appendChild(iconImg); - item.appendChild(infoDiv); - + + // 活动展开箭头 + 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(); @@ -1175,6 +1281,9 @@ async function init() { document.getElementById('btn-save').addEventListener('click', saveConfig); document.getElementById('btn-save-advanced').addEventListener('click', saveAdvancedConfig); document.getElementById('btn-save-webui-config').addEventListener('click', saveWebUIConfig); + document.getElementById('input-auto-refresh').addEventListener('change', (e) => { + document.getElementById('item-status-refresh-interval').style.display = e.target.checked ? '' : 'none'; + }); document.getElementById('btn-reset').addEventListener('click', handleReset); document.getElementById('btn-toggle-service').addEventListener('click', toggleService); document.getElementById('btn-restart-service').addEventListener('click', restartService); @@ -1392,70 +1501,75 @@ async function init() { 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); - + checkbox.addEventListener('change', () => { updateUnsavedStyling(); reorderDOMApps(); }); + const customCheckbox = document.createElement('span'); customCheckbox.className = 'app-checkbox-custom'; - checkboxLabel.appendChild(checkbox); checkboxLabel.appendChild(customCheckbox); - - const iconImg = document.createElement('img'); - iconImg.className = 'app-icon'; - iconImg.src = `ksu://icon/${realPkg}`; - iconImg.loading = 'lazy'; - iconImg.onerror = () => { - const fallback = document.createElement('div'); - fallback.className = 'app-icon-fallback'; - fallback.textContent = (appData.appLabel || appData.packageName || '?').charAt(0).toUpperCase(); - iconImg.replaceWith(fallback); - }; - + const infoDiv = document.createElement('div'); infoDiv.className = 'app-info'; - + const nameSpan = document.createElement('span'); nameSpan.className = 'app-name'; - - const nameNode = document.createTextNode(appData.appLabel || 'Unknown'); - nameSpan.appendChild(nameNode); - + 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); - - item.appendChild(checkboxLabel); - item.appendChild(iconImg); - item.appendChild(infoDiv); - + + 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('已成功添加并勾选'); @@ -1516,27 +1630,54 @@ async function init() { showToast('保存中...'); const checkboxes = document.querySelectorAll('.app-checkbox'); const selectedPkgs = []; - - checkboxes.forEach(cb => { - if (cb.checked) { - selectedPkgs.push(cb.dataset.pkg); - } - }); - - const content = selectedPkgs.join('\n'); + checkboxes.forEach(cb => { if (cb.checked) selectedPkgs.push(cb.dataset.pkg); }); + // 合并包名条目 + 活动条目 + const allEntries = [...selectedPkgs, ...activityEntries]; + const content = allEntries.join('\n'); const res = await writeFile(`${CONFIG_DIR}/blacklist_apps.txt`, content); - if (res.errno === 0 || res.stdout.includes('OK')) { - showToast('黑名单保存成功'); - savedBlacklist = new Set(selectedPkgs); - updateUnsavedStyling(); - reorderDOMApps(); + showToast('黑名单保存成功'); + savedBlacklist = new Set(allEntries); + updateUnsavedStyling(); + reorderDOMApps(); } else { - showToast('保存失败: ' + res.stderr); + 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) { diff --git a/webui/src/style.css b/webui/src/style.css index f5182a6..6b1cbaf 100644 --- a/webui/src/style.css +++ b/webui/src/style.css @@ -1342,15 +1342,21 @@ input:checked + .slider:before { .app-list-item { display: flex; - align-items: center; - gap: var(--spacing-m); - padding: var(--spacing-s) var(--spacing-m); + 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; } -.app-list-item:active { +.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); } @@ -1471,3 +1477,135 @@ input:checked + .slider:before { 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: 'Google Sans Code', '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-label { + font-size: 0.8125rem; + font-weight: 500; + color: var(--md-sys-color-on-surface); +} + +.activity-block-row { + display: flex; + gap: 8px; + align-items: center; +} + +.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: 'Google Sans Code', '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); +}