(feat): improve tray icon
(qol): update todo
This commit is contained in:
parent
92e5003989
commit
943203eeaf
10 changed files with 205 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Tray, Menu } from "electron";
|
||||
import { app, BrowserWindow, Menu, nativeImage, Tray } from "electron";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
|
|
@ -7,19 +7,56 @@ let tray: Tray | null = null;
|
|||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export function initTray() {
|
||||
const iconPath = path.join(__dirname, "../../build/icons/32x32.png");
|
||||
function getTrayIconPath(filename: string) {
|
||||
if (app.isPackaged) return path.join(process.resourcesPath, "icons", filename);
|
||||
return path.resolve(__dirname, "../../build/icons", filename);
|
||||
}
|
||||
|
||||
tray = new Tray(iconPath); // keep reference alive
|
||||
export function setTrayCallStatus(
|
||||
inCall: boolean,
|
||||
iconDataUrl?: string,
|
||||
) {
|
||||
if (!tray) return;
|
||||
|
||||
if (inCall && iconDataUrl) {
|
||||
const image = nativeImage.createFromDataURL(iconDataUrl);
|
||||
if (!image.isEmpty()) {
|
||||
tray.setImage(image);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
tray.setImage(getTrayIconPath("32x32.png"));
|
||||
}
|
||||
|
||||
export function initTray(getMainWindow: () => BrowserWindow | null) {
|
||||
tray = new Tray(getTrayIconPath("32x32.png")); // keep reference alive
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{ label: "Restart", type: "normal" },
|
||||
{ label: "Quit", type: "normal" },
|
||||
{
|
||||
label: "Restart",
|
||||
type: "normal",
|
||||
click: () => {
|
||||
app.relaunch();
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
{ label: "Quit", type: "normal", click: () => app.quit() },
|
||||
]);
|
||||
|
||||
tray.setContextMenu(contextMenu);
|
||||
|
||||
tray.on("click", (event) => {
|
||||
console.log(event);
|
||||
tray.on("click", () => {
|
||||
const mainWindow = getMainWindow();
|
||||
if (!mainWindow) return;
|
||||
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue