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

refactor: remove desktop app migration + import dolphin settings #444

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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
9 changes: 0 additions & 9 deletions src/dolphin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import type { GeckoCode } from "./config/gecko_code";
import {
ipc_checkDesktopAppDolphin,
ipc_checkPlayKeyExists,
ipc_configureDolphin,
ipc_dolphinEvent,
ipc_downloadDolphin,
ipc_fetchGeckoCodes,
ipc_hardResetDolphin,
ipc_importDolphinSettings,
ipc_launchNetplayDolphin,
ipc_openDolphinSettingsFolder,
ipc_removePlayKeyFile,
Expand Down Expand Up @@ -59,13 +57,6 @@ const dolphinApi: DolphinService = {
async launchNetplayDolphin(options: { bootToCss?: boolean }): Promise<void> {
await ipc_launchNetplayDolphin.renderer!.trigger(options);
},
async checkDesktopAppDolphin() {
const { result } = await ipc_checkDesktopAppDolphin.renderer!.trigger({});
return result;
},
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
13 changes: 0 additions & 13 deletions src/dolphin/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ export const ipc_launchNetplayDolphin = makeEndpoint.main(
<SuccessPayload>_,
);

export const ipc_checkDesktopAppDolphin = makeEndpoint.main(
"getDesktopAppDolphinPath",
<EmptyPayload>_,
<{ dolphinPath: string; exists: boolean }>_,
);

// 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
45 changes: 2 additions & 43 deletions src/dolphin/setup.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { app, shell } from "electron";
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 {
ipc_checkDesktopAppDolphin,
ipc_checkPlayKeyExists,
ipc_configureDolphin,
ipc_dolphinEvent,
ipc_downloadDolphin,
ipc_fetchGeckoCodes,
ipc_hardResetDolphin,
ipc_importDolphinSettings,
ipc_launchNetplayDolphin,
ipc_openDolphinSettingsFolder,
ipc_removePlayKeyFile,
Expand All @@ -25,10 +22,7 @@ import {
import type { DolphinManager } from "./manager";
import { deletePlayKeyFile, writePlayKeyFile } from "./playkey";
import { DolphinLaunchType } from "./types";
import { fetchGeckoCodes, findDolphinExecutable, saveGeckoCodes, updateBootToCssCode } from "./util";

const isMac = process.platform === "darwin";
const isLinux = process.platform === "linux";
import { fetchGeckoCodes, saveGeckoCodes, updateBootToCssCode } from "./util";

export default function setupDolphinIpc({ dolphinManager }: { dolphinManager: DolphinManager }) {
dolphinManager.events.subscribe((event) => {
Expand Down Expand Up @@ -119,41 +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_checkDesktopAppDolphin.main!.handle(async () => {
// get the path and check existence
const desktopAppPath = path.join(app.getPath("appData"), "Slippi Desktop App");
let exists = await fs.pathExists(desktopAppPath);

if (!exists) {
return { dolphinPath: "", exists: false };
}

// Linux doesn't need to do anything because their dolphin settings are in a user config dir
if (isLinux && exists) {
await fs.remove(desktopAppPath);
return { dolphinPath: "", exists: false };
}

const dolphinFolderPath = path.join(desktopAppPath, "dolphin");
exists = await fs.pathExists(dolphinFolderPath);

const dolphinExecutablePath = await findDolphinExecutable(DolphinLaunchType.NETPLAY, dolphinFolderPath);

return { dolphinPath: dolphinExecutablePath, exists: exists };
});

ipc_fetchGeckoCodes.main!.handle(async ({ dolphinType }) => {
const installation = dolphinManager.getInstallation(dolphinType);
const codes = await fetchGeckoCodes(installation);
Expand Down
2 changes: 0 additions & 2 deletions src/dolphin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export interface DolphinService {
removePlayKeyFile(): Promise<void>;
viewSlpReplay(files: ReplayQueueItem[]): Promise<void>;
launchNetplayDolphin(options: { bootToCss?: boolean }): Promise<void>;
checkDesktopAppDolphin(): Promise<{ dolphinPath: string; exists: boolean }>;
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
4 changes: 0 additions & 4 deletions src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ipc_checkValidIso,
ipc_clearTempFolder,
ipc_copyLogsToClipboard,
ipc_deleteDesktopAppPath,
ipc_deleteFiles,
ipc_fetchNewsFeed,
ipc_getLatestGitHubReleaseVersion,
Expand Down Expand Up @@ -35,9 +34,6 @@ export default {
async deleteFiles(filePaths: string[]) {
await ipc_deleteFiles.renderer!.trigger({ filePaths });
},
async deleteDesktopAppPath() {
await ipc_deleteDesktopAppPath.renderer!.trigger({});
},
async copyLogsToClipboard(): Promise<void> {
await ipc_copyLogsToClipboard.renderer!.trigger({});
},
Expand Down
2 changes: 0 additions & 2 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const ipc_checkValidIso = makeEndpoint.main(
<{ path: string; valid: IsoValidity }>_,
);

export const ipc_deleteDesktopAppPath = makeEndpoint.main("deleteDesktopAppPath", <EmptyPayload>_, <SuccessPayload>_);

export const ipc_copyLogsToClipboard = makeEndpoint.main("copyLogsToClipboard", <EmptyPayload>_, <SuccessPayload>_);

export const ipc_checkForUpdate = makeEndpoint.main("checkForUpdate", <EmptyPayload>_, <SuccessPayload>_);
Expand Down
9 changes: 0 additions & 9 deletions src/main/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ipc_checkValidIso,
ipc_clearTempFolder,
ipc_copyLogsToClipboard,
ipc_deleteDesktopAppPath,
ipc_deleteFiles,
ipc_fetchNewsFeed,
ipc_getLatestGitHubReleaseVersion,
Expand Down Expand Up @@ -90,14 +89,6 @@ export default function setupMainIpc({
}
});

ipc_deleteDesktopAppPath.main!.handle(async () => {
// get the path and remove
const desktopAppPath = path.join(app.getPath("appData"), "Slippi Desktop App");
await fs.remove(desktopAppPath);

return { success: true };
});

ipc_copyLogsToClipboard.main!.handle(async () => {
let logsFolder = isMac ? app.getPath("logs") : path.resolve(app.getPath("userData"), "logs");
if (isDevelopment) {
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
14 changes: 0 additions & 14 deletions src/renderer/lib/hooks/use_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { useToasts } from "@/lib/hooks/use_toasts";
import { useServices } from "@/services";
import type { AuthUser } from "@/services/auth/types";

import { useDesktopApp } from "./use_quick_start";

export const useAppStore = create(
combine(
{
Expand Down Expand Up @@ -39,8 +37,6 @@ export const useAppInitialization = () => {
const setUserData = useAccount((store) => store.setUserData);
const setUser = useAccount((store) => store.setUser);
const setServerError = useAccount((store) => store.setServerError);
const setDesktopAppExists = useDesktopApp((store) => store.setExists);
const setDesktopAppDolphinPath = useDesktopApp((store) => store.setDolphinPath);

const initialize = async () => {
if (initializing || initialized) {
Expand Down Expand Up @@ -93,16 +89,6 @@ export const useAppInitialization = () => {
});
});

promises.push(
dolphinService
.checkDesktopAppDolphin()
.then(({ exists, dolphinPath }) => {
setDesktopAppExists(exists);
setDesktopAppDolphinPath(dolphinPath);
})
.catch(log.error),
);

// Check if there is an update to the launcher
promises.push(window.electron.common.checkForAppUpdates());

Expand Down
30 changes: 0 additions & 30 deletions src/renderer/lib/hooks/use_quick_start.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { currentRulesVersion } from "@common/constants";
import React from "react";
import { useNavigate } from "react-router-dom";
import { create } from "zustand";
import { combine } from "zustand/middleware";

import { useSettings } from "@/lib/hooks/use_settings";

Expand All @@ -12,7 +10,6 @@ export enum QuickStartStep {
LOGIN = "LOGIN",
VERIFY_EMAIL = "VERIFY_EMAIL",
ACCEPT_RULES = "ACCEPT_RULES",
MIGRATE_DOLPHIN = "MIGRATE_DOLPHIN",
ACTIVATE_ONLINE = "ACTIVATE_ONLINE",
SET_ISO_PATH = "SET_ISO_PATH",
COMPLETE = "COMPLETE",
Expand All @@ -26,7 +23,6 @@ function generateSteps(
showRules: boolean;
serverError: boolean;
hasIso: boolean;
hasOldDesktopApp: boolean;
}>,
): QuickStartStep[] {
// Build the steps in reverse order
Expand All @@ -36,10 +32,6 @@ function generateSteps(
steps.unshift(QuickStartStep.SET_ISO_PATH);
}

if (options.hasOldDesktopApp) {
steps.unshift(QuickStartStep.MIGRATE_DOLPHIN);
}

if (!options.hasPlayKey && !options.serverError) {
steps.unshift(QuickStartStep.ACTIVATE_ONLINE);
}
Expand All @@ -65,15 +57,13 @@ export const useQuickStart = () => {
const user = useAccount((store) => store.user);
const userData = useAccount((store) => store.userData);
const serverError = useAccount((store) => store.serverError);
const desktopAppPathExists = useDesktopApp((store) => store.exists);
const options = {
hasUser: Boolean(user),
hasIso: Boolean(savedIsoPath),
hasVerifiedEmail: Boolean(user?.emailVerified),
hasPlayKey: Boolean(userData?.playKey),
showRules: Boolean((userData?.rulesAccepted ?? 0) < currentRulesVersion),
serverError: Boolean(serverError),
hasOldDesktopApp: desktopAppPathExists,
};
const [steps] = React.useState(generateSteps(options));
const [currentStep, setCurrentStep] = React.useState<QuickStartStep | null>(null);
Expand All @@ -90,10 +80,6 @@ export const useQuickStart = () => {
stepToShow = QuickStartStep.SET_ISO_PATH;
}

if (options.hasOldDesktopApp) {
stepToShow = QuickStartStep.MIGRATE_DOLPHIN;
}

if (!options.hasPlayKey && !options.serverError) {
stepToShow = QuickStartStep.ACTIVATE_ONLINE;
}
Expand All @@ -115,7 +101,6 @@ export const useQuickStart = () => {
steps,
options.hasIso,
options.hasVerifiedEmail,
options.hasOldDesktopApp,
options.hasPlayKey,
options.hasUser,
options.showRules,
Expand Down Expand Up @@ -144,18 +129,3 @@ export const useQuickStart = () => {
prevStep,
};
};

export const oldDesktopApp = { path: "", exists: false };

export const useDesktopApp = create(
combine(
{
exists: false,
dolphinPath: "",
},
(set) => ({
setExists: (exists: boolean) => set({ exists }),
setDolphinPath: (dolphinPath: string) => set({ dolphinPath }),
}),
),
);
3 changes: 0 additions & 3 deletions src/renderer/pages/quick_start/quick_start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { platformTitleBarStyles } from "@/styles/platform_title_bar_styles";

import { AcceptRulesStep } from "./steps/accept_rules_step";
import { ActivateOnlineStep } from "./steps/activate_online_step";
import { ImportDolphinSettingsStep } from "./steps/import_dolphin_settings_step";
import { IsoSelectionStep } from "./steps/iso_selection_step";
import { LoginStep } from "./steps/login_step";
import { SetupCompleteStep } from "./steps/setup_complete_step";
Expand Down Expand Up @@ -43,8 +42,6 @@ const getStepContent = (step: QuickStartStep | null) => {
return <AcceptRulesStep />;
case QuickStartStep.ACTIVATE_ONLINE:
return <ActivateOnlineStep />;
case QuickStartStep.MIGRATE_DOLPHIN:
return <ImportDolphinSettingsStep />;
case QuickStartStep.SET_ISO_PATH:
return <IsoSelectionStep />;
case QuickStartStep.COMPLETE:
Expand Down
Loading
Loading