feat: create game shortcut

This commit is contained in:
Zamitto 2024-06-05 16:42:45 -03:00
parent 6dfd7279dc
commit 086ee8ac04
7 changed files with 52 additions and 1 deletions

View File

@ -48,6 +48,7 @@
"classnames": "^2.5.1", "classnames": "^2.5.1",
"color": "^4.2.3", "color": "^4.2.3",
"color.js": "^1.2.0", "color.js": "^1.2.0",
"create-desktop-shortcuts": "^1.11.0",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"electron-log": "^5.1.4", "electron-log": "^5.1.4",
"electron-updater": "^6.1.8", "electron-updater": "^6.1.8",

View File

@ -10,6 +10,7 @@ import "./catalogue/search-games";
import "./catalogue/search-game-repacks"; import "./catalogue/search-game-repacks";
import "./hardware/get-disk-free-space"; import "./hardware/get-disk-free-space";
import "./library/add-game-to-library"; import "./library/add-game-to-library";
import "./library/create-game-shortcut";
import "./library/close-game"; import "./library/close-game";
import "./library/delete-game-folder"; import "./library/delete-game-folder";
import "./library/get-game-by-object-id"; import "./library/get-game-by-object-id";

View 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);

View File

@ -74,6 +74,8 @@ contextBridge.exposeInMainWorld("electron", {
shop, shop,
executablePath executablePath
), ),
createGameShortcut: (id: number) =>
ipcRenderer.invoke("createGameShortcut", id),
updateExecutablePath: (id: number, executablePath: string) => updateExecutablePath: (id: number, executablePath: string) =>
ipcRenderer.invoke("updateExecutablePath", id, executablePath), ipcRenderer.invoke("updateExecutablePath", id, executablePath),
getLibrary: () => ipcRenderer.invoke("getLibrary"), getLibrary: () => ipcRenderer.invoke("getLibrary"),

View File

@ -59,6 +59,7 @@ declare global {
shop: GameShop, shop: GameShop,
executablePath: string | null executablePath: string | null
) => Promise<void>; ) => Promise<void>;
createGameShortcut: (id: number) => Promise<boolean>;
updateExecutablePath: (id: number, executablePath: string) => Promise<void>; updateExecutablePath: (id: number, executablePath: string) => Promise<void>;
getLibrary: () => Promise<LibraryGame[]>; getLibrary: () => Promise<LibraryGame[]>;
openGameInstaller: (gameId: number) => Promise<boolean>; openGameInstaller: (gameId: number) => Promise<boolean>;

View File

@ -50,6 +50,10 @@ export function GameOptionsModal({
} }
}; };
const handleCreateShortcut = async () => {
await window.electron.createGameShortcut(game.id);
};
const handleDeleteGame = async () => { const handleDeleteGame = async () => {
await removeGameInstaller(game.id); await removeGameInstaller(game.id);
}; };
@ -160,6 +164,15 @@ export function GameOptionsModal({
{t("open_download_options")} {t("open_download_options")}
</Button> </Button>
</div> </div>
<div className={styles.downloadSourceField}>
<Button
onClick={handleCreateShortcut}
theme="outline"
disabled={deleting}
>
{"criar atalho na area de trabalho"}
</Button>
</div>
</div> </div>
</Modal> </Modal>
</> </>

View File

@ -2403,6 +2403,13 @@ crc@^3.8.0:
dependencies: dependencies:
buffer "^5.1.0" buffer "^5.1.0"
create-desktop-shortcuts@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/create-desktop-shortcuts/-/create-desktop-shortcuts-1.11.0.tgz#8eed89329e9bce70dece46d02a80573fe1f2536d"
integrity sha512-nmVtPVqNyMuAyMpDnd7l++hb2laqCWZXnHQaFhqGT1YEi2Ve3unu6QyuyIpGxAwIscNHcG1Ehnl+lFw6ygB2nQ==
dependencies:
which "2.0.2"
cross-fetch-ponyfill@^1.0.3: cross-fetch-ponyfill@^1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/cross-fetch-ponyfill/-/cross-fetch-ponyfill-1.0.3.tgz#5c5524e3bd3374e71d5016c2327e416369a57527" resolved "https://registry.yarnpkg.com/cross-fetch-ponyfill/-/cross-fetch-ponyfill-1.0.3.tgz#5c5524e3bd3374e71d5016c2327e416369a57527"
@ -6278,7 +6285,7 @@ which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.9:
gopd "^1.0.1" gopd "^1.0.1"
has-tostringtag "^1.0.2" has-tostringtag "^1.0.2"
which@^2.0.1: which@2.0.2, which@^2.0.1:
version "2.0.2" version "2.0.2"
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==