feat: create start menu shortcut on Windows

This commit is contained in:
Zamitto
2025-05-02 08:08:58 -03:00
parent f20314de57
commit a922d9a166
10 changed files with 57 additions and 29 deletions

View File

@@ -32,6 +32,7 @@ import type {
Theme,
Badge,
Auth,
ShortcutLocation,
} from "@types";
import type { AxiosProgressEvent } from "axios";
import type disk from "diskusage";
@@ -101,7 +102,11 @@ declare global {
objectId: string,
title: string
) => Promise<void>;
createGameShortcut: (shop: GameShop, objectId: string) => Promise<boolean>;
createGameShortcut: (
shop: GameShop,
objectId: string,
location: ShortcutLocation
) => Promise<boolean>;
updateExecutablePath: (
shop: GameShop,
objectId: string,

View File

@@ -1,7 +1,7 @@
import { useContext, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, CheckboxField, Modal, TextField } from "@renderer/components";
import type { LibraryGame } from "@types";
import type { LibraryGame, ShortcutLocation } from "@types";
import { gameDetailsContext } from "@renderer/context";
import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal";
import { useDownload, useToast, useUserDetails } from "@renderer/hooks";
@@ -107,15 +107,18 @@ export function GameOptionsModal({
}
};
const handleCreateShortcut = async () => {
const handleCreateShortcut = async (location: ShortcutLocation) => {
window.electron
.createGameShortcut(game.shop, game.objectId)
.createGameShortcut(game.shop, game.objectId, location)
.then((success) => {
if (success) {
showSuccessToast(t("create_shortcut_success"));
} else {
showErrorToast(t("create_shortcut_error"));
}
})
.catch(() => {
showErrorToast(t("create_shortcut_error"));
});
};
@@ -176,6 +179,9 @@ export function GameOptionsModal({
const shouldShowWinePrefixConfiguration =
window.electron.platform === "linux";
const shouldShowCreateStartMenuShortcut =
window.electron.platform === "win32";
const handleResetAchievements = async () => {
setIsDeletingAchievements(true);
try {
@@ -278,9 +284,20 @@ export function GameOptionsModal({
>
{t("open_folder")}
</Button>
<Button onClick={handleCreateShortcut} theme="outline">
<Button
onClick={() => handleCreateShortcut("desktop")}
theme="outline"
>
{t("create_shortcut")}
</Button>
{shouldShowCreateStartMenuShortcut && (
<Button
onClick={() => handleCreateShortcut("start_menu")}
theme="outline"
>
{t("create_start_menu_shortcut")}
</Button>
)}
</div>
)}
</div>