From 7aeee350441df11a7ee581d804b02faa9ee5a034 Mon Sep 17 00:00:00 2001 From: Yule Date: Thu, 9 Apr 2026 05:48:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B4=BB=E5=8A=A8=E9=BB=91=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webroot/index.html | 67 ++++- webui/index.html | 65 ++++- webui/src/apps.css | 530 ++++++++++++++++++++++++++++++++++++ webui/src/apps.js | 646 +++++++++++++++++++++++++++++++++++++++++++ webui/src/log.css | 264 ++++++++++++++++++ webui/src/main.js | 648 +------------------------------------------- webui/src/style.css | 608 ----------------------------------------- webui/src/utils.js | 59 ++++ 8 files changed, 1635 insertions(+), 1252 deletions(-) create mode 100644 webui/src/apps.css create mode 100644 webui/src/apps.js create mode 100644 webui/src/log.css create mode 100644 webui/src/utils.js diff --git a/webroot/index.html b/webroot/index.html index 29d4edd..b59cc17 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -6,8 +6,8 @@ LuminPro - - + + @@ -364,7 +364,13 @@
- 按活动屏蔽 +
+ 按活动屏蔽 + +
@@ -481,6 +487,61 @@
+ +
+
+ + 获取活动名 +
+
+
+
+
+
+
+ +
+
+ +
+

将 Web UI 挂小窗

+

+ 在开始获取前,请先将当前 Web UI 调整为小窗模式。

+ 这样在后续步骤中,你可以同时操作目标应用并看到 Web UI 的反馈。 +

+ +
+ +
+
+ +
+

切换到目标界面

+

+ 点击「开始获取」后,切换到需要屏蔽的应用界面。

+ 检测到非 Web UI 界面后将自动停止。

+ 等待中... +

+ +
+ +
+
+ +
+

检测到活动

+

以下活动将被添加到按活动屏蔽列表:

+
+
+ + +
+
+
+
+
diff --git a/webui/index.html b/webui/index.html index 067c975..88a78ec 100644 --- a/webui/index.html +++ b/webui/index.html @@ -7,6 +7,8 @@ LuminPro + + @@ -363,7 +365,13 @@
- 按活动屏蔽 +
+ 按活动屏蔽 + +
@@ -480,6 +488,61 @@
+ +
+
+ + 获取活动名 +
+
+
+
+
+
+
+ +
+
+ +
+

将 Web UI 挂小窗

+

+ 在开始获取前,请先将当前 Web UI 调整为小窗模式。

+ 这样在后续步骤中,你可以同时操作目标应用并看到 Web UI 的反馈。 +

+ +
+ +
+
+ +
+

切换到目标界面

+

+ 点击「开始获取」后,切换到需要屏蔽的应用界面。

+ 检测到非 Web UI 界面后将自动停止。

+ 等待中... +

+ +
+ +
+
+ +
+

检测到活动

+

以下活动将被添加到按活动屏蔽列表:

+
+
+ + +
+
+
+
+
diff --git a/webui/src/apps.css b/webui/src/apps.css new file mode 100644 index 0000000..e98f7ea --- /dev/null +++ b/webui/src/apps.css @@ -0,0 +1,530 @@ +.app-list-hint { + font-size: 0.8125rem; + color: var(--md-sys-color-on-surface-variant); + margin-top: 0; + margin-bottom: var(--spacing-m); +} + +/* App Search */ +.app-search-container { + display: flex; + align-items: center; + background-color: var(--md-sys-color-surface-container-high); + border: 1px solid var(--md-sys-color-outline-variant); + border-radius: var(--border-radius-m); + padding: 8px 12px; + margin-bottom: var(--spacing-m); + transition: border-color 0.2s, box-shadow 0.2s; +} + +.app-search-container:focus-within { + border-color: var(--md-sys-color-primary); + box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.3); +} + +.search-icon { + width: 18px; + height: 18px; + color: var(--md-sys-color-on-surface-variant); + margin-right: 8px; +} + +.app-search-input { + flex: 1; + width: 100%; + min-width: 0; + background: transparent; + border: none; + color: var(--md-sys-color-on-surface); + font-size: 0.875rem; + outline: none; + font-family: inherit; +} + +.app-search-input::placeholder { + color: var(--md-sys-color-on-surface-variant); +} + +.count-badge { + background-color: var(--md-sys-color-primary-container); + color: var(--md-sys-color-on-primary-container); + font-size: 0.75rem; + font-weight: 600; + padding: 2px 8px; + border-radius: 20px; + margin-left: 8px; + white-space: nowrap; + opacity: 0.85; +} + +/* App List */ +.app-list-container { + display: flex; + flex-direction: column; + gap: var(--spacing-s); + max-height: 60vh; + overflow-y: auto; + border-radius: var(--border-radius-m); + padding: 0; +} + +.app-list-container::-webkit-scrollbar { + display: none; +} + +.app-list-item { + display: flex; + 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; + flex-shrink: 0; +} + +.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); +} + +.app-checkbox-label { + display: flex; + align-items: center; + cursor: pointer; + position: relative; +} + +.app-checkbox { + opacity: 0; + position: absolute; + width: 0; + height: 0; +} + +.app-checkbox-custom { + width: 20px; + height: 20px; + border: 2px solid var(--md-sys-color-outline); + border-radius: 4px; + display: flex; + align-items: center; + justify-content: center; + transition: all 0.2s; +} + +.app-checkbox:checked + .app-checkbox-custom { + background-color: var(--md-sys-color-primary); + border-color: var(--md-sys-color-primary); +} + +.app-checkbox.unsaved:checked + .app-checkbox-custom { + background-color: #4caf50; + border-color: #4caf50; +} + +.app-checkbox:checked + .app-checkbox-custom::after { + content: ''; + width: 5px; + height: 10px; + border: solid var(--md-sys-color-on-primary); + border-width: 0 2px 2px 0; + transform: rotate(45deg); + margin-bottom: 2px; +} + +.app-info { + display: flex; + flex-direction: column; + flex: 1; + overflow: hidden; +} + +.app-name { + font-size: 1rem; + font-weight: 500; + color: var(--md-sys-color-on-surface); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.app-pkg { + font-size: 0.8125rem; + color: var(--md-sys-color-on-surface-variant); + font-family: 'Google Sans Code', monospace; + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; + word-break: break-all; + line-height: 1.4; +} + +.app-badge { + background-color: var(--md-sys-color-primary-container); + color: var(--md-sys-color-on-primary-container); + padding: 0 4px; + border-radius: 4px; + font-size: 0.65rem; + font-weight: bold; +} + +.app-icon { + width: 40px; + height: 40px; + border-radius: 8px; + object-fit: cover; + flex-shrink: 0; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + +.app-icon-fallback { + width: 40px; + height: 40px; + border-radius: 8px; + background: linear-gradient(135deg, var(--md-sys-color-primary-container), rgba(168, 199, 250, 0.5)); + color: var(--md-sys-color-on-primary-container); + display: flex; + align-items: center; + justify-content: center; + font-size: 1.25rem; + font-weight: bold; + flex-shrink: 0; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + +.app-uid { + font-size: 0.65rem; + color: var(--md-sys-color-on-surface-variant); + background-color: var(--md-sys-color-surface-container-high); + border: 1px solid var(--md-sys-color-outline-variant); + padding: 0 4px; + border-radius: 4px; + font-family: 'Google Sans Code', monospace; + 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-header { + display: flex; + align-items: center; + justify-content: space-between; +} + +.activity-block-label { + font-size: 0.8125rem; + font-weight: 500; + color: var(--md-sys-color-on-surface); +} + +.btn-picker-trigger { + display: flex; + align-items: center; + gap: 4px; + background: none; + border: 1px solid var(--md-sys-color-outline-variant); + border-radius: var(--border-radius-s); + color: var(--md-sys-color-primary); + font-size: 0.75rem; + font-weight: 500; + padding: 3px 8px; + cursor: pointer; + transition: background-color 0.2s, border-color 0.2s; + white-space: nowrap; + font-family: inherit; +} + +.btn-picker-trigger:hover { + background-color: var(--md-sys-color-primary-container); + border-color: var(--md-sys-color-primary); +} + +.activity-block-row { + display: flex; + gap: 8px; + align-items: stretch; +} + +.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); +} + +/* ======================== + 获取活动名向导覆盖层 + ======================== */ +.activity-picker-overlay { + position: fixed; + inset: 0; + background: var(--md-sys-color-background); + z-index: 950; + display: flex; + flex-direction: column; + transform: translateX(100%); + transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1); +} + +.activity-picker-overlay.show { + transform: translateX(0); +} + +.activity-picker-header { + display: flex; + align-items: center; + gap: 12px; + padding: calc(var(--safe-area-inset-top, 0px) + 16px) 16px 12px; + border-bottom: 1px solid var(--md-sys-color-outline-variant); + flex-shrink: 0; +} + +.picker-back-btn { + display: flex; + align-items: center; + justify-content: center; + width: 36px; + height: 36px; + background: none; + border: none; + border-radius: 50%; + color: var(--md-sys-color-on-surface); + cursor: pointer; + transition: background-color 0.2s; + flex-shrink: 0; +} + +.picker-back-btn:hover { + background-color: var(--md-sys-color-surface-container); +} + +.picker-title { + font-size: 1.0625rem; + font-weight: 600; + color: var(--md-sys-color-on-surface); +} + +.picker-steps-indicator { + display: flex; + justify-content: center; + align-items: center; + gap: 8px; + padding: 16px 0 0; + flex-shrink: 0; +} + +.picker-step-dot { + width: 6px; + height: 6px; + border-radius: 50%; + background-color: var(--md-sys-color-outline-variant); + transition: background-color 0.3s, transform 0.3s, width 0.3s; +} + +.picker-step-dot.active { + background-color: var(--md-sys-color-primary); + transform: scale(1.2); + width: 18px; + border-radius: 4px; +} + +.activity-picker-body { + flex: 1; + overflow-y: auto; + display: flex; + flex-direction: column; +} + +.picker-step { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 32px 32px calc(var(--safe-area-inset-bottom, 0px) + 48px); + text-align: center; + gap: 14px; +} + +.picker-step-icon { + color: var(--md-sys-color-primary); + opacity: 0.9; + margin-bottom: 4px; +} + +.picker-step-title { + font-size: 1.25rem; + font-weight: 600; + color: var(--md-sys-color-on-background); + margin: 0; +} + +.picker-step-desc { + font-size: 0.9375rem; + color: var(--md-sys-color-on-surface-variant); + line-height: 1.65; + max-width: 300px; + margin: 0; +} + +.picker-action-btn { + margin-top: 12px; + padding: 12px 32px; + border-radius: 24px; + font-size: 0.9375rem; +} + +.picker-status-text { + display: inline-block; + font-weight: 500; + color: var(--md-sys-color-primary); +} + +.picker-status-text.polling { + animation: picker-pulse 1.2s ease-in-out infinite; +} + +@keyframes picker-pulse { + 0%, 100% { opacity: 1; } + 50% { opacity: 0.35; } +} + +.picker-result-box { + background: var(--md-sys-color-surface-container-high); + border: 1.5px solid var(--md-sys-color-primary); + border-radius: var(--border-radius-m); + padding: 14px 18px; + font-family: 'Google Sans Code', 'Roboto Mono', monospace; + font-size: 0.875rem; + color: var(--md-sys-color-on-surface); + word-break: break-all; + line-height: 1.55; + max-width: 320px; + width: 100%; + text-align: left; +} + +.picker-result-actions { + display: flex; + gap: 12px; + margin-top: 4px; +} diff --git a/webui/src/apps.js b/webui/src/apps.js new file mode 100644 index 0000000..657385f --- /dev/null +++ b/webui/src/apps.js @@ -0,0 +1,646 @@ +import { listPackages, getPackagesInfo } from 'kernelsu'; +import { createIcons, Eye, EyeOff } from 'lucide'; +import PinyinMatch from 'pinyin-match'; +import { CONFIG_DIR, showToast, runCmd, writeFile } from './utils.js'; + +let showingSystemApps = true; +let savedBlacklist = new Set(); +let activityEntries = new Set(); // 活动级黑名单条目(格式:pkg/ActivityClass) + +export function updateUnsavedStyling() { + 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'); } + } + } + }); +} + +export function reorderDOMApps() { + const container = document.getElementById('app-list-container'); + if (!container) return; + const items = Array.from(container.children); + 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)); +} + +export 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); + }); +} + +export 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"`); + 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 { + const pkgs = await listPackages(); + if (pkgs && pkgs.length > 0) { + infoList = await getPackagesInfo(pkgs); + } else { + throw new Error('No packages found'); + } + } catch (_) { + // 模拟 150 个应用包数据用于调试 + console.log("[DEBUG] 使用模拟应用列表数据"); + infoList = Array.from({ length: 150 }, (_, i) => ({ + packageName: `com.mock.app${i}`, + appLabel: i % 10 === 0 ? `测试应用 ${i} (含抖音关键字)` : `模拟应用 ${i}`, + isSystem: i % 5 === 0, + uid: 10000 + i + })); + } + + // 过滤系统应用 + if (!showingSystemApps) { + infoList = infoList.filter(app => !app.isSystem); + } + + container.innerHTML = ''; + + // 排序:非系统优先,按名称 + infoList.sort((a, b) => { + if (a.isSystem !== b.isSystem) return a.isSystem ? 1 : -1; + return (a.appLabel || "").localeCompare(b.appLabel || ""); + }); + + if (infoList.length === 0) { + infoList.push( + { packageName: "com.example.app1", appLabel: "示例 1", isSystem: false, uid: 10123 }, + { packageName: "com.example.app2", appLabel: "示例 2", isSystem: false, uid: 10124 }, + { packageName: "com.example.sys1", appLabel: "系统示例 1", isSystem: true, uid: 1000 }, + { packageName: "com.example.sys2", appLabel: "系统示例 2", isSystem: true, uid: 1001 } + ); + if (!showingSystemApps) { + infoList = infoList.filter(app => !app.isSystem); + } + } + + // uid 去重 + const seenUids = new Set(); + infoList = infoList.filter(app => { + if (app.uid === undefined || app.uid === null) return true; + if (seenUids.has(app.uid)) return false; + seenUids.add(app.uid); + return true; + }); + + infoList.forEach(app => { + 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 = app.packageName; + + // 依据已保存包名条目勾选(不含活动条目) + checkbox.checked = savedPkgEntries.has(app.packageName); + checkbox.addEventListener('change', () => { + updateUnsavedStyling(); + reorderDOMApps(); + }); + + const customCheckbox = document.createElement('span'); + customCheckbox.className = 'app-checkbox-custom'; + checkboxLabel.appendChild(checkbox); + checkboxLabel.appendChild(customCheckbox); + + const infoDiv = document.createElement('div'); + infoDiv.className = 'app-info'; + + const nameSpan = document.createElement('span'); + nameSpan.className = 'app-name'; + nameSpan.appendChild(document.createTextNode(app.appLabel || 'Unknown')); + + if (app.uid !== undefined) { + const uidBadge = document.createElement('span'); + uidBadge.className = 'app-uid'; + uidBadge.textContent = String(app.uid); + nameSpan.appendChild(uidBadge); + } + + const pkgSpan = document.createElement('span'); + pkgSpan.className = 'app-pkg'; + pkgSpan.textContent = app.packageName || ''; + + if (app.isSystem) { + const sysBadge = document.createElement('span'); + sysBadge.className = 'app-badge'; + sysBadge.textContent = '系统'; + pkgSpan.appendChild(sysBadge); + } + + infoDiv.appendChild(nameSpan); + infoDiv.appendChild(pkgSpan); + + // 活动展开箭头 + 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(); + + const badge = document.getElementById('app-count-badge'); + if (badge) badge.textContent = infoList.length; + + if (infoList.length === 0) { + container.innerHTML = '
无应用
'; + } + } catch (e) { + container.innerHTML = `
加载失败: ${e.message || String(e)}
`; + } +} + +export function setupAppsEvents() { + // 下拉菜单控制 + const btnAppsMenu = document.getElementById('btn-apps-menu'); + const appsDropdownMenu = document.getElementById('apps-dropdown-menu'); + + if (btnAppsMenu && appsDropdownMenu) { + btnAppsMenu.addEventListener('click', (e) => { + e.stopPropagation(); + appsDropdownMenu.classList.toggle('show'); + }); + document.addEventListener('click', (e) => { + if (!btnAppsMenu.contains(e.target) && !appsDropdownMenu.contains(e.target)) { + appsDropdownMenu.classList.remove('show'); + } + }); + } + + // 切换系统应用显示 + const btnToggleSysApps = document.getElementById('btn-toggle-sys-apps'); + if (btnToggleSysApps) { + btnToggleSysApps.addEventListener('click', () => { + showingSystemApps = !showingSystemApps; + + const textSpan = document.getElementById('sys-apps-text'); + const iconWrap = document.getElementById('sys-apps-icon'); + + if (textSpan) textSpan.textContent = showingSystemApps ? '隐藏系统应用' : '显示系统应用'; + + if (iconWrap) { + const p = iconWrap.parentNode; + const newIcon = document.createElement('i'); + newIcon.setAttribute('data-lucide', showingSystemApps ? 'eye-off' : 'eye'); + newIcon.id = 'sys-apps-icon'; + p.replaceChild(newIcon, iconWrap); + createIcons({ icons: { Eye, EyeOff }, nameAttr: 'data-lucide' }); + } + + loadApps(); + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + }); + } + + // 智能选择 + const btnSmartSelect = document.getElementById('btn-smart-select'); + if (btnSmartSelect) { + const smartKeywords = ["相册", "抖音", "快手", "视频", "哔哩哔哩", "bili", "pili", "netflix", "youtube", "tiktok", "x"]; + btnSmartSelect.addEventListener('click', () => { + const items = document.querySelectorAll('.app-list-item'); + items.forEach(item => { + const name = item.querySelector('.app-name').textContent.toLowerCase(); + const checkbox = item.querySelector('.app-checkbox'); + let match = false; + for (const kw of smartKeywords) { + if (kw === 'x') { + if (name === 'x' || name === 'x (twitter)') { match = true; break; } + } else if (name.includes(kw)) { + match = true; break; + } + } + if (match) checkbox.checked = true; + }); + updateUnsavedStyling(); + reorderDOMApps(); + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + }); + } + + // 手动添加包名 + const btnManualAdd = document.getElementById('btn-manual-add'); + if (btnManualAdd) { + btnManualAdd.addEventListener('click', async () => { + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + const pkg = prompt('请输入你要彻底屏蔽的完整应用包名(例如: com.example.app):'); + if (!pkg || !pkg.trim()) return; + + const realPkg = pkg.trim(); + const existing = document.querySelector(`.app-checkbox[data-pkg="${realPkg}"]`); + if (existing) { + existing.checked = true; + updateUnsavedStyling(); + reorderDOMApps(); + showToast('该应用已在列表中,已为你自动勾选并置顶'); + return; + } + + showToast('正在尝试获取应用信息...'); + let appData = { packageName: realPkg, appLabel: '未知 (手动添加)', isSystem: false, uid: '自定义' }; + try { + const info = await getPackagesInfo([realPkg]); + if (info && info.length > 0) appData = info[0]; + } catch { /* ignore */ } + + 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(); reorderDOMApps(); }); + + const customCheckbox = document.createElement('span'); + customCheckbox.className = 'app-checkbox-custom'; + checkboxLabel.appendChild(checkbox); + checkboxLabel.appendChild(customCheckbox); + + const infoDiv = document.createElement('div'); + infoDiv.className = 'app-info'; + + const nameSpan = document.createElement('span'); + nameSpan.className = 'app-name'; + 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); + + 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('已成功添加并勾选'); + }); + } + + // 全选 + const btnSelectAll = document.getElementById('btn-select-all'); + if (btnSelectAll) { + btnSelectAll.addEventListener('click', () => { + document.querySelectorAll('.app-checkbox').forEach(cb => { cb.checked = true; }); + updateUnsavedStyling(); + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + }); + } + + // 全不选 + const btnSelectNone = document.getElementById('btn-select-none'); + if (btnSelectNone) { + btnSelectNone.addEventListener('click', () => { + document.querySelectorAll('.app-checkbox').forEach(cb => { cb.checked = false; }); + updateUnsavedStyling(); + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + }); + } + + // 反选 + const btnInvertSelection = document.getElementById('btn-invert-selection'); + if (btnInvertSelection) { + btnInvertSelection.addEventListener('click', () => { + document.querySelectorAll('.app-checkbox').forEach(cb => { cb.checked = !cb.checked; }); + updateUnsavedStyling(); + appsDropdownMenu && appsDropdownMenu.classList.remove('show'); + }); + } + + // 刷新(重排) + const btnAppsRefresh = document.getElementById('btn-apps-refresh'); + if (btnAppsRefresh) { + btnAppsRefresh.addEventListener('click', () => { reorderDOMApps(); }); + } + + // 保存黑名单 + const btnSaveBlacklist = document.getElementById('btn-save-blacklist'); + if (btnSaveBlacklist) { + btnSaveBlacklist.addEventListener('click', async () => { + showToast('保存中...'); + const selectedPkgs = []; + document.querySelectorAll('.app-checkbox').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(allEntries); + updateUnsavedStyling(); + reorderDOMApps(); + } else { + 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) { + inputAppSearch.addEventListener('input', (e) => { + const keyword = e.target.value.trim().toLowerCase(); + const items = document.querySelectorAll('.app-list-item'); + let visibleCount = 0; + items.forEach(item => { + const name = item.querySelector('.app-name').textContent; + const pkg = item.querySelector('.app-pkg').textContent.toLowerCase(); + if (!keyword || pkg.includes(keyword) || PinyinMatch.match(name, keyword)) { + item.style.display = 'flex'; + visibleCount++; + } else { + item.style.display = 'none'; + } + }); + const badge = document.getElementById('app-count-badge'); + if (badge) badge.textContent = visibleCount; + }); + } + + setupActivityPicker(); +} + +function setupActivityPicker() { + const overlay = document.getElementById('activity-picker-overlay'); + if (!overlay) return; + + const btnPickActivity = document.getElementById('btn-pick-activity'); + const btnPickerBack = document.getElementById('btn-picker-back'); + const step1 = document.getElementById('picker-step-1'); + const step2 = document.getElementById('picker-step-2'); + const step3 = document.getElementById('picker-step-3'); + const dots = [ + document.getElementById('picker-dot-1'), + document.getElementById('picker-dot-2'), + document.getElementById('picker-dot-3'), + ]; + const btnStep1Next = document.getElementById('btn-picker-step1-next'); + const btnPickerStart = document.getElementById('btn-picker-start'); + const btnPickerRetry = document.getElementById('btn-picker-retry'); + const btnPickerConfirm = document.getElementById('btn-picker-confirm'); + const pickerStatusText = document.getElementById('picker-status-text'); + const pickerResultText = document.getElementById('picker-result-text'); + + let pollingTimer = null; + let detectedActivity = null; + + function showStep(n) { + [step1, step2, step3].forEach((s, i) => { + if (s) s.style.display = i + 1 === n ? 'flex' : 'none'; + }); + dots.forEach((d, i) => { + d?.classList.toggle('active', i + 1 === n); + }); + } + + function stopPolling() { + if (pollingTimer) { clearInterval(pollingTimer); pollingTimer = null; } + } + + function openPicker() { + stopPolling(); + detectedActivity = null; + if (btnPickerStart) btnPickerStart.disabled = false; + if (pickerStatusText) { + pickerStatusText.textContent = '等待中...'; + pickerStatusText.classList.remove('polling'); + } + showStep(1); + overlay.classList.add('show'); + } + + function closePicker() { + stopPolling(); + overlay.classList.remove('show'); + } + + btnPickActivity?.addEventListener('click', openPicker); + btnPickerBack?.addEventListener('click', closePicker); + btnStep1Next?.addEventListener('click', () => showStep(2)); + + btnPickerStart?.addEventListener('click', () => { + btnPickerStart.disabled = true; + if (pickerStatusText) { + pickerStatusText.textContent = '检测中,请切换到目标界面...'; + pickerStatusText.classList.add('polling'); + } + stopPolling(); + pollingTimer = setInterval(async () => { + try { + const res = await runCmd(`dumpsys window 2>/dev/null | grep mCurrentFocus | sed 's/.*u0 \\(.*\\)}/\\1/'`); + if (res.errno !== 0) return; + const activity = res.stdout.trim(); + // 空值或仍在 WebUI 内则继续等待 + if (!activity || activity.toLowerCase().includes('webui')) return; + stopPolling(); + detectedActivity = activity; + if (pickerStatusText) pickerStatusText.classList.remove('polling'); + if (pickerResultText) pickerResultText.textContent = activity; + if (btnPickerStart) btnPickerStart.disabled = false; + showStep(3); + } catch { /* 忽略,继续轮询 */ } + }, 600); + }); + + btnPickerRetry?.addEventListener('click', () => { + stopPolling(); + detectedActivity = null; + if (btnPickerStart) btnPickerStart.disabled = false; + if (pickerStatusText) { + pickerStatusText.textContent = '等待中...'; + pickerStatusText.classList.remove('polling'); + } + showStep(2); + }); + + btnPickerConfirm?.addEventListener('click', () => { + if (!detectedActivity) return; + activityEntries.add(detectedActivity); + const pkg = detectedActivity.split('/')[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(`已添加: ${detectedActivity}`); + closePicker(); + }); +} diff --git a/webui/src/log.css b/webui/src/log.css new file mode 100644 index 0000000..a695c40 --- /dev/null +++ b/webui/src/log.css @@ -0,0 +1,264 @@ +/* Logs */ +.log-output { + font-family: 'Google Sans Code', 'JetBrains Mono', 'Consolas', monospace; + font-size: 0.6875rem; + padding: var(--spacing-m); + background-color: #0d0e12; + color: #e3e3e3; + border-radius: var(--border-radius-m); + border: 1px solid rgba(255, 255, 255, 0.05); + flex: 1; + max-height: 60vh; + overflow-y: auto; + margin: 0; + white-space: pre-wrap; + word-wrap: break-word; + line-height: 1.5; + scrollbar-width: thin; + scrollbar-color: var(--md-sys-color-outline-variant) transparent; +} + +.log-output::-webkit-scrollbar { + width: 4px; +} + +.log-output::-webkit-scrollbar-thumb { + background-color: var(--md-sys-color-outline-variant); + border-radius: 4px; +} + +.log-filter-select { + padding: 0 12px; + border: 1px solid var(--md-sys-color-outline-variant); + border-radius: 8px; + background-color: var(--md-sys-color-surface-container-high); + color: var(--md-sys-color-on-surface); + font-family: inherit; + font-size: 0.8125rem; + height: 32px; + cursor: pointer; + outline: none; + transition: all 0.22s ease; +} + +.log-filter-select:focus { + border-color: var(--md-sys-color-primary); + box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); +} + +.log-output::-webkit-scrollbar { + display: none; /* Chrome, Safari */ +} + +/* Simple Toast */ +.top-blur { + position: fixed; + top: 0; + left: 0; + right: 0; + height: calc(85px + var(--safe-area-inset-top, 0px)); + z-index: 998; + pointer-events: none; + /* 基础暗色背景,增强状态栏文字可读性 */ + background: linear-gradient(to bottom, + rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.85) 0%, + rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.4) 40%, + rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0) 100% + ); + /* 核心:毛玻璃滤镜 */ + -webkit-backdrop-filter: blur(16px); + backdrop-filter: blur(16px); + /* 梯度蒙版:越往上越模糊的核心逻辑 */ + -webkit-mask-image: linear-gradient(to bottom, + rgba(0,0,0,1) 0%, + rgba(0,0,0,1) 30%, + rgba(0,0,0,0.7) 60%, + rgba(0,0,0,0) 100% + ); + mask-image: linear-gradient(to bottom, + rgba(0,0,0,1) 0%, + rgba(0,0,0,1) 30%, + rgba(0,0,0,0.7) 60%, + rgba(0,0,0,0) 100% + ); + transform: translateZ(0); /* 开启 GPU 加速 */ + opacity: 0; + transition: opacity 0.3s ease; +} + +.top-blur.scrolled { + opacity: 1; +} + +.toast { + position: fixed; + bottom: 24px; + left: 50%; + transform: translateX(-50%) translateY(100px); + background-color: var(--md-sys-color-on-surface); + color: var(--md-sys-color-surface); + padding: 12px 24px; + border-radius: var(--border-radius-s); + font-size: 0.875rem; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); + transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); + z-index: 1000; + width: max-content; + max-width: 90vw; + text-align: center; +} + +.toast.show { + transform: translateX(-50%) translateY(0); +} + +/* Floating Navigation Bar */ +.floating-navbar { + position: fixed; + bottom: calc(18px + var(--safe-area-inset-bottom, 0px)); + left: 50%; + transform: translateX(-50%) translateZ(0); /* 居中并开启硬件加速 */ + display: flex; + justify-content: center; + align-items: center; + gap: 8px; + background: rgba(var(--md-sys-color-surface-container-high-rgb, 43, 41, 48), 0.6); + -webkit-backdrop-filter: blur(20px) saturate(180%); + backdrop-filter: blur(20px) saturate(180%); + will-change: backdrop-filter; + padding: 8px 16px; + border-radius: 28px; + border: 1px solid rgba(255, 255, 255, 0.08); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 8px 32px rgba(0, 0, 0, 0.3); + z-index: 999; + width: fit-content; + max-width: calc(100% - 32px); + user-select: none; + -webkit-user-select: none; + -webkit-tap-highlight-color: transparent; + touch-action: none; /* Prevents browser scroll during drag */ +} + +.navbar-slider { + position: absolute; + left: 0; + top: 8px; + bottom: 8px; + height: auto; + background: rgba(var(--md-sys-color-primary-rgb, 168, 199, 250), 0.35); + -webkit-backdrop-filter: blur(8px) saturate(120%); + backdrop-filter: blur(8px) saturate(120%); + transform: translateZ(0); + border-radius: 20px; + transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s ease; + pointer-events: none; + z-index: 0; + border: 1px solid rgba(var(--md-sys-color-primary-rgb, 168, 199, 250), 0.4); + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); +} + +.navbar-btn { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 5px; + padding: 6px 12px; + background-color: transparent; + border: none; + color: var(--md-sys-color-on-surface-variant); + font-size: 0.75rem; + cursor: pointer; + border-radius: 8px; + transition: all 0.2s ease; + flex: 1; + max-width: 90px; + white-space: nowrap; + position: relative; + z-index: 1; +} + +.navbar-btn i, .navbar-btn svg { + width: 20px; + height: 20px; + display: flex; + align-items: center; + justify-content: center; +} + +.navbar-btn span { + font-size: 0.75rem; +} + +.navbar-btn:active { + /* No scaling here, we rely on the slider feedback */ +} + +.navbar-btn.active { + color: var(--md-sys-color-on-primary-container); +} + +/* Dropdown Menu */ +.dropdown-container { + position: relative; +} + +.dropdown-menu { + position: absolute; + top: 100%; + right: 0; + margin-top: 8px; + background-color: var(--md-sys-color-surface-container-high); + border: 1px solid var(--md-sys-color-outline-variant); + border-radius: var(--border-radius-s); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); + min-width: 160px; + opacity: 0; + visibility: hidden; + transform: translateY(-8px); + transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28); + z-index: 100; + display: flex; + flex-direction: column; + padding: 4px; +} + +.dropdown-menu.show { + opacity: 1; + visibility: visible; + transform: translateY(0); +} + +.dropdown-item { + display: flex; + align-items: center; + gap: 12px; + padding: 10px 12px; + border-radius: 4px; + cursor: pointer; + color: var(--md-sys-color-on-surface); + font-size: 0.875rem; + transition: background-color 0.2s; +} + +.dropdown-item:hover { + background-color: var(--md-sys-color-surface-container); +} + +.dropdown-item:active { + background-color: var(--md-sys-color-surface); +} + +.dropdown-item svg { + color: var(--md-sys-color-primary); + width: 18px; + height: 18px; +} + +.dropdown-item-danger { + color: var(--md-sys-color-error, #cf6679); +} + +.dropdown-item-danger svg { + color: var(--md-sys-color-error, #cf6679); +} diff --git a/webui/src/main.js b/webui/src/main.js index 1a523d0..ba8da25 100644 --- a/webui/src/main.js +++ b/webui/src/main.js @@ -1,17 +1,7 @@ -import { exec, listPackages, getPackagesInfo } from 'kernelsu'; -import { createIcons, Sun, Settings, Settings2, Save, Activity, RefreshCw, FileText, Smartphone, MoreVertical, Eye, EyeOff, CheckSquare, CheckCheck, Square, Search, Sparkles, Plus, ShieldCheck, Moon, Play, RotateCcw, Monitor, Info, Code, User, BookOpen, X, Globe, Minus, Copy, Download } from 'lucide'; +import { createIcons, Sun, Settings, Settings2, Save, Activity, RefreshCw, FileText, Smartphone, MoreVertical, Eye, EyeOff, CheckSquare, CheckCheck, Square, Search, Sparkles, Plus, ShieldCheck, Moon, Play, RotateCcw, Monitor, Info, Code, User, BookOpen, X, Globe, Minus } from 'lucide'; import MarkdownIt from 'markdown-it'; -import PinyinMatch from 'pinyin-match'; - -const CONFIG_DIR = '/data/adb/modules/LuminPro/config'; -const PATH_CONFIG_DIR = '/data/adb/modules/LuminPro/config/path'; -const BACKUP_DIR = '/data/adb/modules/LuminPro/config/.backup'; -const PID_FILE = '/data/adb/modules/LuminPro/pid/inotifyd.pid'; -const FLAG_FILE = '/data/adb/modules/LuminPro/pid/up.flag'; -const STOP_FLAG_FILE = '/data/adb/modules/LuminPro/pid/stop.flag'; -const LOG_FILE = '/data/adb/modules/LuminPro/service.log'; -const DEFAULT_NOW_BRI_FILE = '/sys/class/backlight/panel0-backlight/brightness'; -const DEFAULT_SYS_MAX_BRI_FILE = '/sys/class/backlight/panel0-backlight/max_brightness'; +import { CONFIG_DIR, PATH_CONFIG_DIR, BACKUP_DIR, PID_FILE, FLAG_FILE, STOP_FLAG_FILE, LOG_FILE, DEFAULT_NOW_BRI_FILE, DEFAULT_SYS_MAX_BRI_FILE, showToast, runCmd, writeFile } from './utils.js'; +import { loadApps, setupAppsEvents } from './apps.js'; let NOW_BRI_FILE = DEFAULT_NOW_BRI_FILE; let SYS_MAX_BRI_FILE = DEFAULT_SYS_MAX_BRI_FILE; @@ -28,59 +18,6 @@ let autoRefreshConfigTimer = null; // 配置刷新定时器 let uiZoom = 100; // 界面缩放百分比 (50-150) let autoRefresh = true; // 自动刷新开关(默认开启) -// ========================== -// 工具函数 -// ========================== -function showToast(msg) { - const toast = document.getElementById('toast'); - toast.textContent = msg; - toast.classList.add('show'); - setTimeout(() => toast.classList.remove('show'), 3000); -} - -// 封装的 exec,按需返回真实执行结果 -async function runCmd(cmd) { - try { - const res = await exec(cmd); - return res; - } catch (e) { - // 调试模式数据模拟 - console.warn(`[DEBUG] 执行命令失败 (可能是非 KSU 环境): ${cmd}`); - - // 基础配置模拟 - if (cmd.includes('cat') && cmd.includes('ui_max_bri.txt')) return { errno: 0, stdout: '4095', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('max_bri.txt')) return { errno: 0, stdout: '3500', stderr: '' }; - if (cmd.includes('cat') && (cmd.includes('now_bri_file.txt') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '/sys/mock/brightness', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('inotify_events.txt')) return { errno: 0, stdout: 'c', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('log_max_size.txt')) return { errno: 0, stdout: '1024', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('steps_num.txt')) return { errno: 0, stdout: '100', stderr: '' }; - - // 状态模拟 - if (cmd.includes('cat') && (cmd.includes('brightness') || cmd.includes('now_bri_file.txt'))) return { errno: 0, stdout: '1200', stderr: '' }; - if (cmd.includes('cat') && (cmd.includes('max_brightness') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '4095', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('inotifyd.pid')) return { errno: 0, stdout: '12345', stderr: '' }; - if (cmd.includes('settings get system screen_brightness_mode')) return { errno: 0, stdout: '1', stderr: '' }; - if (cmd.includes('[ -f') && cmd.includes('stop.flag')) return { errno: 0, stdout: '0', stderr: '' }; - - // 日志模拟 - if (cmd.includes('tail') && cmd.includes('service.log')) { - return { errno: 0, stdout: '[2026-04-07 15:40:01] [INFO] 服务启动成功\n[2026-04-07 15:41:05] [DEBUG] 亮度调整: 1200 -> 1250\n[2026-04-07 15:42:10] [INFO] 切换至峰值亮度模式\n[2026-04-07 15:43:22] [WARN] 检测到极低亮度设定', stderr: '' }; - } - - // 文档模拟 - if (cmd.includes('cat') && cmd.includes('.md')) return { errno: 0, stdout: '# 调试模式说明\n\n当前处于 **Web 调试模式**,显示的是模拟出的测试数据。\n\n- 状态卡片:全部固定为运行中。\n- 应用列表:预设了 150 个常用模拟应用。\n- 按钮:所有变更仅在当前页面生效,不会写入手机文件系统。', stderr: '' }; - if (cmd.includes('cat') && cmd.includes('.txt')) return { errno: 0, stdout: '这是 NOTE.txt 的模拟内容,用于测试纯文本渲染。', stderr: '' }; - - return { errno: -1, stdout: '', stderr: String(e) }; - } -} - -// 写入文件 -async function writeFile(path, content) { - const safeContent = String(content).replace(/'/g, "'\\''"); - return runCmd(`echo -n '${safeContent}' > "${path}"`); -} - // ========================== // 业务逻辑 // ========================== @@ -455,7 +392,7 @@ async function loadStatus(forceFull = false) { 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/'`); + 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 { @@ -975,258 +912,6 @@ function setupNavbar() { }); } -let showingSystemApps = true; -let savedBlacklist = new Set(); -let activityEntries = new Set(); // 活动级黑名单条目(格式:pkg/ActivityClass) - -function updateUnsavedStyling() { - 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'); } - } - } - }); -} - -function reorderDOMApps() { - const container = document.getElementById('app-list-container'); - if (!container) return; - const items = Array.from(container.children); - 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"`); - 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 { - const pkgs = await listPackages(); - if (pkgs && pkgs.length > 0) { - infoList = await getPackagesInfo(pkgs); - } else { - throw new Error('No packages found'); - } - } catch (_) { - // 模拟 150 个应用包数据用于调试 - console.log("[DEBUG] 使用模拟应用列表数据"); - infoList = Array.from({ length: 150 }, (_, i) => ({ - packageName: `com.mock.app${i}`, - appLabel: i % 10 === 0 ? `测试应用 ${i} (含抖音关键字)` : `模拟应用 ${i}`, - isSystem: i % 5 === 0, - uid: 10000 + i - })); - } - - // 过滤对应示例展示的系统应用状态 - if (!showingSystemApps) { - infoList = infoList.filter(app => !app.isSystem); - } - - container.innerHTML = ''; - - // 排序:默认按是否包含系统应用及名称 - infoList.sort((a, b) => { - if (a.isSystem !== b.isSystem) return a.isSystem ? 1 : -1; - return (a.appLabel || "").localeCompare(b.appLabel || ""); - }); - - if (infoList.length === 0) { - // 在无数据时展示一些示例数据,方便在 PC/浏览器中预览样式 - infoList.push( - { packageName: "com.example.app1", appLabel: "示例 1", isSystem: false, uid: 10123 }, - { packageName: "com.example.app2", appLabel: "示例 2", isSystem: false, uid: 10124 }, - { packageName: "com.example.sys1", appLabel: "系统示例 1", isSystem: true, uid: 1000 }, - { packageName: "com.example.sys2", appLabel: "系统示例 2", isSystem: true, uid: 1001 } - ); - - // 过滤对应示例展示的系统应用状态 - if (!showingSystemApps) { - infoList = infoList.filter(app => !app.isSystem); - } - } - - // 根据 uid 去重处理 - const seenUids = new Set(); - infoList = infoList.filter(app => { - if (app.uid === undefined || app.uid === null) return true; - if (seenUids.has(app.uid)) return false; - seenUids.add(app.uid); - return true; - }); - - infoList.forEach(app => { - 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 = app.packageName; - - // 依据已保存包名条目勾选(不含活动条目) - checkbox.checked = savedPkgEntries.has(app.packageName); - checkbox.addEventListener('change', () => { - updateUnsavedStyling(); - reorderDOMApps(); - }); - - const customCheckbox = document.createElement('span'); - customCheckbox.className = 'app-checkbox-custom'; - checkboxLabel.appendChild(checkbox); - checkboxLabel.appendChild(customCheckbox); - - const infoDiv = document.createElement('div'); - infoDiv.className = 'app-info'; - - const nameSpan = document.createElement('span'); - nameSpan.className = 'app-name'; - - const nameNode = document.createTextNode(app.appLabel || 'Unknown'); - nameSpan.appendChild(nameNode); - - if (app.uid !== undefined) { - const uidBadge = document.createElement('span'); - uidBadge.className = 'app-uid'; - uidBadge.textContent = String(app.uid); - nameSpan.appendChild(uidBadge); - } - - const pkgSpan = document.createElement('span'); - pkgSpan.className = 'app-pkg'; - pkgSpan.textContent = app.packageName || ''; - - if (app.isSystem) { - const sysBadge = document.createElement('span'); - sysBadge.className = 'app-badge'; - sysBadge.textContent = '系统'; - pkgSpan.appendChild(sysBadge); - } - - infoDiv.appendChild(nameSpan); - infoDiv.appendChild(pkgSpan); - - // 活动展开箭头 - 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(); - - // 更新数量统计 - const badge = document.getElementById('app-count-badge'); - if (badge) badge.textContent = infoList.length; - - if (infoList.length === 0) { - container.innerHTML = '
无应用
'; - } - } catch (e) { - container.innerHTML = `
加载失败: ${e.message || String(e)}
`; - } -} - async function init() { // 优先应用保存在本地的缩放设置,避免初次加载时闪动 try { @@ -1238,7 +923,7 @@ async function init() { applyUIZoom(uiZoom); } } - } catch(e) {} + } catch {} // 初始化 Lucide 图标 createIcons({ @@ -1335,14 +1020,14 @@ async function init() { if (btnCopyLog) { btnCopyLog.addEventListener('click', () => { - logDropdownMenu && logDropdownMenu.classList.remove('show'); + logDropdownMenu?.classList.remove('show'); handleCopyLog(); }); } if (btnExportLog) { btnExportLog.addEventListener('click', () => { - logDropdownMenu && logDropdownMenu.classList.remove('show'); + logDropdownMenu?.classList.remove('show'); handleExportLog(); }); } @@ -1384,324 +1069,7 @@ async function init() { setTimeout(autoResize, 0); }); - // 应用列表-下拉菜单控制 - const btnAppsMenu = document.getElementById('btn-apps-menu'); - const appsDropdownMenu = document.getElementById('apps-dropdown-menu'); - - if (btnAppsMenu && appsDropdownMenu) { - btnAppsMenu.addEventListener('click', (e) => { - e.stopPropagation(); - appsDropdownMenu.classList.toggle('show'); - }); - - // 点击外部隐藏菜单 - document.addEventListener('click', (e) => { - if (!btnAppsMenu.contains(e.target) && !appsDropdownMenu.contains(e.target)) { - appsDropdownMenu.classList.remove('show'); - } - }); - } - - // 绑定应用列表控制事件 - const btnToggleSysApps = document.getElementById('btn-toggle-sys-apps'); - if (btnToggleSysApps) { - btnToggleSysApps.addEventListener('click', () => { - showingSystemApps = !showingSystemApps; - - const textSpan = document.getElementById('sys-apps-text'); - const iconWrap = document.getElementById('sys-apps-icon'); - - if (textSpan) textSpan.textContent = showingSystemApps ? '隐藏系统应用' : '显示系统应用'; - - // 更新 Lucide 图标 - if (iconWrap) { - //重新创建图标 - const p = iconWrap.parentNode; - const newIcon = document.createElement('i'); - newIcon.setAttribute('data-lucide', showingSystemApps ? 'eye-off' : 'eye'); - newIcon.id = 'sys-apps-icon'; - p.replaceChild(newIcon, iconWrap); - createIcons({ - icons: { - Eye, - EyeOff - }, - nameAttr: 'data-lucide' - }); - } - - loadApps(); - appsDropdownMenu.classList.remove('show'); - }); - } - - // 智能选择功能 - const btnSmartSelect = document.getElementById('btn-smart-select'); - if (btnSmartSelect) { - const smartKeywords = ["相册", "抖音", "快手", "视频", "哔哩哔哩", "bili", "pili", "netflix", "youtube", "tiktok", "x"]; - btnSmartSelect.addEventListener('click', () => { - const items = document.querySelectorAll('.app-list-item'); - items.forEach(item => { - const name = item.querySelector('.app-name').textContent.toLowerCase(); - const checkbox = item.querySelector('.app-checkbox'); - - let match = false; - for (const kw of smartKeywords) { - // 对 x 采用更严格的匹配以防误伤字母 x 结尾的应用 - if (kw === 'x') { - if (name === 'x' || name === 'x (twitter)') { - match = true; - break; - } - } else if (name.includes(kw)) { - match = true; - break; - } - } - - if (match) { - checkbox.checked = true; - } - }); - updateUnsavedStyling(); - reorderDOMApps(); - appsDropdownMenu.classList.remove('show'); - }); - } - - // 手动添加包名功能 - const btnManualAdd = document.getElementById('btn-manual-add'); - if (btnManualAdd) { - btnManualAdd.addEventListener('click', async () => { - appsDropdownMenu.classList.remove('show'); - const pkg = prompt('请输入你要彻底屏蔽的完整应用包名(例如: com.example.app):'); - if (!pkg || !pkg.trim()) return; - - const realPkg = pkg.trim(); - const existing = document.querySelector(`.app-checkbox[data-pkg="${realPkg}"]`); - if (existing) { - existing.checked = true; - updateUnsavedStyling(); - reorderDOMApps(); - showToast('该应用已在列表中,已为你自动勾选并置顶'); - return; - } - - showToast('正在尝试获取应用信息...'); - let appData = { packageName: realPkg, appLabel: '未知 (手动添加)', isSystem: false, uid: '自定义' }; - try { - const info = await getPackagesInfo([realPkg]); - if (info && info.length > 0) { - appData = info[0]; - } - } catch { - // failed to fetch, use default - } - - 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(); reorderDOMApps(); }); - - const customCheckbox = document.createElement('span'); - customCheckbox.className = 'app-checkbox-custom'; - checkboxLabel.appendChild(checkbox); - checkboxLabel.appendChild(customCheckbox); - - const infoDiv = document.createElement('div'); - infoDiv.className = 'app-info'; - - const nameSpan = document.createElement('span'); - nameSpan.className = 'app-name'; - 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); - - 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('已成功添加并勾选'); - }); - } - - // 全选功能 - const btnSelectAll = document.getElementById('btn-select-all'); - if (btnSelectAll) { - btnSelectAll.addEventListener('click', () => { - const checkboxes = document.querySelectorAll('.app-checkbox'); - checkboxes.forEach(cb => { - cb.checked = true; - }); - updateUnsavedStyling(); - appsDropdownMenu.classList.remove('show'); - }); - } - - // 全不选功能 - const btnSelectNone = document.getElementById('btn-select-none'); - if (btnSelectNone) { - btnSelectNone.addEventListener('click', () => { - const checkboxes = document.querySelectorAll('.app-checkbox'); - checkboxes.forEach(cb => { - cb.checked = false; - }); - updateUnsavedStyling(); - appsDropdownMenu.classList.remove('show'); - }); - } - - // 反选功能 - const btnInvertSelection = document.getElementById('btn-invert-selection'); - if (btnInvertSelection) { - btnInvertSelection.addEventListener('click', () => { - const checkboxes = document.querySelectorAll('.app-checkbox'); - checkboxes.forEach(cb => { - cb.checked = !cb.checked; - }); - updateUnsavedStyling(); - appsDropdownMenu.classList.remove('show'); - }); - } - - // 刷新按钮 (重排应用,不保存) - const btnAppsRefresh = document.getElementById('btn-apps-refresh'); - if (btnAppsRefresh) { - btnAppsRefresh.addEventListener('click', () => { - reorderDOMApps(); - }); - } - - // 保存黑名单 - const btnSaveBlacklist = document.getElementById('btn-save-blacklist'); - if (btnSaveBlacklist) { - btnSaveBlacklist.addEventListener('click', async () => { - showToast('保存中...'); - const checkboxes = document.querySelectorAll('.app-checkbox'); - const selectedPkgs = []; - 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(allEntries); - updateUnsavedStyling(); - reorderDOMApps(); - } else { - 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) { - inputAppSearch.addEventListener('input', (e) => { - const keyword = e.target.value.trim().toLowerCase(); - const items = document.querySelectorAll('.app-list-item'); - let visibleCount = 0; - - items.forEach(item => { - const name = item.querySelector('.app-name').textContent; - const pkg = item.querySelector('.app-pkg').textContent.toLowerCase(); - - if (!keyword || pkg.includes(keyword) || PinyinMatch.match(name, keyword)) { - item.style.display = 'flex'; - visibleCount++; - } else { - item.style.display = 'none'; - } - }); - - const badge = document.getElementById('app-count-badge'); - if (badge) badge.textContent = visibleCount; - }); - } + setupAppsEvents(); // 全局拦截链接点击,调用系统浏览器 document.addEventListener('click', async (e) => { diff --git a/webui/src/style.css b/webui/src/style.css index 6b1cbaf..a98bd57 100644 --- a/webui/src/style.css +++ b/webui/src/style.css @@ -1001,611 +1001,3 @@ input:checked + .slider:before { to { transform: rotate(360deg); } } -/* Logs */ -.log-output { - font-family: 'Google Sans Code', 'JetBrains Mono', 'Consolas', monospace; - font-size: 0.6875rem; - padding: var(--spacing-m); - background-color: #0d0e12; - color: #e3e3e3; - border-radius: var(--border-radius-m); - border: 1px solid rgba(255, 255, 255, 0.05); - flex: 1; - max-height: 60vh; - overflow-y: auto; - margin: 0; - white-space: pre-wrap; - word-wrap: break-word; - line-height: 1.5; - scrollbar-width: thin; - scrollbar-color: var(--md-sys-color-outline-variant) transparent; -} - -.log-output::-webkit-scrollbar { - width: 4px; -} - -.log-output::-webkit-scrollbar-thumb { - background-color: var(--md-sys-color-outline-variant); - border-radius: 4px; -} - -.log-filter-select { - padding: 0 12px; - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: 8px; - background-color: var(--md-sys-color-surface-container-high); - color: var(--md-sys-color-on-surface); - font-family: inherit; - font-size: 0.8125rem; - height: 32px; - cursor: pointer; - outline: none; - transition: all 0.22s ease; -} - -.log-filter-select:focus { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.2); -} - -.log-output::-webkit-scrollbar { - display: none; /* Chrome, Safari */ -} - -/* Simple Toast */ -.top-blur { - position: fixed; - top: 0; - left: 0; - right: 0; - height: calc(85px + var(--safe-area-inset-top, 0px)); - z-index: 998; - pointer-events: none; - /* 基础暗色背景,增强状态栏文字可读性 */ - background: linear-gradient(to bottom, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.85) 0%, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0.4) 40%, - rgba(var(--md-sys-color-background-rgb, 17, 19, 24), 0) 100% - ); - /* 核心:毛玻璃滤镜 */ - -webkit-backdrop-filter: blur(16px); - backdrop-filter: blur(16px); - /* 梯度蒙版:越往上越模糊的核心逻辑 */ - -webkit-mask-image: linear-gradient(to bottom, - rgba(0,0,0,1) 0%, - rgba(0,0,0,1) 30%, - rgba(0,0,0,0.7) 60%, - rgba(0,0,0,0) 100% - ); - mask-image: linear-gradient(to bottom, - rgba(0,0,0,1) 0%, - rgba(0,0,0,1) 30%, - rgba(0,0,0,0.7) 60%, - rgba(0,0,0,0) 100% - ); - transform: translateZ(0); /* 开启 GPU 加速 */ - opacity: 0; - transition: opacity 0.3s ease; -} - -.top-blur.scrolled { - opacity: 1; -} - -.toast { - position: fixed; - bottom: 24px; - left: 50%; - transform: translateX(-50%) translateY(100px); - background-color: var(--md-sys-color-on-surface); - color: var(--md-sys-color-surface); - padding: 12px 24px; - border-radius: var(--border-radius-s); - font-size: 0.875rem; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); - transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); - z-index: 1000; - width: max-content; - max-width: 90vw; - text-align: center; -} - -.toast.show { - transform: translateX(-50%) translateY(0); -} - -/* Floating Navigation Bar */ -.floating-navbar { - position: fixed; - bottom: calc(18px + var(--safe-area-inset-bottom, 0px)); - left: 50%; - transform: translateX(-50%) translateZ(0); /* 居中并开启硬件加速 */ - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - background: rgba(var(--md-sys-color-surface-container-high-rgb, 43, 41, 48), 0.6); - -webkit-backdrop-filter: blur(20px) saturate(180%); - backdrop-filter: blur(20px) saturate(180%); - will-change: backdrop-filter; - padding: 8px 16px; - border-radius: 28px; - border: 1px solid rgba(255, 255, 255, 0.08); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 8px 32px rgba(0, 0, 0, 0.3); - z-index: 999; - width: fit-content; - max-width: calc(100% - 32px); - user-select: none; - -webkit-user-select: none; - -webkit-tap-highlight-color: transparent; - touch-action: none; /* Prevents browser scroll during drag */ -} - -.navbar-slider { - position: absolute; - left: 0; - top: 8px; - bottom: 8px; - height: auto; - background: rgba(var(--md-sys-color-primary-rgb, 168, 199, 250), 0.35); - -webkit-backdrop-filter: blur(8px) saturate(120%); - backdrop-filter: blur(8px) saturate(120%); - transform: translateZ(0); - border-radius: 20px; - transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s ease; - pointer-events: none; - z-index: 0; - border: 1px solid rgba(var(--md-sys-color-primary-rgb, 168, 199, 250), 0.4); - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); -} - -.navbar-btn { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - gap: 5px; - padding: 6px 12px; - background-color: transparent; - border: none; - color: var(--md-sys-color-on-surface-variant); - font-size: 0.75rem; - cursor: pointer; - border-radius: 8px; - transition: all 0.2s ease; - flex: 1; - max-width: 90px; - white-space: nowrap; - position: relative; - z-index: 1; -} - -.navbar-btn i, .navbar-btn svg { - width: 20px; - height: 20px; - display: flex; - align-items: center; - justify-content: center; -} - -.navbar-btn span { - font-size: 0.75rem; -} - -.navbar-btn:active { - /* No scaling here, we rely on the slider feedback */ -} - -.navbar-btn.active { - color: var(--md-sys-color-on-primary-container); -} - -/* Dropdown Menu */ -.dropdown-container { - position: relative; -} - -.dropdown-menu { - position: absolute; - top: 100%; - right: 0; - margin-top: 8px; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-s); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); - min-width: 160px; - opacity: 0; - visibility: hidden; - transform: translateY(-8px); - transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28); - z-index: 100; - display: flex; - flex-direction: column; - padding: 4px; -} - -.dropdown-menu.show { - opacity: 1; - visibility: visible; - transform: translateY(0); -} - -.dropdown-item { - display: flex; - align-items: center; - gap: 12px; - padding: 10px 12px; - border-radius: 4px; - cursor: pointer; - color: var(--md-sys-color-on-surface); - font-size: 0.875rem; - transition: background-color 0.2s; -} - -.dropdown-item:hover { - background-color: var(--md-sys-color-surface-container); -} - -.dropdown-item:active { - background-color: var(--md-sys-color-surface); -} - -.dropdown-item svg { - color: var(--md-sys-color-primary); - width: 18px; - height: 18px; -} - -.dropdown-item-danger { - color: var(--md-sys-color-error, #cf6679); -} - -.dropdown-item-danger svg { - color: var(--md-sys-color-error, #cf6679); -} - -.app-list-hint { - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface-variant); - margin-top: 0; - margin-bottom: var(--spacing-m); -} - -/* App Search */ -.app-search-container { - display: flex; - align-items: center; - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - border-radius: var(--border-radius-m); - padding: 8px 12px; - margin-bottom: var(--spacing-m); - transition: border-color 0.2s, box-shadow 0.2s; -} - -.app-search-container:focus-within { - border-color: var(--md-sys-color-primary); - box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.3); -} - -.search-icon { - width: 18px; - height: 18px; - color: var(--md-sys-color-on-surface-variant); - margin-right: 8px; -} - -.app-search-input { - flex: 1; - width: 100%; - min-width: 0; - background: transparent; - border: none; - color: var(--md-sys-color-on-surface); - font-size: 0.875rem; - outline: none; - font-family: inherit; -} - -.app-search-input::placeholder { - color: var(--md-sys-color-on-surface-variant); -} - -.count-badge { - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - font-size: 0.75rem; - font-weight: 600; - padding: 2px 8px; - border-radius: 20px; - margin-left: 8px; - white-space: nowrap; - opacity: 0.85; -} - -/* App List */ -.app-list-container { - display: flex; - flex-direction: column; - gap: var(--spacing-s); - max-height: 60vh; - overflow-y: auto; - border-radius: var(--border-radius-m); - padding: 0; -} - -.app-list-container::-webkit-scrollbar { - display: none; -} - -.app-list-item { - display: flex; - 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-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); -} - -.app-checkbox-label { - display: flex; - align-items: center; - cursor: pointer; - position: relative; -} - -.app-checkbox { - opacity: 0; - position: absolute; - width: 0; - height: 0; -} - -.app-checkbox-custom { - width: 20px; - height: 20px; - border: 2px solid var(--md-sys-color-outline); - border-radius: 4px; - display: flex; - align-items: center; - justify-content: center; - transition: all 0.2s; -} - -.app-checkbox:checked + .app-checkbox-custom { - background-color: var(--md-sys-color-primary); - border-color: var(--md-sys-color-primary); -} - -.app-checkbox.unsaved:checked + .app-checkbox-custom { - background-color: #4caf50; - border-color: #4caf50; -} - -.app-checkbox:checked + .app-checkbox-custom::after { - content: ''; - width: 5px; - height: 10px; - border: solid var(--md-sys-color-on-primary); - border-width: 0 2px 2px 0; - transform: rotate(45deg); - margin-bottom: 2px; -} - -.app-info { - display: flex; - flex-direction: column; - flex: 1; - overflow: hidden; -} - -.app-name { - font-size: 1rem; - font-weight: 500; - color: var(--md-sys-color-on-surface); - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.app-pkg { - font-size: 0.8125rem; - color: var(--md-sys-color-on-surface-variant); - font-family: 'Google Sans Code', monospace; - display: flex; - flex-wrap: wrap; - align-items: center; - gap: 6px; - word-break: break-all; - line-height: 1.4; -} - -.app-badge { - background-color: var(--md-sys-color-primary-container); - color: var(--md-sys-color-on-primary-container); - padding: 0 4px; - border-radius: 4px; - font-size: 0.65rem; - font-weight: bold; -} - -.app-icon { - width: 40px; - height: 40px; - border-radius: 8px; - object-fit: cover; - flex-shrink: 0; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.app-icon-fallback { - width: 40px; - height: 40px; - border-radius: 8px; - background: linear-gradient(135deg, var(--md-sys-color-primary-container), rgba(168, 199, 250, 0.5)); - color: var(--md-sys-color-on-primary-container); - display: flex; - align-items: center; - justify-content: center; - font-size: 1.25rem; - font-weight: bold; - flex-shrink: 0; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.app-uid { - font-size: 0.65rem; - color: var(--md-sys-color-on-surface-variant); - background-color: var(--md-sys-color-surface-container-high); - border: 1px solid var(--md-sys-color-outline-variant); - padding: 0 4px; - border-radius: 4px; - font-family: 'Google Sans Code', monospace; - 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); -} diff --git a/webui/src/utils.js b/webui/src/utils.js new file mode 100644 index 0000000..6fa4350 --- /dev/null +++ b/webui/src/utils.js @@ -0,0 +1,59 @@ +import { exec } from 'kernelsu'; + +export const CONFIG_DIR = '/data/adb/modules/LuminPro/config'; +export const PATH_CONFIG_DIR = '/data/adb/modules/LuminPro/config/path'; +export const BACKUP_DIR = '/data/adb/modules/LuminPro/config/.backup'; +export const PID_FILE = '/data/adb/modules/LuminPro/pid/inotifyd.pid'; +export const FLAG_FILE = '/data/adb/modules/LuminPro/pid/up.flag'; +export const STOP_FLAG_FILE = '/data/adb/modules/LuminPro/pid/stop.flag'; +export const LOG_FILE = '/data/adb/modules/LuminPro/service.log'; +export const DEFAULT_NOW_BRI_FILE = '/sys/class/backlight/panel0-backlight/brightness'; +export const DEFAULT_SYS_MAX_BRI_FILE = '/sys/class/backlight/panel0-backlight/max_brightness'; + +export function showToast(msg) { + const toast = document.getElementById('toast'); + toast.textContent = msg; + toast.classList.add('show'); + setTimeout(() => toast.classList.remove('show'), 3000); +} + +export async function runCmd(cmd) { + try { + const res = await exec(cmd); + return res; + } catch (e) { + // 调试模式数据模拟 + console.warn(`[DEBUG] 执行命令失败 (可能是非 KSU 环境): ${cmd}`); + + // 基础配置模拟 + if (cmd.includes('cat') && cmd.includes('ui_max_bri.txt')) return { errno: 0, stdout: '4095', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('max_bri.txt')) return { errno: 0, stdout: '3500', stderr: '' }; + if (cmd.includes('cat') && (cmd.includes('now_bri_file.txt') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '/sys/mock/brightness', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('inotify_events.txt')) return { errno: 0, stdout: 'c', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('log_max_size.txt')) return { errno: 0, stdout: '1024', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('steps_num.txt')) return { errno: 0, stdout: '100', stderr: '' }; + + // 状态模拟 + if (cmd.includes('cat') && (cmd.includes('brightness') || cmd.includes('now_bri_file.txt'))) return { errno: 0, stdout: '1200', stderr: '' }; + if (cmd.includes('cat') && (cmd.includes('max_brightness') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '4095', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('inotifyd.pid')) return { errno: 0, stdout: '12345', stderr: '' }; + if (cmd.includes('settings get system screen_brightness_mode')) return { errno: 0, stdout: '1', stderr: '' }; + if (cmd.includes('[ -f') && cmd.includes('stop.flag')) return { errno: 0, stdout: '0', stderr: '' }; + + // 日志模拟 + if (cmd.includes('tail') && cmd.includes('service.log')) { + return { errno: 0, stdout: '[2026-04-07 15:40:01] [INFO] 服务启动成功\n[2026-04-07 15:41:05] [DEBUG] 亮度调整: 1200 -> 1250\n[2026-04-07 15:42:10] [INFO] 切换至峰值亮度模式\n[2026-04-07 15:43:22] [WARN] 检测到极低亮度设定', stderr: '' }; + } + + // 文档模拟 + if (cmd.includes('cat') && cmd.includes('.md')) return { errno: 0, stdout: '# 调试模式说明\n\n当前处于 **Web 调试模式**,显示的是模拟出的测试数据。\n\n- 状态卡片:全部固定为运行中。\n- 应用列表:预设了 150 个常用模拟应用。\n- 按钮:所有变更仅在当前页面生效,不会写入手机文件系统。', stderr: '' }; + if (cmd.includes('cat') && cmd.includes('.txt')) return { errno: 0, stdout: '这是 NOTE.txt 的模拟内容,用于测试纯文本渲染。', stderr: '' }; + + return { errno: -1, stdout: '', stderr: String(e) }; + } +} + +export async function writeFile(path, content) { + const safeContent = String(content).replace(/'/g, "'\\''"); + return runCmd(`echo -n '${safeContent}' > "${path}"`); +}