mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 22:06:17 +00:00
Merge branch 'fix/game_asset_changing_path' of https://github.com/hydralauncher/hydra into fix/game_asset_changing_path
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
&__item-container {
|
||||
position: relative;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
&__item {
|
||||
@@ -97,7 +96,7 @@
|
||||
|
||||
&__submenu {
|
||||
position: absolute;
|
||||
left: calc(100% - 2px);
|
||||
left: 100%;
|
||||
top: 0;
|
||||
background-color: globals.$background-color;
|
||||
border: 1px solid globals.$border-color;
|
||||
|
||||
@@ -144,9 +144,9 @@ export function ContextMenu({
|
||||
|
||||
if (parentRect.right + submenuWidth > viewportWidth - 8) {
|
||||
styles.left = "auto";
|
||||
styles.right = "calc(100% - 2px)";
|
||||
styles.right = "100%";
|
||||
} else {
|
||||
styles.left = "calc(100% - 2px)";
|
||||
styles.left = "100%";
|
||||
styles.right = undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,11 @@ export function GameContextMenu({
|
||||
canPlay,
|
||||
isDeleting,
|
||||
isGameDownloading,
|
||||
isGameRunning,
|
||||
hasRepacks,
|
||||
shouldShowCreateStartMenuShortcut,
|
||||
handlePlayGame,
|
||||
handleCloseGame,
|
||||
handleToggleFavorite,
|
||||
handleCreateShortcut,
|
||||
handleCreateSteamShortcut,
|
||||
@@ -57,10 +59,20 @@ export function GameContextMenu({
|
||||
const items: ContextMenuItemData[] = [
|
||||
{
|
||||
id: "play",
|
||||
label: canPlay ? t("play") : t("download"),
|
||||
icon: canPlay ? <PlayIcon size={16} /> : <DownloadIcon size={16} />,
|
||||
label: isGameRunning ? t("close") : canPlay ? t("play") : t("download"),
|
||||
icon: isGameRunning ? (
|
||||
<XIcon size={16} />
|
||||
) : canPlay ? (
|
||||
<PlayIcon size={16} />
|
||||
) : (
|
||||
<DownloadIcon size={16} />
|
||||
),
|
||||
onClick: () => {
|
||||
void handlePlayGame();
|
||||
if (isGameRunning) {
|
||||
void handleCloseGame();
|
||||
} else {
|
||||
void handlePlayGame();
|
||||
}
|
||||
},
|
||||
disabled: isDeleting,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { LibraryGame, ShortcutLocation } from "@types";
|
||||
import { useDownload, useLibrary, useToast } from "@renderer/hooks";
|
||||
@@ -21,6 +21,7 @@ export function useGameActions(game: LibraryGame) {
|
||||
} = useDownload();
|
||||
|
||||
const [creatingSteamShortcut, setCreatingSteamShortcut] = useState(false);
|
||||
const [isGameRunning, setIsGameRunning] = useState(false);
|
||||
|
||||
const canPlay = Boolean(game.executablePath);
|
||||
const isDeleting = isGameDeleting(game.id);
|
||||
@@ -30,6 +31,20 @@ export function useGameActions(game: LibraryGame) {
|
||||
const shouldShowCreateStartMenuShortcut =
|
||||
window.electron.platform === "win32";
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = window.electron.onGamesRunning((gamesIds) => {
|
||||
const updatedIsGameRunning =
|
||||
!!game?.id &&
|
||||
!!gamesIds.find((gameRunning) => gameRunning.id == game.id);
|
||||
|
||||
setIsGameRunning(updatedIsGameRunning);
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [game?.id]);
|
||||
|
||||
const handlePlayGame = async () => {
|
||||
if (!canPlay) {
|
||||
const path = buildGameDetailsPath({
|
||||
@@ -75,6 +90,15 @@ export function useGameActions(game: LibraryGame) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCloseGame = async () => {
|
||||
try {
|
||||
await window.electron.closeGame(game.shop, game.objectId);
|
||||
} catch (error) {
|
||||
showErrorToast("Failed to close game");
|
||||
logger.error("Failed to close game", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleFavorite = async () => {
|
||||
try {
|
||||
if (game.favorite) {
|
||||
@@ -239,10 +263,12 @@ export function useGameActions(game: LibraryGame) {
|
||||
canPlay,
|
||||
isDeleting,
|
||||
isGameDownloading,
|
||||
isGameRunning,
|
||||
hasRepacks,
|
||||
shouldShowCreateStartMenuShortcut,
|
||||
creatingSteamShortcut,
|
||||
handlePlayGame,
|
||||
handleCloseGame,
|
||||
handleToggleFavorite,
|
||||
handleCreateShortcut,
|
||||
handleCreateSteamShortcut,
|
||||
|
||||
@@ -161,6 +161,14 @@ export function RepacksModal({
|
||||
|
||||
const [isFilterDrawerOpen, setIsFilterDrawerOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!visible) {
|
||||
setFilterTerm("");
|
||||
setSelectedFingerprints([]);
|
||||
setIsFilterDrawerOpen(false);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DownloadSettingsModal
|
||||
@@ -180,7 +188,11 @@ export function RepacksModal({
|
||||
className={`repacks-modal__filter-container ${isFilterDrawerOpen ? "repacks-modal__filter-container--drawer-open" : ""}`}
|
||||
>
|
||||
<div className="repacks-modal__filter-top">
|
||||
<TextField placeholder={t("filter")} onChange={handleFilter} />
|
||||
<TextField
|
||||
placeholder={t("filter")}
|
||||
value={filterTerm}
|
||||
onChange={handleFilter}
|
||||
/>
|
||||
{downloadSources.length > 0 && (
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user