This commit is contained in:
parent
a414cb7f3f
commit
df3b48dfbc
5 changed files with 47 additions and 5 deletions
|
|
@ -9,4 +9,5 @@ export function registerReminderHandlers(service: MeetingReminderService): void
|
||||||
registerHandler('reminder:dismiss', async ({ key }) => service.dismiss(key))
|
registerHandler('reminder:dismiss', async ({ key }) => service.dismiss(key))
|
||||||
registerHandler('reminder:join', async ({ key }) => service.join(key))
|
registerHandler('reminder:join', async ({ key }) => service.join(key))
|
||||||
registerHandler('reminder:open', async ({ key }) => service.open(key))
|
registerHandler('reminder:open', async ({ key }) => service.open(key))
|
||||||
|
registerHandler('reminder:resize', async ({ height }) => service.resizeWindow(height))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,10 @@ export class MeetingReminderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Закрыть все показанные напоминания (окно закрыли средствами ОС). */
|
/** Закрыть все показанные напоминания (окно закрыли средствами ОС). */
|
||||||
|
resizeWindow(contentHeight: number): void {
|
||||||
|
this.window.setContentHeight(contentHeight)
|
||||||
|
}
|
||||||
|
|
||||||
dismissAll(): void {
|
dismissAll(): void {
|
||||||
this.active.clear()
|
this.active.clear()
|
||||||
this.publish()
|
this.publish()
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ import { join } from 'node:path'
|
||||||
import type { MeetingReminder } from '@shared/types/calendar'
|
import type { MeetingReminder } from '@shared/types/calendar'
|
||||||
|
|
||||||
const WINDOW_WIDTH = 380
|
const WINDOW_WIDTH = 380
|
||||||
const CARD_HEIGHT = 150
|
const CARD_HEIGHT = 150 // оценка до первого замера из рендерера
|
||||||
const MAX_VISIBLE_CARDS = 3
|
const MAX_VISIBLE_CARDS = 3
|
||||||
|
const MIN_HEIGHT = 100
|
||||||
|
const MAX_HEIGHT_RATIO = 0.8
|
||||||
const SCREEN_MARGIN = 16
|
const SCREEN_MARGIN = 16
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -14,6 +16,8 @@ const SCREEN_MARGIN = 16
|
||||||
export class ReminderWindow {
|
export class ReminderWindow {
|
||||||
private win: BrowserWindow | null = null
|
private win: BrowserWindow | null = null
|
||||||
private reminders: MeetingReminder[] = []
|
private reminders: MeetingReminder[] = []
|
||||||
|
/** Реальная высота контента, замеренная в рендерере; null — замера ещё не было */
|
||||||
|
private contentHeight: number | null = null
|
||||||
|
|
||||||
/** @param onClosedByUser окно закрыли средствами ОС (Alt+F4) — напоминания считаем закрытыми */
|
/** @param onClosedByUser окно закрыли средствами ОС (Alt+F4) — напоминания считаем закрытыми */
|
||||||
constructor(private readonly onClosedByUser: () => void) {}
|
constructor(private readonly onClosedByUser: () => void) {}
|
||||||
|
|
@ -37,6 +41,15 @@ export class ReminderWindow {
|
||||||
if (!win.isVisible()) win.showInactive()
|
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 {
|
destroy(): void {
|
||||||
if (this.win && !this.win.isDestroyed()) this.win.destroy()
|
if (this.win && !this.win.isDestroyed()) this.win.destroy()
|
||||||
this.win = null
|
this.win = null
|
||||||
|
|
@ -91,7 +104,13 @@ export class ReminderWindow {
|
||||||
|
|
||||||
private placeWindow(win: BrowserWindow, count: number): void {
|
private placeWindow(win: BrowserWindow, count: number): void {
|
||||||
const { workArea } = screen.getPrimaryDisplay()
|
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({
|
win.setBounds({
|
||||||
x: workArea.x + workArea.width - WINDOW_WIDTH - SCREEN_MARGIN,
|
x: workArea.x + workArea.width - WINDOW_WIDTH - SCREEN_MARGIN,
|
||||||
y: workArea.y + workArea.height - height - SCREEN_MARGIN,
|
y: workArea.y + workArea.height - height - SCREEN_MARGIN,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { useIpc } from '../composables/useIpc'
|
import { useIpc } from '../composables/useIpc'
|
||||||
import { useSettingsStore } from '../stores/settings.store'
|
import { useSettingsStore } from '../stores/settings.store'
|
||||||
|
|
@ -12,21 +12,37 @@ useSettingsStore()
|
||||||
const { invoke, on } = useIpc()
|
const { invoke, on } = useIpc()
|
||||||
const reminders = ref<MeetingReminder[]>([])
|
const reminders = ref<MeetingReminder[]>([])
|
||||||
const now = ref(Date.now())
|
const now = ref(Date.now())
|
||||||
|
const listEl = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
let unsubUpdate: (() => void) | null = null
|
let unsubUpdate: (() => void) | null = null
|
||||||
let clockTimer: ReturnType<typeof setInterval> | null = null
|
let clockTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
let resizeObserver: ResizeObserver | null = null
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
unsubUpdate = on('reminder:update', (data) => { reminders.value = data.reminders })
|
unsubUpdate = on('reminder:update', (data) => { reminders.value = data.reminders })
|
||||||
clockTimer = setInterval(() => { now.value = Date.now() }, 15_000)
|
clockTimer = setInterval(() => { now.value = Date.now() }, 15_000)
|
||||||
reminders.value = await invoke('reminder:list')
|
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(() => {
|
onUnmounted(() => {
|
||||||
unsubUpdate?.()
|
unsubUpdate?.()
|
||||||
|
resizeObserver?.disconnect()
|
||||||
if (clockTimer) clearInterval(clockTimer)
|
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 {
|
function badge(reminder: MeetingReminder): string {
|
||||||
if (reminder.event.isAllDay) return 'Сегодня весь день'
|
if (reminder.event.isAllDay) return 'Сегодня весь день'
|
||||||
const minutesLeft = Math.ceil((new Date(reminder.event.start).getTime() - now.value) / 60_000)
|
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>
|
<template>
|
||||||
<div class="reminder-shell">
|
<div class="reminder-shell">
|
||||||
|
<div ref="listEl" class="reminder-list">
|
||||||
<div
|
<div
|
||||||
v-for="reminder in reminders"
|
v-for="reminder in reminders"
|
||||||
:key="reminder.key"
|
:key="reminder.key"
|
||||||
|
|
@ -83,6 +100,7 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -95,8 +113,7 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
.reminder-card {
|
.reminder-card {
|
||||||
/* высота карточки совпадает с CARD_HEIGHT в main/windows/reminder-window.ts */
|
min-height: 110px;
|
||||||
height: 150px;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ export interface IpcChannelMap {
|
||||||
'reminder:dismiss': [{ key: string }, void]
|
'reminder:dismiss': [{ key: string }, void]
|
||||||
'reminder:join': [{ key: string }, void]
|
'reminder:join': [{ key: string }, void]
|
||||||
'reminder:open': [{ key: string }, void]
|
'reminder:open': [{ key: string }, void]
|
||||||
|
'reminder:resize': [{ height: number }, void]
|
||||||
|
|
||||||
'update:check': [void, { hasUpdate: boolean; version?: string; notes?: string }]
|
'update:check': [void, { hasUpdate: boolean; version?: string; notes?: string }]
|
||||||
'update:download': [void, void]
|
'update:download': [void, void]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue