Closing the main window hides it on macOS and Windows; the page and the Host keep running and the next show resumes the same document. Windows gets a permanent tray icon (open / quit) and a one-time notification the first time the window is hidden after installation. Every ordinary quit entry asks the Host over a new quit-inspection IPC request for active tasks (same rule as the update restart check) and armed scheduled reminders (schedule family of workspace/session-activity for loaded sessions). Nothing to interrupt quits silently; otherwise a native message box explains what stops, with Quit as the default and Cancel on Esc. Inspection failure or a missed two-second deadline counts as running tasks. The installer restart, fatal recovery, the development restart command, and OS session end skip the confirmation. Also: defer the downloaded-update confirmation while the window is hidden, render the tray ICO from the vector icon, and point the installer's running-application message at the tray. Closes #4013
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
/** Windows system tray: the always-present way back to a hidden window and the explicit quit entry. */
|
|
|
|
import { Menu, nativeImage, Tray } from 'electron'
|
|
import type { DesktopLocale } from './locale.ts'
|
|
|
|
/** Main-process actions the tray triggers; both run the same paths as the window and application menu. */
|
|
export interface DesktopTrayOptions {
|
|
/** Multi-size ICO rendered by `scripts/render-tray-icon.ts`; Windows picks the bitmap for the display scale. */
|
|
readonly iconPath: string
|
|
readonly locale: () => DesktopLocale
|
|
/** Show and focus the primary window. */
|
|
readonly open: () => void
|
|
/** Request quit through the same confirmation as every other quit entry. */
|
|
readonly quit: () => void
|
|
}
|
|
|
|
/** Tray icon present for the whole run, not only while the window is hidden. */
|
|
export class DesktopTray {
|
|
private tray: Tray | undefined
|
|
|
|
/** @param options - Icon path, locale reader, and the open and quit actions. */
|
|
constructor(private readonly options: DesktopTrayOptions) {
|
|
const tray = new Tray(nativeImage.createFromPath(options.iconPath))
|
|
this.tray = tray
|
|
tray.on('click', () => { options.open() })
|
|
this.relabel()
|
|
}
|
|
|
|
/** Rebuild the tooltip and context menu in the current locale. */
|
|
relabel(): void {
|
|
const tray = this.tray
|
|
if (tray === undefined) return
|
|
const { messages } = this.options.locale()
|
|
tray.setToolTip(messages.aboutProduct)
|
|
tray.setContextMenu(Menu.buildFromTemplate([
|
|
{ label: messages.openApplication, click: () => { this.options.open() } },
|
|
{ type: 'separator' },
|
|
{ label: messages.quitApplication, click: () => { this.options.quit() } },
|
|
]))
|
|
}
|
|
|
|
/** Remove the icon; called once the quit is confirmed so no dead icon outlives the process. */
|
|
dispose(): void {
|
|
const tray = this.tray
|
|
this.tray = undefined
|
|
tray?.destroy()
|
|
}
|
|
}
|