2026-04-19 14:18:20 +08:00
|
|
|
import { nativeImage } from "electron/common";
|
2026-04-20 09:52:48 +08:00
|
|
|
import { Menu, Tray, app } from "electron/main";
|
2026-04-19 14:18:20 +08:00
|
|
|
import type { Tray as ElectronTray } from "electron/main";
|
|
|
|
|
|
|
|
|
|
let tray: ElectronTray | null = null;
|
|
|
|
|
|
2026-04-20 09:52:48 +08:00
|
|
|
const TRAY_ICON_BASE64 =
|
|
|
|
|
"iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAnUlEQVR4nN2UwQmAMAxF360Dee8I" +
|
|
|
|
|
"LuNIxT2cpIv0oJcIEqJGMSIG/qX8fn5/msDfqgcKUIEmqHLW3xHsgAmYTzAJ1+2yOURXNI/77qLo" +
|
|
|
|
|
"VvzQufX8EchAEmQ5s2LZjUCThwMTg8E3IymG07PSzotFqoqUHcJZ3akWSTctOYST0cT3hMOiCGte" +
|
|
|
|
|
"2HcjakCIHGmiltDW+eNrU7t/dNF/txaahq+VoZ+VygAAAABJRU5ErkJggg==";
|
|
|
|
|
|
|
|
|
|
function createTrayIcon() {
|
|
|
|
|
const buffer = Buffer.from(TRAY_ICON_BASE64, "base64");
|
|
|
|
|
const icon = nativeImage.createFromBuffer(buffer);
|
|
|
|
|
if (icon.isEmpty()) {
|
|
|
|
|
return nativeImage.createEmpty();
|
|
|
|
|
}
|
|
|
|
|
icon.setTemplateImage(true);
|
|
|
|
|
return icon;
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function initTray(onOpen: () => void): ElectronTray {
|
|
|
|
|
if (tray) {
|
|
|
|
|
return tray;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 09:52:48 +08:00
|
|
|
tray = new Tray(createTrayIcon());
|
2026-04-19 14:18:20 +08:00
|
|
|
tray.setToolTip("GEO Rankly Desktop");
|
|
|
|
|
tray.setContextMenu(
|
|
|
|
|
Menu.buildFromTemplate([
|
|
|
|
|
{ label: "Open", click: () => onOpen() },
|
|
|
|
|
{ type: "separator" },
|
2026-04-20 09:52:48 +08:00
|
|
|
{ label: "Quit", click: () => app.quit() },
|
2026-04-19 14:18:20 +08:00
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
tray.on("click", () => onOpen());
|
|
|
|
|
return tray;
|
|
|
|
|
}
|