forked from OctoWoW/OctoLauncher
5dca94a3fc
Manifest-based CDN updater and mod manager for the OctoWoW 1.12.1 client: launcher-owned realmlist, torrent-backed content sync with bundled aria2c, antivirus and Defender exclusion handling, hardware-aware render distance, optional client tweaks and mods, and the in-launcher news feed.
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { Tray, Menu, nativeImage, app } from 'electron';
|
|
import Logger from 'electron-log/main';
|
|
|
|
import icon from '~build/icon.png?asset';
|
|
|
|
import { mainWindow } from '~main/index';
|
|
|
|
let tray: Tray | null = null;
|
|
let isMinimizedToTray = false;
|
|
|
|
const restoreWindow = () => {
|
|
if (!mainWindow) return;
|
|
mainWindow.show();
|
|
if (mainWindow.isMinimized()) mainWindow.restore();
|
|
mainWindow.focus();
|
|
isMinimizedToTray = false;
|
|
};
|
|
|
|
const ensureTray = () => {
|
|
if (tray) return tray;
|
|
const trayIcon = nativeImage.createFromPath(icon).resize({ width: 16, height: 16 });
|
|
tray = new Tray(trayIcon);
|
|
tray.setToolTip('OctoLauncher');
|
|
tray.setContextMenu(
|
|
Menu.buildFromTemplate([
|
|
{ label: 'Show launcher', click: restoreWindow },
|
|
{ type: 'separator' },
|
|
{ label: 'Quit', click: () => app.quit() }
|
|
])
|
|
);
|
|
tray.on('click', restoreWindow);
|
|
return tray;
|
|
};
|
|
|
|
export const minimizeToTray = () => {
|
|
if (!mainWindow) return;
|
|
ensureTray();
|
|
mainWindow.hide();
|
|
isMinimizedToTray = true;
|
|
Logger.info('Minimized to tray');
|
|
};
|
|
|
|
export const restoreFromTray = () => {
|
|
if (!isMinimizedToTray) return;
|
|
restoreWindow();
|
|
};
|
|
|
|
export const isInTray = () => isMinimizedToTray;
|
|
|
|
export const destroyTray = () => {
|
|
tray?.destroy();
|
|
tray = null;
|
|
};
|