Skip to content

Commit

Permalink
fix: handle offline dolphin a bit better
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilNarayana committed Mar 15, 2024
1 parent a1bc231 commit fccf6f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dolphin/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class DolphinManager {
await this._updateDolphinFlags(dolphinDownloadInfo, dolphinType);
} catch (err) {
log.error(`Failed to fetch latest Dolphin version: ${err}`);
this._onOffline(dolphinType);
return;
}

Expand Down Expand Up @@ -229,6 +230,7 @@ export class DolphinManager {
await this._updateDolphinFlags(dolphinDownloadInfo, launchType);
} catch (err) {
log.error(`Failed to fetch latest Dolphin version: ${err}`);
this._onOffline(launchType);
return;
}
const installation = this.getInstallation(launchType);
Expand Down Expand Up @@ -326,6 +328,13 @@ export class DolphinManager {
});
}

private _onOffline(dolphinType: DolphinLaunchType) {
this.eventSubject.next({
type: DolphinEventType.OFFLINE,
dolphinType,
});
}

// Run after fetchLatestVersion to update the necessary flags
private async _updateDolphinFlags(downloadInfo: DolphinVersionResponse, dolphinType: DolphinLaunchType) {
const isBeta = (downloadInfo.version as string).includes("-beta");
Expand Down
7 changes: 7 additions & 0 deletions src/dolphin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum DolphinEventType {
DOWNLOAD_START = "DOWNLOAD_START",
DOWNLOAD_PROGRESS = "DOWNLOAD_PROGRESS",
DOWNLOAD_COMPLETE = "DOWNLOAD_COMPLETE",
OFFLINE = "OFFLINE",
}

export type DolphinNetplayClosedEvent = {
Expand Down Expand Up @@ -84,11 +85,17 @@ export type DolphinDownloadCompleteEvent = {
dolphinVersion: string | null;
};

export type DolphinOfflineEvent = {
type: DolphinEventType.OFFLINE;
dolphinType: DolphinLaunchType;
};

export type DolphinEventMap = {
[DolphinEventType.CLOSED]: DolphinNetplayClosedEvent | DolphinPlaybackClosedEvent;
[DolphinEventType.DOWNLOAD_START]: DolphinDownloadStartEvent;
[DolphinEventType.DOWNLOAD_PROGRESS]: DolphinDownloadProgressEvent;
[DolphinEventType.DOWNLOAD_COMPLETE]: DolphinDownloadCompleteEvent;
[DolphinEventType.OFFLINE]: DolphinOfflineEvent;
};

export type DolphinEvent = DolphinEventMap[DolphinEventType];
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/lib/dolphin/use_dolphin_listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DolphinDownloadProgressEvent,
DolphinDownloadStartEvent,
DolphinNetplayClosedEvent,
DolphinOfflineEvent,
DolphinPlaybackClosedEvent,
DolphinService,
} from "@dolphin/types";
Expand Down Expand Up @@ -47,6 +48,11 @@ export const useDolphinListeners = (dolphinService: DolphinService) => {
setDolphinVersion(event.dolphinVersion, event.dolphinType);
}, []);

const dolphinOfflineHandler = useCallback((event: DolphinOfflineEvent) => {
showError("You seem to be offline, some functionality of the Launcher and Dolphin will be impacted.");
setDolphinStatus(event.dolphinType, DolphinStatus.READY);
}, []);

Check warning on line 54 in src/renderer/lib/dolphin/use_dolphin_listeners.ts

View workflow job for this annotation

GitHub Actions / Test on node 18.x and ubuntu-latest

React Hook useCallback has a missing dependency: 'showError'. Either include it or remove the dependency array

const dolphinDownloadStartHandler = useCallback((event: DolphinDownloadStartEvent) => {
setDolphinStatus(event.dolphinType, DolphinStatus.DOWNLOADING);
}, []);
Expand All @@ -57,6 +63,7 @@ export const useDolphinListeners = (dolphinService: DolphinService) => {
subs.push(dolphinService.onEvent(DolphinEventType.DOWNLOAD_START, dolphinDownloadStartHandler));
subs.push(dolphinService.onEvent(DolphinEventType.DOWNLOAD_PROGRESS, dolphinProgressHandler));
subs.push(dolphinService.onEvent(DolphinEventType.DOWNLOAD_COMPLETE, dolphinCompleteHandler));
subs.push(dolphinService.onEvent(DolphinEventType.OFFLINE, dolphinOfflineHandler));

return () => {
subs.forEach((unsub) => unsub());
Expand All @@ -67,5 +74,6 @@ export const useDolphinListeners = (dolphinService: DolphinService) => {
dolphinProgressHandler,
dolphinCompleteHandler,
dolphinDownloadStartHandler,
dolphinOfflineHandler,
]);
};

0 comments on commit fccf6f4

Please sign in to comment.