From a62cc60fad3b918d82ed7c4882704b4a246e2bce Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Sat, 26 Jun 2021 02:02:09 -0700 Subject: [PATCH 1/5] feat: ability to set play button functionality --- src/dolphin/manager.ts | 3 +- .../containers/Settings/DolphinSettings.tsx | 32 ++++++++++++++++++- src/renderer/lib/hooks/useSettings.ts | 13 ++++++++ src/settings/defaultSettings.ts | 1 + src/settings/ipc.ts | 6 ++++ src/settings/main.ts | 6 ++++ src/settings/settingsManager.ts | 4 +++ src/settings/types.ts | 1 + 8 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/dolphin/manager.ts b/src/dolphin/manager.ts index db166316d..fc5dbc98c 100644 --- a/src/dolphin/manager.ts +++ b/src/dolphin/manager.ts @@ -46,7 +46,8 @@ export class DolphinManager extends EventEmitter { const dolphinPath = await findDolphinExecutable(DolphinLaunchType.NETPLAY); log.info(`Launching dolphin at path: ${dolphinPath}`); - const meleeIsoPath = await this._getIsoPath(); + const launchMeleeOnPlay = settingsManager.get().settings.launchMeleeOnPlay; + const meleeIsoPath = launchMeleeOnPlay ? await this._getIsoPath() : undefined; // Create the Dolphin instance and start it this.netplayDolphinInstance = new DolphinInstance(dolphinPath, meleeIsoPath); diff --git a/src/renderer/containers/Settings/DolphinSettings.tsx b/src/renderer/containers/Settings/DolphinSettings.tsx index 2b2d0370c..901fd0a51 100644 --- a/src/renderer/containers/Settings/DolphinSettings.tsx +++ b/src/renderer/containers/Settings/DolphinSettings.tsx @@ -3,6 +3,9 @@ import { clearDolphinCache, configureDolphin, reinstallDolphin } from "@dolphin/ import { DolphinLaunchType } from "@dolphin/types"; import { css, jsx } from "@emotion/react"; import Button from "@material-ui/core/Button"; +import FormControlLabel from "@material-ui/core/FormControlLabel"; +import Radio from "@material-ui/core/Radio"; +import RadioGroup from "@material-ui/core/RadioGroup"; import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"; import Typography from "@material-ui/core/Typography"; import { isLinux } from "common/constants"; @@ -13,7 +16,7 @@ import { useToasts } from "react-toast-notifications"; import { ConfirmationModal } from "@/components/ConfirmationModal"; import { DevGuard } from "@/components/DevGuard"; import { PathInput } from "@/components/PathInput"; -import { useDolphinPath } from "@/lib/hooks/useSettings"; +import { useDolphinPath, useLaunchMeleeOnPlay } from "@/lib/hooks/useSettings"; import { SettingItem } from "./SettingItem"; @@ -42,12 +45,20 @@ const useStyles = makeStyles((theme: Theme) => export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({ dolphinType }) => { const [dolphinPath, setDolphinPath] = useDolphinPath(dolphinType); + const [launchMeleeOnPlay, setLaunchMelee] = useLaunchMeleeOnPlay(); const [modalOpen, setModalOpen] = React.useState(false); const classes = useStyles(); const { addToast } = useToasts(); + + const onLaunchMeleeChange = async (event: any) => { + const value = event.target.value === "true" ? true : false; + await setLaunchMelee(value); + }; + const openDolphinDirectoryHandler = async () => { shell.openItem(dolphinPath); }; + const configureDolphinHandler = async () => { console.log("configure dolphin pressed"); if (process.platform === "darwin") { @@ -58,13 +69,16 @@ export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({ } await configureDolphin.renderer!.trigger({ dolphinType }); }; + const reinstallDolphinHandler = async () => { console.log("reinstall button clicked"); await reinstallDolphin.renderer!.trigger({ dolphinType }); }; + const clearDolphinCacheHandler = async () => { await clearDolphinCache.renderer!.trigger({ dolphinType }); }; + return (
@@ -80,6 +94,22 @@ export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({ /> + {dolphinType === DolphinLaunchType.NETPLAY && ( + + onLaunchMeleeChange(event)}> + } + /> + } + /> + + + )}
{ } } }; + +export const useLaunchMeleeOnPlay = () => { + const launchMeleeOnPlay = useSettings((store) => store.settings.launchMeleeOnPlay); + const setLaunchMelee = async (launchMelee: boolean) => { + const setResult = await setLaunchMeleeOnPlay.renderer!.trigger({ launchMelee }); + if (!setResult.result) { + throw new Error("Error setting launch melee on Play"); + } + }; + + return [launchMeleeOnPlay, setLaunchMelee] as const; +}; diff --git a/src/settings/defaultSettings.ts b/src/settings/defaultSettings.ts index 7af1a6b2f..6ab6846e5 100644 --- a/src/settings/defaultSettings.ts +++ b/src/settings/defaultSettings.ts @@ -19,5 +19,6 @@ export const defaultAppSettings: AppSettings = { spectateSlpPath: path.join(getDefaultRootSlpPath(), "Spectate"), netplayDolphinPath: path.join(app.getPath("userData"), "netplay"), playbackDolphinPath: path.join(app.getPath("userData"), "playback"), + launchMeleeOnPlay: true, }, }; diff --git a/src/settings/ipc.ts b/src/settings/ipc.ts index 470486031..511b1e92b 100644 --- a/src/settings/ipc.ts +++ b/src/settings/ipc.ts @@ -19,6 +19,12 @@ export const setPlaybackDolphinPath = makeEndpoint.main( _, ); +export const setLaunchMeleeOnPlay = makeEndpoint.main( + "setLaunchMeleeOnPlay", + <{ launchMelee: boolean }>_, + _, +); + export const addNewConnection = makeEndpoint.main( "addNewConnection", <{ connection: Omit }>_, diff --git a/src/settings/main.ts b/src/settings/main.ts index e78ffaf2f..b1473d720 100644 --- a/src/settings/main.ts +++ b/src/settings/main.ts @@ -6,6 +6,7 @@ import { deleteConnection, editConnection, setIsoPath, + setLaunchMeleeOnPlay, setNetplayDolphinPath, setPlaybackDolphinPath, setRootSlpPath, @@ -61,3 +62,8 @@ deleteConnection.main!.handle(async ({ id }) => { await settingsManager.deleteConsoleConnection(id); return { success: true }; }); + +setLaunchMeleeOnPlay.main!.handle(async ({ launchMelee }) => { + await settingsManager.setLaunchMeleeOnPlay(launchMelee); + return { success: true }; +}); diff --git a/src/settings/settingsManager.ts b/src/settings/settingsManager.ts index 7baa354b8..68632d921 100644 --- a/src/settings/settingsManager.ts +++ b/src/settings/settingsManager.ts @@ -65,6 +65,10 @@ export class SettingsManager { await this._set("settings.playbackDolphinPath", dolphinPath); } + public async setLaunchMeleeOnPlay(launchMelee: boolean): Promise { + await this._set("settings.launchMeleeOnPlay", launchMelee); + } + public async addConsoleConnection(conn: Omit): Promise { const connections = this.get().connections; // Auto-generate an ID diff --git a/src/settings/types.ts b/src/settings/types.ts index 5cd7ff86d..6d343f3e9 100644 --- a/src/settings/types.ts +++ b/src/settings/types.ts @@ -20,5 +20,6 @@ export type AppSettings = { spectateSlpPath: string; netplayDolphinPath: string; playbackDolphinPath: string; + launchMeleeOnPlay: boolean; }; }; From e0d2c18fb808b68929eb58af84e403b77559ddaf Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Sat, 26 Jun 2021 11:03:52 -0700 Subject: [PATCH 2/5] refactor: move launchMelee setting to MeleeOptions and fix some logic/typing --- src/dolphin/util.ts | 6 ++--- .../containers/Settings/DolphinSettings.tsx | 27 +------------------ .../containers/Settings/MeleeOptions.tsx | 25 ++++++++++++++++- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/dolphin/util.ts b/src/dolphin/util.ts index d4ba87ad5..1a112860e 100644 --- a/src/dolphin/util.ts +++ b/src/dolphin/util.ts @@ -8,11 +8,9 @@ import path from "path"; import { DolphinLaunchType } from "./types"; -export async function findDolphinExecutable(type: DolphinLaunchType, dolphinPath?: string): Promise { +export async function findDolphinExecutable(type: DolphinLaunchType): Promise { // Make sure the directory actually exists - if (!dolphinPath) { - dolphinPath = settingsManager.getDolphinPath(type); - } + const dolphinPath = settingsManager.getDolphinPath(type); await fs.ensureDir(dolphinPath); diff --git a/src/renderer/containers/Settings/DolphinSettings.tsx b/src/renderer/containers/Settings/DolphinSettings.tsx index 901fd0a51..46a106ab5 100644 --- a/src/renderer/containers/Settings/DolphinSettings.tsx +++ b/src/renderer/containers/Settings/DolphinSettings.tsx @@ -3,9 +3,6 @@ import { clearDolphinCache, configureDolphin, reinstallDolphin } from "@dolphin/ import { DolphinLaunchType } from "@dolphin/types"; import { css, jsx } from "@emotion/react"; import Button from "@material-ui/core/Button"; -import FormControlLabel from "@material-ui/core/FormControlLabel"; -import Radio from "@material-ui/core/Radio"; -import RadioGroup from "@material-ui/core/RadioGroup"; import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"; import Typography from "@material-ui/core/Typography"; import { isLinux } from "common/constants"; @@ -16,7 +13,7 @@ import { useToasts } from "react-toast-notifications"; import { ConfirmationModal } from "@/components/ConfirmationModal"; import { DevGuard } from "@/components/DevGuard"; import { PathInput } from "@/components/PathInput"; -import { useDolphinPath, useLaunchMeleeOnPlay } from "@/lib/hooks/useSettings"; +import { useDolphinPath } from "@/lib/hooks/useSettings"; import { SettingItem } from "./SettingItem"; @@ -45,16 +42,10 @@ const useStyles = makeStyles((theme: Theme) => export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({ dolphinType }) => { const [dolphinPath, setDolphinPath] = useDolphinPath(dolphinType); - const [launchMeleeOnPlay, setLaunchMelee] = useLaunchMeleeOnPlay(); const [modalOpen, setModalOpen] = React.useState(false); const classes = useStyles(); const { addToast } = useToasts(); - const onLaunchMeleeChange = async (event: any) => { - const value = event.target.value === "true" ? true : false; - await setLaunchMelee(value); - }; - const openDolphinDirectoryHandler = async () => { shell.openItem(dolphinPath); }; @@ -94,22 +85,6 @@ export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({ /> - {dolphinType === DolphinLaunchType.NETPLAY && ( - - onLaunchMeleeChange(event)}> - } - /> - } - /> - - - )}
{ const verifying = useIsoVerification((state) => state.isValidating); const isValidIso = useIsoVerification((state) => state.isValid); const [isoPath, setIsoPath] = useIsoPath(); + const [launchMeleeOnPlay, setLaunchMelee] = useLaunchMeleeOnPlay(); const [replayDir, setReplayDir] = useRootSlpPath(); const [spectateDir, setSpectateDir] = useSpectateSlpPath(); const classes = useStyles(); + const onLaunchMeleeChange = async (value: string) => { + const launchMelee = value === "true"; + await setLaunchMelee(launchMelee); + }; + return (
@@ -62,6 +71,20 @@ export const MeleeOptions: React.FC = () => { } /> + + onLaunchMeleeChange(value)}> + } + /> + } + /> + + Date: Sat, 26 Jun 2021 11:05:47 -0700 Subject: [PATCH 3/5] feat: succinct labels for LaunchMelee radio buttons --- src/renderer/containers/Settings/MeleeOptions.tsx | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/renderer/containers/Settings/MeleeOptions.tsx b/src/renderer/containers/Settings/MeleeOptions.tsx index ca2205282..a94c4ba7a 100644 --- a/src/renderer/containers/Settings/MeleeOptions.tsx +++ b/src/renderer/containers/Settings/MeleeOptions.tsx @@ -73,16 +73,8 @@ export const MeleeOptions: React.FC = () => { onLaunchMeleeChange(value)}> - } - /> - } - /> + } /> + } /> From 121ef42c3859de4545057f23cea57c267e38e11d Mon Sep 17 00:00:00 2001 From: Vince Au Date: Sun, 27 Jun 2021 09:46:41 +1000 Subject: [PATCH 4/5] feat: add description for play button setting --- src/renderer/containers/Settings/MeleeOptions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/containers/Settings/MeleeOptions.tsx b/src/renderer/containers/Settings/MeleeOptions.tsx index a94c4ba7a..d1f2f644e 100644 --- a/src/renderer/containers/Settings/MeleeOptions.tsx +++ b/src/renderer/containers/Settings/MeleeOptions.tsx @@ -71,7 +71,7 @@ export const MeleeOptions: React.FC = () => { } /> - + onLaunchMeleeChange(value)}> } /> } /> From d43a84a18ba2b033ef57bdc2fbe77d39933ea4c0 Mon Sep 17 00:00:00 2001 From: Vince Au Date: Sun, 27 Jun 2021 09:47:03 +1000 Subject: [PATCH 5/5] feat: use primary color for radios --- src/renderer/styles/theme.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/renderer/styles/theme.ts b/src/renderer/styles/theme.ts index 7dc572ff1..52c9191ff 100644 --- a/src/renderer/styles/theme.ts +++ b/src/renderer/styles/theme.ts @@ -64,6 +64,9 @@ const addOverrides = (theme: Theme) => { fullWidth: true, size: "small", }, + MuiRadio: { + color: "primary", + }, }, overrides: { MuiPaper: {