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

fix: don't update settings from playback dolphin and check if update is necessary #386

Merged
merged 4 commits into from
Jul 31, 2023
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
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
Loading