mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
feat: add tray for macos
This commit is contained in:
parent
5528330265
commit
e45991cb7c
@ -5,6 +5,7 @@ import {
|
|||||||
MenuItemConstructorOptions,
|
MenuItemConstructorOptions,
|
||||||
Tray,
|
Tray,
|
||||||
app,
|
app,
|
||||||
|
nativeImage,
|
||||||
shell,
|
shell,
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import { is } from "@electron-toolkit/utils";
|
import { is } from "@electron-toolkit/utils";
|
||||||
@ -88,7 +89,16 @@ export class WindowManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static createSystemTray(language: string) {
|
public static createSystemTray(language: string) {
|
||||||
const tray = new Tray(trayIcon);
|
let tray;
|
||||||
|
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
const macIcon = nativeImage
|
||||||
|
.createFromPath(trayIcon)
|
||||||
|
.resize({ width: 24, height: 24 });
|
||||||
|
tray = new Tray(macIcon);
|
||||||
|
} else {
|
||||||
|
tray = new Tray(trayIcon);
|
||||||
|
}
|
||||||
|
|
||||||
const updateSystemTray = async () => {
|
const updateSystemTray = async () => {
|
||||||
const games = await gameRepository.find({
|
const games = await gameRepository.find({
|
||||||
@ -149,9 +159,14 @@ export class WindowManager {
|
|||||||
return contextMenu;
|
return contextMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showContextMenu = async () => {
|
||||||
|
const contextMenu = await updateSystemTray();
|
||||||
|
tray.popUpContextMenu(contextMenu);
|
||||||
|
};
|
||||||
|
|
||||||
tray.setToolTip("Hydra");
|
tray.setToolTip("Hydra");
|
||||||
|
|
||||||
if (process.platform === "win32" || process.platform === "linux") {
|
if (process.platform !== "darwin") {
|
||||||
tray.addListener("click", () => {
|
tray.addListener("click", () => {
|
||||||
if (this.mainWindow) {
|
if (this.mainWindow) {
|
||||||
if (WindowManager.mainWindow?.isMinimized())
|
if (WindowManager.mainWindow?.isMinimized())
|
||||||
@ -164,10 +179,10 @@ export class WindowManager {
|
|||||||
this.createMainWindow();
|
this.createMainWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
tray.addListener("right-click", async () => {
|
tray.addListener("right-click", showContextMenu);
|
||||||
const contextMenu = await updateSystemTray();
|
} else {
|
||||||
tray.popUpContextMenu(contextMenu);
|
tray.addListener("click", showContextMenu);
|
||||||
});
|
tray.addListener("right-click", showContextMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user