Merge branch 'main' into feat/force-use-yarn

This commit is contained in:
Abduladil Sunnat 2024-05-16 11:45:02 -04:00 committed by GitHub
commit e908cc6273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,10 +1,19 @@
import { BrowserWindow, Menu, Tray, app } from "electron"; import {
BrowserWindow,
Menu,
MenuItem,
MenuItemConstructorOptions,
Tray,
app,
shell,
} from "electron";
import { is } from "@electron-toolkit/utils"; import { is } from "@electron-toolkit/utils";
import { t } from "i18next"; import { t } from "i18next";
import path from "node:path"; import path from "node:path";
import icon from "@resources/icon.png?asset"; import icon from "@resources/icon.png?asset";
import trayIcon from "@resources/tray-icon.png?asset"; import trayIcon from "@resources/tray-icon.png?asset";
import { userPreferencesRepository } from "@main/repository"; import { gameRepository, userPreferencesRepository } from "@main/repository";
import { IsNull, Not } from "typeorm";
export class WindowManager { export class WindowManager {
public static mainWindow: Electron.BrowserWindow | null = null; public static mainWindow: Electron.BrowserWindow | null = null;
@ -77,6 +86,30 @@ export class WindowManager {
public static createSystemTray(language: string) { public static createSystemTray(language: string) {
const tray = new Tray(trayIcon); const tray = new Tray(trayIcon);
const updateSystemTray = async () => {
const games = await gameRepository.find({
where: {
isDeleted: false,
executablePath: Not(IsNull()),
lastTimePlayed: Not(IsNull()),
},
take: 5,
order: {
updatedAt: "DESC",
},
});
const recentlyPlayedGames: Array<MenuItemConstructorOptions | MenuItem> =
games.map(({ title, executablePath }) => ({
label: title,
type: "normal",
click: async () => {
if (!executablePath) return;
shell.openPath(executablePath);
},
}));
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
label: t("open", { label: t("open", {
@ -92,6 +125,13 @@ export class WindowManager {
} }
}, },
}, },
{
type: "separator",
},
...recentlyPlayedGames,
{
type: "separator",
},
{ {
label: t("quit", { label: t("quit", {
ns: "system_tray", ns: "system_tray",
@ -102,8 +142,10 @@ export class WindowManager {
}, },
]); ]);
return contextMenu;
};
tray.setToolTip("Hydra"); tray.setToolTip("Hydra");
tray.setContextMenu(contextMenu);
if (process.platform === "win32" || process.platform === "linux") { if (process.platform === "win32" || process.platform === "linux") {
tray.addListener("click", () => { tray.addListener("click", () => {
@ -117,6 +159,11 @@ export class WindowManager {
this.createMainWindow(); this.createMainWindow();
}); });
tray.addListener("right-click", async () => {
const contextMenu = await updateSystemTray();
tray.popUpContextMenu(contextMenu);
});
} }
} }
} }