fix
All checks were successful
Release / release (push) Successful in 2m46s

This commit is contained in:
d.a.kolesov 2026-11-11 10:20:37 +07:00
parent a414cb7f3f
commit df3b48dfbc
5 changed files with 47 additions and 5 deletions

View file

@ -9,4 +9,5 @@ export function registerReminderHandlers(service: MeetingReminderService): void
registerHandler('reminder:dismiss', async ({ key }) => service.dismiss(key))
registerHandler('reminder:join', async ({ key }) => service.join(key))
registerHandler('reminder:open', async ({ key }) => service.open(key))
registerHandler('reminder:resize', async ({ height }) => service.resizeWindow(height))
}

View file

@ -118,6 +118,10 @@ export class MeetingReminderService {
}
/** Закрыть все показанные напоминания (окно закрыли средствами ОС). */
resizeWindow(contentHeight: number): void {
this.window.setContentHeight(contentHeight)
}
dismissAll(): void {
this.active.clear()
this.publish()

View file

@ -3,8 +3,10 @@ import { join } from 'node:path'
import type { MeetingReminder } from '@shared/types/calendar'
const WINDOW_WIDTH = 380
const CARD_HEIGHT = 150
const CARD_HEIGHT = 150 // оценка до первого замера из рендерера
const MAX_VISIBLE_CARDS = 3
const MIN_HEIGHT = 100
const MAX_HEIGHT_RATIO = 0.8
const SCREEN_MARGIN = 16
/**
@ -14,6 +16,8 @@ const SCREEN_MARGIN = 16
export class ReminderWindow {
private win: BrowserWindow | null = null
private reminders: MeetingReminder[] = []
/** Реальная высота контента, замеренная в рендерере; null — замера ещё не было */
private contentHeight: number | null = null
/** @param onClosedByUser окно закрыли средствами ОС (Alt+F4) — напоминания считаем закрытыми */
constructor(private readonly onClosedByUser: () => void) {}
@ -37,6 +41,15 @@ export class ReminderWindow {
if (!win.isVisible()) win.showInactive()
}
/** Рендерер сообщает фактическую высоту карточек — подгоняем окно под неё */
setContentHeight(height: number): void {
if (!Number.isFinite(height)) return
this.contentHeight = Math.ceil(height)
if (this.win && !this.win.isDestroyed() && this.reminders.length > 0) {
this.placeWindow(this.win, this.reminders.length)
}
}
destroy(): void {
if (this.win && !this.win.isDestroyed()) this.win.destroy()
this.win = null
@ -91,7 +104,13 @@ export class ReminderWindow {
private placeWindow(win: BrowserWindow, count: number): void {
const { workArea } = screen.getPrimaryDisplay()
const height = Math.min(count, MAX_VISIBLE_CARDS) * CARD_HEIGHT
const estimated = Math.min(count, MAX_VISIBLE_CARDS) * CARD_HEIGHT
const height = Math.round(
Math.min(
Math.max(this.contentHeight ?? estimated, MIN_HEIGHT),
workArea.height * MAX_HEIGHT_RATIO
)
)
win.setBounds({
x: workArea.x + workArea.width - WINDOW_WIDTH - SCREEN_MARGIN,
y: workArea.y + workArea.height - height - SCREEN_MARGIN,

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { format } from 'date-fns'
import { useIpc } from '../composables/useIpc'
import { useSettingsStore } from '../stores/settings.store'
@ -12,21 +12,37 @@ useSettingsStore()
const { invoke, on } = useIpc()
const reminders = ref<MeetingReminder[]>([])
const now = ref(Date.now())
const listEl = ref<HTMLElement | null>(null)
let unsubUpdate: (() => void) | null = null
let clockTimer: ReturnType<typeof setInterval> | null = null
let resizeObserver: ResizeObserver | null = null
onMounted(async () => {
unsubUpdate = on('reminder:update', (data) => { reminders.value = data.reminders })
clockTimer = setInterval(() => { now.value = Date.now() }, 15_000)
reminders.value = await invoke('reminder:list')
// Окно подгоняется под фактическую высоту карточек, а не под фиксированную константу
resizeObserver = new ResizeObserver(reportHeight)
if (listEl.value) resizeObserver.observe(listEl.value)
await nextTick()
reportHeight()
})
watch(reminders, () => void nextTick(reportHeight))
onUnmounted(() => {
unsubUpdate?.()
resizeObserver?.disconnect()
if (clockTimer) clearInterval(clockTimer)
})
function reportHeight(): void {
const height = listEl.value?.offsetHeight ?? 0
if (height > 0) void invoke('reminder:resize', { height })
}
function badge(reminder: MeetingReminder): string {
if (reminder.event.isAllDay) return 'Сегодня весь день'
const minutesLeft = Math.ceil((new Date(reminder.event.start).getTime() - now.value) / 60_000)
@ -48,6 +64,7 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
<template>
<div class="reminder-shell">
<div ref="listEl" class="reminder-list">
<div
v-for="reminder in reminders"
:key="reminder.key"
@ -83,6 +100,7 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
</button>
</div>
</div>
</div>
</div>
</template>
@ -95,8 +113,7 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
}
.reminder-card {
/* высота карточки совпадает с CARD_HEIGHT в main/windows/reminder-window.ts */
height: 150px;
min-height: 110px;
box-sizing: border-box;
display: flex;
flex-direction: column;

View file

@ -72,6 +72,7 @@ export interface IpcChannelMap {
'reminder:dismiss': [{ key: string }, void]
'reminder:join': [{ key: string }, void]
'reminder:open': [{ key: string }, void]
'reminder:resize': [{ height: number }, void]
'update:check': [void, { hasUpdate: boolean; version?: string; notes?: string }]
'update:download': [void, void]