forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage.ts
More file actions
35 lines (34 loc) · 1.26 KB
/
Copy pathusage.ts
File metadata and controls
35 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ipcMain } from 'electron'
import { listAppUsage } from './db'
import { getUsageSettings, setUsageSettings } from '../usage/usageSettings'
import {
flushForegroundMonitor,
pruneUsageNow,
startForegroundMonitor,
stopForegroundMonitor
} from '../usage/foregroundMonitor'
import { seedUserAssistOnce } from '../usage/userAssistSeed'
import type { UsageSettings } from '../../shared/types'
export function registerUsageHandlers(): void {
ipcMain.handle('usage:list', async () => listAppUsage())
// Force an immediate flush of the in-memory tally, then return the fresh rows.
ipcMain.handle('usage:flush', async () => {
flushForegroundMonitor()
return listAppUsage()
})
ipcMain.handle('usage:getSettings', async () => getUsageSettings())
ipcMain.handle('usage:setSettings', async (_e, next: UsageSettings) => {
const saved = setUsageSettings(next)
if (saved.enabled) {
// First time tracking is turned on, seed historical usage (once-guarded).
seedUserAssistOnce()
startForegroundMonitor()
// Apply a changed retention window now (startForegroundMonitor no-ops when
// already running, so it wouldn't re-prune on its own).
pruneUsageNow()
} else {
stopForegroundMonitor()
}
return saved
})
}