Skip to content

Commit

Permalink
fix: don't update settings from playback dolphin and check if update …
Browse files Browse the repository at this point in the history
…is necessary (#386)

* fix: normalize path name from dolphin

dolphin uses a forward slash on the default value, normalizing will replace that with a backslash

* fix: only update the launcher setting if needed

* don't update settings from playback dolphin

* minor refactor
  • Loading branch information
NikhilNarayana authored Jul 31, 2023
1 parent c68feba commit 3c3ea4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/dolphin/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export async function setSlippiSettings(iniFile: IniFile, options: Partial<Synce

export async function getSlippiSettings(iniFile: IniFile): Promise<SyncedDolphinSettings> {
const coreSection = iniFile.getOrCreateSection("Core");

const useMonthlySubfolders = coreSection.get("SlippiReplayMonthFolders", "False") === "True";
const replayPath = coreSection.get("SlippiReplayDir", defaultAppSettings.settings.rootSlpPath);

const enableJukebox = coreSection.get("SlippiJukeboxEnabled", "True") === "True";

return { useMonthlySubfolders, replayPath, enableJukebox };
Expand Down
30 changes: 25 additions & 5 deletions src/dolphin/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class DolphinManager {
if (!playbackInstance) {
playbackInstance = new PlaybackDolphinInstance(dolphinPath, meleeIsoPath);
playbackInstance.on("close", async (exitCode) => {
await this._updateLauncherSettings(DolphinLaunchType.PLAYBACK);
this.eventSubject.next({
type: DolphinEventType.CLOSED,
instanceId: id,
Expand Down Expand Up @@ -123,7 +122,9 @@ export class DolphinManager {
const instance = new DolphinInstance(dolphinPath);
this.netplayDolphinInstance = instance;
instance.on("close", async (exitCode) => {
await this._updateLauncherSettings(launchType);
if (launchType === DolphinLaunchType.NETPLAY) {
await this._updateLauncherSettings(launchType);
}
this.eventSubject.next({
type: DolphinEventType.CLOSED,
dolphinType: DolphinLaunchType.NETPLAY,
Expand Down Expand Up @@ -217,9 +218,28 @@ export class DolphinManager {
const installation = this.getInstallation(launchType);
const newSettings = await installation.getSettings();

await this.settingsManager.setRootSlpPath(newSettings.replayPath);
await this.settingsManager.setUseMonthlySubfolders(newSettings.useMonthlySubfolders);
await this.settingsManager.setEnableJukebox(newSettings.enableJukebox);
await this._updateLauncherSetting(
this.settingsManager.getRootSlpPath(),
path.normalize(newSettings.replayPath),
this.settingsManager.setRootSlpPath,
);
await this._updateLauncherSetting(
this.settingsManager.getUseMonthlySubfolders(),
newSettings.useMonthlySubfolders,
this.settingsManager.setUseMonthlySubfolders,
);
await this._updateLauncherSetting(
this.settingsManager.get().settings.enableJukebox,
newSettings.enableJukebox,
this.settingsManager.setEnableJukebox,
);
}

private async _updateLauncherSetting<T>(currentVal: T, newVal: T, update: (val: T) => Promise<void>) {
if (currentVal === newVal) {
return;
}
await update(newVal);
}

private _onStart(dolphinType: DolphinLaunchType) {
Expand Down

0 comments on commit 3c3ea4e

Please sign in to comment.