28 lines
674 B
TypeScript
28 lines
674 B
TypeScript
|
|
import { nativeImage } from "electron/common";
|
||
|
|
import { Menu, Tray } from "electron/main";
|
||
|
|
import type { Tray as ElectronTray } from "electron/main";
|
||
|
|
|
||
|
|
let tray: ElectronTray | null = null;
|
||
|
|
|
||
|
|
function createFallbackIcon() {
|
||
|
|
return nativeImage.createEmpty();
|
||
|
|
}
|
||
|
|
|
||
|
|
export function initTray(onOpen: () => void): ElectronTray {
|
||
|
|
if (tray) {
|
||
|
|
return tray;
|
||
|
|
}
|
||
|
|
|
||
|
|
tray = new Tray(createFallbackIcon());
|
||
|
|
tray.setToolTip("GEO Rankly Desktop");
|
||
|
|
tray.setContextMenu(
|
||
|
|
Menu.buildFromTemplate([
|
||
|
|
{ label: "Open", click: () => onOpen() },
|
||
|
|
{ type: "separator" },
|
||
|
|
{ role: "quit", label: "Quit" },
|
||
|
|
]),
|
||
|
|
);
|
||
|
|
tray.on("click", () => onOpen());
|
||
|
|
return tray;
|
||
|
|
}
|