mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: create game shortcut
This commit is contained in:
parent
6dfd7279dc
commit
086ee8ac04
7 changed files with 52 additions and 1 deletions
|
@ -10,6 +10,7 @@ import "./catalogue/search-games";
|
|||
import "./catalogue/search-game-repacks";
|
||||
import "./hardware/get-disk-free-space";
|
||||
import "./library/add-game-to-library";
|
||||
import "./library/create-game-shortcut";
|
||||
import "./library/close-game";
|
||||
import "./library/delete-game-folder";
|
||||
import "./library/get-game-by-object-id";
|
||||
|
|
26
src/main/events/library/create-game-shortcut.ts
Normal file
26
src/main/events/library/create-game-shortcut.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { gameRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import createDesktopShortcut from "create-desktop-shortcuts";
|
||||
|
||||
const createGameShortcut = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
id: number
|
||||
): Promise<boolean> => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: { id, executablePath: Not(IsNull()) },
|
||||
});
|
||||
|
||||
if (game) {
|
||||
const filePath = game.executablePath;
|
||||
return createDesktopShortcut({
|
||||
windows: { filePath },
|
||||
linux: { filePath },
|
||||
osx: { filePath },
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
registerEvent("createGameShortcut", createGameShortcut);
|
|
@ -74,6 +74,8 @@ contextBridge.exposeInMainWorld("electron", {
|
|||
shop,
|
||||
executablePath
|
||||
),
|
||||
createGameShortcut: (id: number) =>
|
||||
ipcRenderer.invoke("createGameShortcut", id),
|
||||
updateExecutablePath: (id: number, executablePath: string) =>
|
||||
ipcRenderer.invoke("updateExecutablePath", id, executablePath),
|
||||
getLibrary: () => ipcRenderer.invoke("getLibrary"),
|
||||
|
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
|
@ -59,6 +59,7 @@ declare global {
|
|||
shop: GameShop,
|
||||
executablePath: string | null
|
||||
) => Promise<void>;
|
||||
createGameShortcut: (id: number) => Promise<boolean>;
|
||||
updateExecutablePath: (id: number, executablePath: string) => Promise<void>;
|
||||
getLibrary: () => Promise<LibraryGame[]>;
|
||||
openGameInstaller: (gameId: number) => Promise<boolean>;
|
||||
|
|
|
@ -50,6 +50,10 @@ export function GameOptionsModal({
|
|||
}
|
||||
};
|
||||
|
||||
const handleCreateShortcut = async () => {
|
||||
await window.electron.createGameShortcut(game.id);
|
||||
};
|
||||
|
||||
const handleDeleteGame = async () => {
|
||||
await removeGameInstaller(game.id);
|
||||
};
|
||||
|
@ -160,6 +164,15 @@ export function GameOptionsModal({
|
|||
{t("open_download_options")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className={styles.downloadSourceField}>
|
||||
<Button
|
||||
onClick={handleCreateShortcut}
|
||||
theme="outline"
|
||||
disabled={deleting}
|
||||
>
|
||||
{"criar atalho na area de trabalho"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue