Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 37 38 39 40 41 42 | 1x 3x 3x 3x 1x 3x 1x 1x 1x 1x | import { IPC_CHANNELS } from '@shared/contracts'
import type { TimerSnapshot } from '@shared/types'
import type { TimerService } from '@main/services/timerService'
interface SnapshotWindow {
webContents: {
send(channel: string, snapshot: TimerSnapshot): void
}
}
export const createBroadcastTimerSnapshot =
(getWindows: () => SnapshotWindow[]) =>
(snapshot: TimerSnapshot): void => {
for (const window of getWindows()) {
window.webContents.send(IPC_CHANNELS.timer.snapshot, snapshot)
}
}
export const wireTimerSnapshotBroadcast = ({
timer,
getWindows
}: {
timer: Pick<TimerService, 'onSnapshot'>
getWindows: () => SnapshotWindow[]
}): (() => void) => timer.onSnapshot(createBroadcastTimerSnapshot(getWindows))
export const createTimerTickRunner = ({
timer,
onError
}: {
timer: Pick<TimerService, 'tick'>
onError(error: unknown): void
}) => {
return async (): Promise<void> => {
try {
await timer.tick()
} catch (error) {
onError(error)
}
}
}
|