Skip to content

Commit

Permalink
refactor: remove import dolphin settings
Browse files Browse the repository at this point in the history
not really as useful as i expected and more likely to cause issues
  • Loading branch information
NikhilNarayana committed Sep 16, 2024
1 parent 55f88a7 commit f3c3847
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 101 deletions.
4 changes: 0 additions & 4 deletions src/dolphin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ipc_downloadDolphin,
ipc_fetchGeckoCodes,
ipc_hardResetDolphin,
ipc_importDolphinSettings,
ipc_launchNetplayDolphin,
ipc_openDolphinSettingsFolder,
ipc_removePlayKeyFile,
Expand Down Expand Up @@ -58,9 +57,6 @@ const dolphinApi: DolphinService = {
async launchNetplayDolphin(options: { bootToCss?: boolean }): Promise<void> {
await ipc_launchNetplayDolphin.renderer!.trigger(options);
},
async importDolphinSettings(options: { toImportDolphinPath: string; dolphinType: DolphinLaunchType }): Promise<void> {
await ipc_importDolphinSettings.renderer!.trigger(options);
},
async fetchGeckoCodes(dolphinType: DolphinLaunchType): Promise<GeckoCode[]> {
const { result } = await ipc_fetchGeckoCodes.renderer!.trigger({ dolphinType });
return result.codes;
Expand Down
7 changes: 0 additions & 7 deletions src/dolphin/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ export const ipc_launchNetplayDolphin = makeEndpoint.main(
<SuccessPayload>_,
);

// toImportDolphin path must point to a "Slippi Dolphin.{exe,app}"
export const ipc_importDolphinSettings = makeEndpoint.main(
"importDolphinSettings",
<{ toImportDolphinPath: string; dolphinType: DolphinLaunchType }>_,
<SuccessPayload>_,
);

export const ipc_fetchGeckoCodes = makeEndpoint.main(
"fetchGeckoCodes",
<{ dolphinType: DolphinLaunchType }>_,
Expand Down
16 changes: 0 additions & 16 deletions src/dolphin/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { shell } from "electron";
import log from "electron-log";
import * as fs from "fs-extra";
import isEqual from "lodash/isEqual";
import path from "path";
import { fileExists } from "utils/file_exists";

import {
Expand All @@ -12,7 +11,6 @@ import {
ipc_downloadDolphin,
ipc_fetchGeckoCodes,
ipc_hardResetDolphin,
ipc_importDolphinSettings,
ipc_launchNetplayDolphin,
ipc_openDolphinSettingsFolder,
ipc_removePlayKeyFile,
Expand All @@ -26,8 +24,6 @@ import { deletePlayKeyFile, writePlayKeyFile } from "./playkey";
import { DolphinLaunchType } from "./types";
import { fetchGeckoCodes, saveGeckoCodes, updateBootToCssCode } from "./util";

const isMac = process.platform === "darwin";

export default function setupDolphinIpc({ dolphinManager }: { dolphinManager: DolphinManager }) {
dolphinManager.events.subscribe((event) => {
void ipc_dolphinEvent.main!.trigger(event).catch(log.error);
Expand Down Expand Up @@ -117,18 +113,6 @@ export default function setupDolphinIpc({ dolphinManager }: { dolphinManager: Do
return { success: true };
});

ipc_importDolphinSettings.main!.handle(async ({ toImportDolphinPath, dolphinType }) => {
let dolphinPath = toImportDolphinPath;
if (isMac) {
dolphinPath = path.join(dolphinPath, "Contents", "Resources");
} else {
dolphinPath = path.dirname(dolphinPath);
}

await dolphinManager.importConfig(dolphinType, dolphinPath);
return { success: true };
});

ipc_fetchGeckoCodes.main!.handle(async ({ dolphinType }) => {
const installation = dolphinManager.getInstallation(dolphinType);
const codes = await fetchGeckoCodes(installation);
Expand Down
1 change: 0 additions & 1 deletion src/dolphin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export interface DolphinService {
removePlayKeyFile(): Promise<void>;
viewSlpReplay(files: ReplayQueueItem[]): Promise<void>;
launchNetplayDolphin(options: { bootToCss?: boolean }): Promise<void>;
importDolphinSettings(options: { toImportDolphinPath: string; dolphinType: DolphinLaunchType }): Promise<void>;
fetchGeckoCodes(dolphinLaunchType: DolphinLaunchType): Promise<GeckoCode[]>;
saveGeckoCodes(dolphinLaunchType: DolphinLaunchType, geckoCodes: GeckoCode[]): Promise<void>;
onEvent<T extends DolphinEventType>(eventType: T, handle: (event: DolphinEventMap[T]) => void): () => void;
Expand Down
15 changes: 1 addition & 14 deletions src/renderer/lib/dolphin/use_dolphin_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useToasts } from "@/lib/hooks/use_toasts";
import { DolphinStatus, setDolphinOpened, useDolphinStore } from "./use_dolphin_store";

export const useDolphinActions = (dolphinService: DolphinService) => {
const { showError, showSuccess } = useToasts();
const { showError } = useToasts();
const netplayStatus = useDolphinStore((store) => store.netplayStatus);
const playbackStatus = useDolphinStore((store) => store.playbackStatus);

Expand Down Expand Up @@ -114,18 +114,6 @@ export const useDolphinActions = (dolphinService: DolphinService) => {
[getInstallStatus, dolphinService, showError],
);

const importDolphin = useCallback(
(toImportDolphinPath: string, dolphinType: DolphinLaunchType) => {
dolphinService
.importDolphinSettings({ toImportDolphinPath, dolphinType })
.then(() => {
showSuccess(`${dolphinType} Dolphin settings successfully imported`);
})
.catch(showError);
},
[dolphinService, showError, showSuccess],
);

const readGeckoCodes = useCallback(
async (dolphinType: DolphinLaunchType) => {
if (getInstallStatus(dolphinType) !== DolphinStatus.READY) {
Expand Down Expand Up @@ -155,7 +143,6 @@ export const useDolphinActions = (dolphinService: DolphinService) => {
hardResetDolphin,
launchNetplay,
viewReplays,
importDolphin,
updateDolphin,
readGeckoCodes,
saveGeckoCodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import FormControlLabel from "@mui/material/FormControlLabel";
import Radio from "@mui/material/Radio";
import RadioGroup from "@mui/material/RadioGroup";
import Typography from "@mui/material/Typography";
import log from "electron-log";
import capitalize from "lodash/capitalize";
import React from "react";

Expand All @@ -20,8 +19,6 @@ import { useServices } from "@/services";
import { SettingItem } from "../setting_item_section";
import { GeckoCodes } from "./gecko_codes/gecko_codes";

const { isMac, isWindows } = window.electron.bootstrap;

enum ResetType {
SOFT,
HARD,
Expand All @@ -41,7 +38,7 @@ export const DolphinSettings = ({ dolphinType }: { dolphinType: DolphinLaunchTyp
const [resetModalOpen, setResetModalOpen] = React.useState(false);
const [isResetType, setResetType] = React.useState<ResetType | null>(null);
const { dolphinService } = useServices();
const { openConfigureDolphin, hardResetDolphin, softResetDolphin, importDolphin } = useDolphinActions(dolphinService);
const { openConfigureDolphin, hardResetDolphin, softResetDolphin } = useDolphinActions(dolphinService);
const { showWarning } = useToasts();
const dolphinIsReady = dolphinStatus === DolphinStatus.READY && !dolphinIsOpen && isResetType === null;
const versionString: string =
Expand Down Expand Up @@ -78,11 +75,6 @@ export const DolphinSettings = ({ dolphinType }: { dolphinType: DolphinLaunchTyp
setResetType(null);
};

const importDolphinHandler = (importPath: string) => {
log.info(`importing dolphin from ${importPath}`);
importDolphin(importPath, dolphinType);
};

const dolphinTypeName = capitalize(dolphinType);
return (
<div>
Expand Down Expand Up @@ -181,48 +173,6 @@ export const DolphinSettings = ({ dolphinType }: { dolphinType: DolphinLaunchTyp
</RadioGroup>
</SettingItem>
)}
{isWindows && (
<ImportDolphinConfigForm
dolphinType={dolphinType}
disabled={!dolphinIsReady}
onImportDolphin={importDolphinHandler}
/>
)}
</div>
);
};

const ImportDolphinConfigForm = ({
dolphinType,
disabled,
onImportDolphin,
}: {
dolphinType: DolphinLaunchType;
disabled?: boolean;
onImportDolphin: (importPath: string) => void;
}) => {
const dolphinTypeName = capitalize(dolphinType);
const extension = isMac ? "app" : "exe";

const onImportClick = async () => {
const result = await window.electron.common.showOpenDialog({
filters: [{ name: "Slippi Dolphin", extensions: [isMac ? "app" : "exe"] }],
});
const res = result.filePaths;
if (result.canceled || res.length === 0) {
return;
}
onImportDolphin(res[0]);
};

return (
<SettingItem
name={`Import ${dolphinTypeName} Dolphin Settings`}
description={`Replace the ${dolphinTypeName} Dolphin settings with those from a different Dolphin application. To do this, select the Dolphin.${extension} with the desired ${dolphinType} settings.`}
>
<Button variant="contained" color="secondary" onClick={onImportClick} disabled={disabled}>
Import Dolphin settings
</Button>
</SettingItem>
);
};
8 changes: 0 additions & 8 deletions src/renderer/services/dolphin/dolphin.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ class MockDolphinClient implements DolphinService {
throw new Error("Method not implemented.");
}

@delayAndMaybeError(SHOULD_ERROR)
public async importDolphinSettings(_options: {
toImportDolphinPath: string;
dolphinType: DolphinLaunchType;
}): Promise<void> {
throw new Error("Method not implemented.");
}

@delayAndMaybeError(SHOULD_ERROR)
public async openDolphinSettingsFolder(_dolphinType: DolphinLaunchType): Promise<void> {
throw new Error("Method not implemented.");
Expand Down

0 comments on commit f3c3847

Please sign in to comment.