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

68
src/main/tray.ts Normal file
View File

@@ -0,0 +1,68 @@
import { Tray, Menu, nativeImage, app } from 'electron'
import { join } from 'node:path'
import { showMainWindow } from './windows'
import { isPaused, setPaused, forceCheck } from './scheduler'
import { snoozeAll } from './state-actions'
let tray: Tray | null = null
function resolveTrayIcon(): Electron.NativeImage {
// Try resources/, fallback to a transparent 16x16 if missing during dev.
const candidates = [
join(process.resourcesPath, 'tray.png'),
join(__dirname, '../../resources/tray.png'),
join(app.getAppPath(), 'resources/tray.png')
]
for (const p of candidates) {
const img = nativeImage.createFromPath(p)
if (!img.isEmpty()) return img
}
return nativeImage.createEmpty()
}
export function createTray(): Tray {
if (tray) return tray
const icon = resolveTrayIcon()
tray = new Tray(icon)
tray.setToolTip('Exercise Reminder')
refreshMenu()
tray.on('click', () => showMainWindow())
tray.on('double-click', () => showMainWindow())
return tray
}
export function refreshMenu(): void {
if (!tray) return
const paused = isPaused()
const menu = Menu.buildFromTemplate([
{ label: 'Открыть', click: () => showMainWindow() },
{ type: 'separator' },
{
label: paused ? 'Возобновить напоминания' : 'Пауза напоминаний',
click: () => {
setPaused(!paused)
refreshMenu()
if (!paused) forceCheck()
}
},
{
label: 'Отложить все на 15 мин',
click: () => snoozeAll(15)
},
{ type: 'separator' },
{
label: 'Выход',
click: () => {
app.quit()
}
}
])
tray.setContextMenu(menu)
}
export function destroyTray(): void {
if (tray) {
tray.destroy()
tray = null
}
}