Merge pull request #1645 from hydralauncher/feat/create-start-menu-shortcut-on-windows

feat: create start menu shortcut on windows
This commit is contained in:
Zamitto
2025-05-02 11:44:29 -03:00
committed by GitHub
13 changed files with 60 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "hydralauncher",
"version": "3.4.6",
"version": "3.4.7",
"description": "Hydra",
"main": "./out/main/index.js",
"author": "Los Broxas",

View File

@@ -198,7 +198,8 @@
"download_error_not_cached_on_hydra": "This download is not available on Nimbus.",
"game_removed_from_favorites": "Game removed from favorites",
"game_added_to_favorites": "Game added to favorites",
"automatically_extract_downloaded_files": "Automatically extract downloaded files"
"automatically_extract_downloaded_files": "Automatically extract downloaded files",
"create_start_menu_shortcut": "Create Start Menu shortcut"
},
"activation": {
"title": "Activate Hydra",

View File

@@ -187,7 +187,8 @@
"download_error_not_cached_on_hydra": "Este download não está disponível no Nimbus.",
"game_removed_from_favorites": "Jogo removido dos favoritos",
"game_added_to_favorites": "Jogo adicionado aos favoritos",
"automatically_extract_downloaded_files": "Extrair automaticamente os arquivos baixados"
"automatically_extract_downloaded_files": "Extrair automaticamente os arquivos baixados",
"create_start_menu_shortcut": "Criar atalho no Menu Iniciar"
},
"activation": {
"title": "Ativação",

View File

@@ -178,7 +178,8 @@
"download_error_not_cached_on_real_debrid": "Este download não está disponível no Real-Debrid e a verificação do status do download não está disponível.",
"download_error_not_cached_on_torbox": "Este download não está disponível no TorBox e a verificação do status do download não está disponível.",
"game_removed_from_favorites": "Jogo removido dos favoritos",
"game_added_to_favorites": "Jogo adicionado aos favoritos"
"game_added_to_favorites": "Jogo adicionado aos favoritos",
"create_start_menu_shortcut": "Criar atalho no Menu Iniciar"
},
"activation": {
"title": "Ativação",

View File

@@ -8,6 +8,14 @@ export const defaultDownloadsPath = SystemPath.getPath("downloads");
export const isStaging = import.meta.env.MAIN_VITE_API_URL.includes("staging");
export const windowsStartMenuPath = path.join(
SystemPath.getPath("appData"),
"Microsoft",
"Windows",
"Start Menu",
"Programs"
);
export const levelDatabasePath = path.join(
SystemPath.getPath("userData"),
`hydra-db${isStaging ? "-staging" : ""}`

View File

@@ -3,14 +3,16 @@ import createDesktopShortcut from "create-desktop-shortcuts";
import path from "node:path";
import { app } from "electron";
import { removeSymbolsFromName } from "@shared";
import { GameShop } from "@types";
import { GameShop, ShortcutLocation } from "@types";
import { gamesSublevel, levelKeys } from "@main/level";
import { SystemPath } from "@main/services/system-path";
import { windowsStartMenuPath } from "@main/constants";
const createGameShortcut = async (
_event: Electron.IpcMainInvokeEvent,
shop: GameShop,
objectId: string
objectId: string,
location: ShortcutLocation
): Promise<boolean> => {
const gameKey = levelKeys.game(shop, objectId);
const game = await gamesSublevel.get(gameKey);
@@ -25,7 +27,10 @@ const createGameShortcut = async (
const options = {
filePath,
name: removeSymbolsFromName(game.title),
outputPath: SystemPath.getPath("desktop"),
outputPath:
location === "desktop"
? SystemPath.getPath("desktop")
: windowsStartMenuPath,
};
return createDesktopShortcut({

View File

@@ -1,19 +1,7 @@
import { registerEvent } from "../register-event";
import AutoLaunch from "auto-launch";
import { app } from "electron";
import path from "path";
import fs from "node:fs";
import { logger } from "@main/services";
import { SystemPath } from "@main/services/system-path";
const windowsStartupPath = path.join(
SystemPath.getPath("appData"),
"Microsoft",
"Windows",
"Start Menu",
"Programs",
"Startup"
);
const autoLaunch = async (
_event: Electron.IpcMainInvokeEvent,
@@ -31,10 +19,6 @@ const autoLaunch = async (
logger.error(err);
});
} else {
if (process.platform == "win32") {
fs.rm(path.join(windowsStartupPath, "Hydra.vbs"), () => {});
}
appLauncher.disable().catch((err) => {
logger.error(err);
});

View File

@@ -91,7 +91,7 @@ export class CommonRedistManager {
for (const redist of this.redistributables) {
const filePath = path.join(commonRedistPath, redist);
if (fs.existsSync(filePath)) {
if (fs.existsSync(filePath) && redist !== "install.bat") {
continue;
}

View File

@@ -16,6 +16,7 @@ import type {
GameAchievement,
Theme,
FriendRequestSync,
ShortcutLocation,
} from "@types";
import type { AuthPage, CatalogueCategory } from "@shared";
import type { AxiosProgressEvent } from "axios";
@@ -122,8 +123,11 @@ contextBridge.exposeInMainWorld("electron", {
),
addGameToLibrary: (shop: GameShop, objectId: string, title: string) =>
ipcRenderer.invoke("addGameToLibrary", shop, objectId, title),
createGameShortcut: (shop: GameShop, objectId: string) =>
ipcRenderer.invoke("createGameShortcut", shop, objectId),
createGameShortcut: (
shop: GameShop,
objectId: string,
location: ShortcutLocation
) => ipcRenderer.invoke("createGameShortcut", shop, objectId, location),
updateExecutablePath: (
shop: GameShop,
objectId: string,

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

@@ -26,7 +26,7 @@ export const toastSlice = createSlice({
state.title = action.payload.title;
state.message = action.payload.message;
state.type = action.payload.type;
state.duration = action.payload.duration ?? 2000;
state.duration = action.payload.duration ?? 3000;
state.visible = true;
},
closeToast: (state) => {

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>

View File

@@ -1,5 +1,7 @@
export type GameShop = "steam" | "epic";
export type ShortcutLocation = "desktop" | "start_menu";
export interface UnlockedAchievement {
name: string;
unlockTime: number;