Initial commit

This commit is contained in:
AnRil
2026-05-16 13:43:29 +07:00
commit 688a86b611
208 changed files with 44350 additions and 0 deletions

65
src/main/notifications.ts Normal file
View File

@@ -0,0 +1,65 @@
import { Notification, app } from 'electron'
import type { Exercise, MatchSummary, NotificationMode } from '@shared/types'
import { IPC } from '@shared/ipc'
import {
createReminderWindow,
getReminderWindow,
showReminderWindow
} from './windows'
export function fireReminder(exercise: Exercise, mode: NotificationMode): void {
if (mode === 'toast' || mode === 'both') showToast(exercise)
if (mode === 'modal' || mode === 'both') showModal(exercise)
}
export function fireMatchSummary(summary: MatchSummary): void {
if (Notification.isSupported()) {
const totalReps = summary.results.reduce((s, r) => s + r.reps, 0)
const n = new Notification({
title: `Матч ${summary.gameName} завершён`,
body: `Челленджей: ${summary.results.length}, всего повторений: ${totalReps}`,
silent: false
})
n.on('click', () => showReminderWindow())
n.show()
}
const win = createReminderWindow()
const send = (): void => {
win.webContents.send(IPC.evtMatchEnd, summary)
}
if (win.webContents.isLoading()) {
win.webContents.once('did-finish-load', send)
} else {
send()
}
showReminderWindow()
}
function showToast(exercise: Exercise): void {
if (!Notification.isSupported()) return
const n = new Notification({
title: app.getName(),
body: `${exercise.name}${exercise.reps}`,
silent: false
})
n.on('click', () => showReminderWindow())
n.show()
}
function showModal(exercise: Exercise): void {
const win = createReminderWindow()
const send = (): void => {
win.webContents.send(IPC.evtFire, exercise)
}
if (win.webContents.isLoading()) {
win.webContents.once('did-finish-load', send)
} else {
send()
}
showReminderWindow()
}
export function notifyReminderClosed(): void {
const win = getReminderWindow()
if (win && !win.isDestroyed()) win.hide()
}