From 12a8a49ccb4ec835cc7aaf90ed83c11eb857025a Mon Sep 17 00:00:00 2001 From: Pierce Thompson Date: Tue, 26 Mar 2024 20:19:50 -0400 Subject: [PATCH] Add Proton path setting --- assets/jsons/translations/en.json | 5 ++++ src/main/ipcs/os-controls-ipcs.ts | 4 +++ src/main/preload.ts | 1 + .../settings/setting-container.component.tsx | 11 +++++-- .../pages/settings-page.component.tsx | 29 +++++++++++++++++-- src/renderer/preload.d.ts | 1 + src/renderer/services/bs-launcher.service.ts | 10 +++++++ 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index d229c817..43ae8f44 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -134,6 +134,11 @@ "description": "Change the default folder for Beat Saber versions and other upcoming features.", "choose-folder": "Choose folder" }, + "proton-path": { + "title": "Proton path", + "description": "Change the path to the Proton binary", + "choose-file": "Choose file" + }, "additional-content": { "title": "Additional content", "description": "Additional content that allows you to customize Beat Saber!", diff --git a/src/main/ipcs/os-controls-ipcs.ts b/src/main/ipcs/os-controls-ipcs.ts index 6d59e706..f4f928fa 100644 --- a/src/main/ipcs/os-controls-ipcs.ts +++ b/src/main/ipcs/os-controls-ipcs.ts @@ -15,6 +15,10 @@ ipc.on("choose-folder", (args, reply) => { reply(from(dialog.showOpenDialog({ properties: ["openDirectory"], defaultPath: args ?? "" }))); }); +ipc.on("choose-file", async (args, reply) => { + reply(from(dialog.showOpenDialog({ properties: ["openFile"], defaultPath: args ?? "" }))); +}); + ipc.on("window.progression",(args, reply, sender) => { BrowserWindow.fromWebContents(sender)?.setProgressBar(args / 100); reply(of(undefined)); diff --git a/src/main/preload.ts b/src/main/preload.ts index 61ced3c1..243f5e76 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -4,6 +4,7 @@ import { ProviderPlatform } from "shared/models/provider-platform.enum"; const sep = process.platform === ProviderPlatform.WINDOWS ? "\\" : "/"; contextBridge.exposeInMainWorld("electron", { + platform: process.platform, ipcRenderer: { sendMessage(channel: string, args: unknown[]) { ipcRenderer.send(channel, args); diff --git a/src/renderer/components/settings/setting-container.component.tsx b/src/renderer/components/settings/setting-container.component.tsx index c57adb3e..abb41b38 100644 --- a/src/renderer/components/settings/setting-container.component.tsx +++ b/src/renderer/components/settings/setting-container.component.tsx @@ -8,15 +8,20 @@ type Props = { minorTitle?: string; description?: string; children?: ReactNode; + os?: string; }; -export function SettingContainer({ id, className, title, minorTitle, description, children }: Props) { +export function SettingContainer({ id, className, title, minorTitle, description, children, os }: Props) { const t = useTranslation(); + if (os && os !== window.electron.platform) { + return <>; + } + return (
- {title &&

{t(title)}

} - {minorTitle &&

{t(minorTitle)}

} + {title &&

{t(title)}

} + {minorTitle &&

{t(minorTitle)}

} {description &&

{t(description)}

} {children}
diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index 7353f62d..76ec5a66 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -42,7 +42,7 @@ import { BsDownloaderService } from "renderer/services/bs-version-download/bs-do import { AutoUpdaterService } from "renderer/services/auto-updater.service"; import BeatWaitingImg from "../../../assets/images/apngs/beat-waiting.png"; import { logRenderError } from "renderer"; - +import { BSLauncherService } from "renderer/services/bs-launcher.service"; export function SettingsPage() { @@ -51,6 +51,7 @@ export function SettingsPage() { const ipcService = useService(IpcService); const modalService = useService(ModalService); const bsDownloader = useService(BsDownloaderService); + const bsLauncher = useService(BSLauncherService); const steamDownloader = useService(SteamDownloaderService); const progressBarService = useService(ProgressBarService); const notificationService = useService(NotificationService); @@ -85,6 +86,7 @@ export function SettingsPage() { const downloadStore = useObservable(() => bsDownloader.defaultStore$); const [installationFolder, setInstallationFolder] = useState(null); + const [protonPath, setProtonPath] = useState(bsLauncher.getProtonPath()); const [showSupporters, setShowSupporters] = useState(false); const [mapDeepLinksEnabled, setMapDeepLinksEnabled] = useState(false); const [playlistsDeepLinkEnabled, setPlaylistsDeepLinkEnabled] = useState(false); @@ -156,6 +158,20 @@ export function SettingsPage() { clearTimeout(timeoutId); }; + const setDefaultProtonPath = () => { + if (!progressBarService.require()) { + return; + } + + ipcService.sendV2<{ canceled: boolean; filePaths: string[] }>("choose-file").toPromise().then(res => { + if (!res.canceled && res.filePaths?.length) { + const protonPath = res.filePaths[0]; + setProtonPath(protonPath); + bsLauncher.setProtonPath(protonPath); + } + }); + }; + const setDefaultInstallationFolder = () => { if (!progressBarService.require()) { return; @@ -282,7 +298,16 @@ export function SettingsPage() { {installationFolder} - + + + + + +
+ + {protonPath} + +
diff --git a/src/renderer/preload.d.ts b/src/renderer/preload.d.ts index ab023814..29aace8b 100644 --- a/src/renderer/preload.d.ts +++ b/src/renderer/preload.d.ts @@ -1,6 +1,7 @@ declare global { interface Window { electron: { + platform: "win32"|"linux"|"darwin", ipcRenderer: { sendMessage(channel: string, args: any): void; on(channel: string, func: (...args: any) => void): (() => void) | undefined; diff --git a/src/renderer/services/bs-launcher.service.ts b/src/renderer/services/bs-launcher.service.ts index 8bc89ec8..1769c9de 100644 --- a/src/renderer/services/bs-launcher.service.ts +++ b/src/renderer/services/bs-launcher.service.ts @@ -23,6 +23,8 @@ export class BSLauncherService { public readonly versionRunning$: BehaviorSubject = new BehaviorSubject(null); + private readonly PROTON_PATH_KEY = "protonPath"; + public static getInstance(){ if(!BSLauncherService.instance){ BSLauncherService.instance = new BSLauncherService(); } return BSLauncherService.instance; @@ -36,6 +38,14 @@ export class BSLauncherService { this.modals = ModalService.getInstance(); } + public setProtonPath(protonPath: string|undefined): void { + this.config.set(this.PROTON_PATH_KEY, protonPath); + } + + public getProtonPath(): string|undefined { + return this.config.get(this.PROTON_PATH_KEY); + } + private notRewindBackupOculus(): boolean{ return this.config.get("not-rewind-backup-oculus"); }