Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto redirect play button #630

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ export function GameDetailsContextProvider({
return window.electron.getDefaultDownloadsPath();
};

const selectGameExecutable = async () => {
const downloadsPath = await getDownloadsPath();
const selectGameExecutable = async (
gameInstallerFolderIfExists?: string
) => {
const downloadsPath =
gameInstallerFolderIfExists ?? (await getDownloadsPath());

return window.electron
.showOpenDialog({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export interface GameDetailsContext {
hasNSFWContentBlocked: boolean;
lastDownloadedOption: GameRepack | null;
setGameColor: React.Dispatch<React.SetStateAction<string>>;
selectGameExecutable: () => Promise<string | null>;
selectGameExecutable: (
gameInstallerFolderIfExists?: string
) => Promise<string | null>;
updateGame: () => Promise<void>;
setShowRepacksModal: React.Dispatch<React.SetStateAction<boolean>>;
setShowGameOptionsModal: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down
26 changes: 24 additions & 2 deletions src/renderer/src/pages/game-details/hero/hero-panel-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PlusCircleIcon,
} from "@primer/octicons-react";
import { Button } from "@renderer/components";
import { useDownload, useLibrary } from "@renderer/hooks";
import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks";
import { useContext, useState } from "react";
import { useTranslation } from "react-i18next";
import * as styles from "./hero-panel-actions.css";
Expand All @@ -18,6 +18,10 @@ export function HeroPanelActions() {

const { isGameDeleting } = useDownload();

const userPreferences = useAppSelector(
(state) => state.userPreferences.value
);

const {
game,
repacks,
Expand Down Expand Up @@ -63,7 +67,25 @@ export function HeroPanelActions() {
return;
}

const gameExecutablePath = await selectGameExecutable();
let gameInstallerFolderIfExists

if (game && game.folderName) {
let downloadsPath = await window.electron.getDefaultDownloadsPath();
if (userPreferences?.downloadsPath)
downloadsPath = userPreferences.downloadsPath;

const folderSeparator =
window.electron.platform == "win32" ? "\\" : "/";

gameInstallerFolderIfExists =
(game.downloadPath ?? downloadsPath) +
folderSeparator +
game.folderName!;
}

const gameExecutablePath = await selectGameExecutable(
gameInstallerFolderIfExists
);
if (gameExecutablePath)
window.electron.openGame(
game.id,
Expand Down
Loading