feat: 添加遮罩筛选

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-25 13:02:05 +08:00
co-authored by Copilot
parent d1c5b818d9
commit d82872ad18
7 changed files with 109 additions and 6 deletions
+12 -1
View File
@@ -28,6 +28,7 @@ interface TitleUsage {
interface MutableAppUsage {
processId: string
rawProcessName: string
rawProcessPath: string
durationMs: number
titleDurations: Map<string, number>
}
@@ -111,12 +112,14 @@ const getLocalDateUtcMs = (parts: DateParts, tzOffsetMinutes: number) => {
const normalizeProcess = (processPath: string, title: string) => {
const rawProcessName = win32.basename(processPath || '').trim()
const rawProcessPath = processPath.trim()
const normalizedTitle = cleanTitle(title)
const fallbackId = normalizedTitle ? `title:${normalizedTitle.toLowerCase()}` : 'unknown'
return {
processId: rawProcessName ? rawProcessName.toLowerCase() : fallbackId,
rawProcessName
rawProcessName,
rawProcessPath
}
}
@@ -228,6 +231,7 @@ const addDurationToUsageMap = (
usageMap: Map<string, MutableAppUsage>,
processId: string,
rawProcessName: string,
rawProcessPath: string,
title: string,
durationMs: number
) => {
@@ -240,12 +244,16 @@ const addDurationToUsageMap = (
if (!existing.rawProcessName && rawProcessName) {
existing.rawProcessName = rawProcessName
}
if (!existing.rawProcessPath && rawProcessPath) {
existing.rawProcessPath = rawProcessPath
}
return
}
usageMap.set(processId, {
processId,
rawProcessName,
rawProcessPath,
durationMs,
titleDurations: new Map([[title, durationMs]])
})
@@ -266,6 +274,7 @@ const buildAppList = (usageMap: Map<string, MutableAppUsage>) => {
processId: app.processId,
processName: resolveProcessDisplayName(app.rawProcessName, sortedTitles),
rawProcessName: app.rawProcessName,
processPath: app.rawProcessPath,
durationSeconds: Math.round(app.durationMs / 1000),
percentage: totalDurationMs > 0 ? Number(((app.durationMs / totalDurationMs) * 100).toFixed(2)) : 0,
titleCount: sortedTitles.length,
@@ -384,6 +393,7 @@ async function handleScreenTime(req: NextRequest) {
aggregateUsageMap,
process.processId,
process.rawProcessName,
process.rawProcessPath,
title,
aggregateContributionMs
)
@@ -393,6 +403,7 @@ async function handleScreenTime(req: NextRequest) {
selectedDayUsageMap,
process.processId,
process.rawProcessName,
process.rawProcessPath,
title,
selectedDayContributionMs
)