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

feat: ability to set play button functionality #188

Merged
merged 5 commits into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/dolphin/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 31 additions & 1 deletion src/renderer/containers/Settings/DolphinSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -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") {
Expand All @@ -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 (
<div>
<Typography variant="h5" className={classes.title}>
Expand All @@ -80,6 +94,22 @@ export const DolphinSettings: React.FC<{ dolphinType: DolphinLaunchType }> = ({
/>
</SettingItem>
</DevGuard>
{dolphinType === DolphinLaunchType.NETPLAY && (
<SettingItem name="Play Button Functionality">
<RadioGroup value={launchMeleeOnPlay} onChange={(event) => onLaunchMeleeChange(event)}>
<FormControlLabel
value={true}
label="Launch Melee when clicking play on the home screen"
control={<Radio />}
/>
<FormControlLabel
value={false}
label="Launch Dolphin when clicking play on the home screen"
control={<Radio />}
/>
</RadioGroup>
</SettingItem>
)}
<SettingItem name={`Configure ${dolphinType} Dolphin`}>
<div
css={css`
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/lib/hooks/useSettings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DolphinLaunchType } from "@dolphin/types";
import {
setIsoPath,
setLaunchMeleeOnPlay,
setNetplayDolphinPath,
setPlaybackDolphinPath,
setRootSlpPath,
Expand Down Expand Up @@ -84,3 +85,15 @@ export const useDolphinPath = (dolphinType: DolphinLaunchType) => {
}
}
};

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;
};
1 change: 1 addition & 0 deletions src/settings/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
6 changes: 6 additions & 0 deletions src/settings/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export const setPlaybackDolphinPath = makeEndpoint.main(
<SuccessPayload>_,
);

export const setLaunchMeleeOnPlay = makeEndpoint.main(
"setLaunchMeleeOnPlay",
<{ launchMelee: boolean }>_,
<SuccessPayload>_,
);

export const addNewConnection = makeEndpoint.main(
"addNewConnection",
<{ connection: Omit<StoredConnection, "id"> }>_,
Expand Down
6 changes: 6 additions & 0 deletions src/settings/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
deleteConnection,
editConnection,
setIsoPath,
setLaunchMeleeOnPlay,
setNetplayDolphinPath,
setPlaybackDolphinPath,
setRootSlpPath,
Expand Down Expand Up @@ -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 };
});
4 changes: 4 additions & 0 deletions src/settings/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class SettingsManager {
await this._set("settings.playbackDolphinPath", dolphinPath);
}

public async setLaunchMeleeOnPlay(launchMelee: boolean): Promise<void> {
await this._set("settings.launchMeleeOnPlay", launchMelee);
}

public async addConsoleConnection(conn: Omit<StoredConnection, "id">): Promise<void> {
const connections = this.get().connections;
// Auto-generate an ID
Expand Down
1 change: 1 addition & 0 deletions src/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export type AppSettings = {
spectateSlpPath: string;
netplayDolphinPath: string;
playbackDolphinPath: string;
launchMeleeOnPlay: boolean;
};
};