forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenSynth.ts
More file actions
36 lines (35 loc) · 1.34 KB
/
Copy pathscreenSynth.ts
File metadata and controls
36 lines (35 loc) · 1.34 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
36
// src/main/ipc/screenSynth.ts
import { ipcMain } from 'electron'
import { listRewindFrames } from './db'
import {
getScreenSynthState,
updateScreenSynthState,
advanceWatermark,
recordRun
} from '../screenSynth/state'
import type { ScreenFrameLite, ScreenSynthState, ScreenSynthRun } from '../../shared/types'
export function registerScreenSynthHandlers(): void {
// Frames since the watermark, stripped to the fields synthesis needs (no image bytes).
ipcMain.handle('screenSynth:framesSince', async (): Promise<ScreenFrameLite[]> => {
const { watermarkTs } = getScreenSynthState()
// +1 so we never re-emit the exact watermark frame.
const frames = listRewindFrames(watermarkTs + 1, Date.now())
return frames.map((f) => ({
ts: f.ts,
app: f.app,
windowTitle: f.windowTitle,
processName: f.processName,
ocrText: f.ocrText
}))
})
ipcMain.handle('screenSynth:getState', async () => getScreenSynthState())
ipcMain.handle('screenSynth:setState', async (_e, patch: Partial<ScreenSynthState>) =>
updateScreenSynthState(patch)
)
ipcMain.handle('screenSynth:advanceWatermark', async (_e, ts: number) => {
if (typeof ts === 'number' && ts > 0) advanceWatermark(ts)
})
ipcMain.handle('screenSynth:recordRun', async (_e, run: ScreenSynthRun) =>
recordRun(run.lastRunAt, run.lastCount)
)
}