update: 更新到 2208 版本;实现 HDR 避让;实现活动级黑名单

This commit is contained in:
YuleBest committed 2026-04-09 04:44:08 +08:00
1 parent a61c845323
commit b4169ceb1f
12 files changed
+566 -124

No files matched your search

+51 -5
View File
@@ -20,7 +20,7 @@
<div class="header-text">
<h1>LuminPro</h1>
<p class="header-subtitle">日用屏幕亮度强化</p>
<p class="header-version" id="module-version">V2.2-2204</p>
<p class="header-version" id="module-version">V2.2-2208</p>
</div>
</div>
<div class="header-status-container">
@@ -45,32 +45,46 @@
<div class="status-grid">
<div class="status-item">
<div class="status-item-header">
<i data-lucide="sun"></i>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"></circle><path d="M12 2v2"></path><path d="M12 20v2"></path><path d="m4.93 4.93 1.41 1.41"></path><path d="m17.66 17.66 1.41 1.41"></path><path d="M2 12h2"></path><path d="M20 12h2"></path><path d="m6.34 17.66-1.41 1.41"></path><path d="m19.07 4.93-1.41 1.41"></path></svg>
<span class="status-label">当前亮度</span>
</div>
<span class="status-value" id="status-current-bri">—</span>
</div>
<div class="status-item">
<div class="status-item-header">
<i data-lucide="smartphone"></i>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="20" x="5" y="2" rx="2" ry="2"></rect><path d="M12 18h.01"></path></svg>
<span class="status-label">系统最大亮度</span>
</div>
<span class="status-value" id="status-sys-max-bri">—</span>
</div>
<div class="status-item">
<div class="status-item-header">
<i data-lucide="activity"></i>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 12h-4l-3 9L9 3l-3 9H2"></path></svg>
<span class="status-label">inotifyd PID</span>
</div>
<span class="status-value" id="status-inotifyd-pid">—</span>
</div>
<div class="status-item">
<div class="status-item-header">
<i data-lucide="moon"></i>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><path d="M12 6v6l4 2"></path></svg>
<span class="status-label">inotifyd 状态</span>
</div>
<span class="status-value" id="status-inotifyd-state">—</span>
</div>
<div class="status-item">
<div class="status-item-header">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"></path></svg>
<span class="status-label">休眠状态</span>
</div>
<span class="status-value" id="status-sleep">—</span>
</div>
<div class="status-item">
<div class="status-item-header">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"></path><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"></path><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"></path></svg>
<span class="status-label">HDR/SDR 比率</span>
</div>
<span class="status-value" id="status-hdr-ratio">—</span>
</div>
</div>
<!-- 亮度控制区 -->
@@ -147,6 +161,19 @@
</label>
</div>
</div>
<div class="config-item">
<div class="config-label">
<span class="config-name">显示 HDR 内容时休眠</span>
<span class="config-desc">HDR/SDR 比率 &gt; 1 时不提升</span>
<span class="config-desc" style="color: var(--color-warning, #f59e0b);">建议配合去温控使用(部分系统温控策略较严格,高温时可能不显示 HDR 但仍提升亮度,导致闪屏。出现此情况时,可以使用活动黑名单/应用黑名单功能)</span>
</div>
<div class="config-value">
<label class="switch">
<input type="checkbox" id="input-display-hdr-sleep">
<span class="slider"></span>
</label>
</div>
</div>
<div class="config-item">
<div class="config-label">
<span class="config-name">定时休眠</span>
@@ -212,6 +239,7 @@
<div class="config-label">
<span class="config-name">inotifyd 监听事件</span>
<span class="config-desc">默认 c。修改需重启服务</span>
<span class="config-desc" style="color: var(--color-warning, #f59e0b);">为避免性能消耗,修改为 c 以外的事件时建议关闭 Web UI 配置 - 自动刷新</span>
<button class="btn-text-s" id="btn-view-inotifyd-help" style="margin-top: 6px; padding: 2px 6px;">查看支持事件</button>
</div>
<div class="config-value">
@@ -254,6 +282,15 @@
<div class="config-group">
<h3 class="group-title"><i data-lucide="monitor"></i> 界面设置</h3>
<div class="config-item">
<div class="config-label">
<span class="config-name">自动刷新</span>
<span class="config-desc">定时刷新状态和日志。监听非 c 事件时建议关闭</span>
</div>
<div class="config-value">
<label class="switch"><input type="checkbox" id="input-auto-refresh" checked /><span class="slider"></span></label>
</div>
</div>
<div class="config-item" id="item-status-refresh-interval">
<div class="config-label">
<span class="config-name">状态/日志刷新间隔</span>
<span class="config-desc">单位: 毫秒 (最小100ms)</span>
@@ -324,6 +361,15 @@
推荐选择视频类、相册等需展示 HDR 内容的应用
</p>
<!-- 按活动屏蔽 -->
<div class="activity-block-card">
<span class="activity-block-label">按活动屏蔽</span>
<div class="activity-block-row">
<input type="text" id="input-activity-entry" class="activity-block-input" placeholder="com.pkg/com.pkg.ActivityClass" autocomplete="off" spellcheck="false" />
<button class="btn btn-primary" id="btn-add-activity" style="padding: 0 14px; border-radius: var(--border-radius-m); font-size: 0.8125rem; white-space: nowrap; flex-shrink: 0;">确认</button>
</div>
</div>
<!-- 搜索栏 -->
<div style="display: flex; gap: 8px; align-items: stretch; margin-bottom: var(--spacing-m);">
<div class="app-search-container" style="flex: 1; margin-bottom: 0;">
+233 -92
View File
@@ -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 = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>';
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 = '<div style="text-align:center;padding:20px;color:var(--md-sys-color-on-surface-variant);">加载中...</div>';
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 = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
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 = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
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) {
+142 -4
View File
@@ -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);
}