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

feat: add toast when mirroring errors are emitted #224

Merged
merged 2 commits into from
Aug 30, 2021
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
5 changes: 5 additions & 0 deletions src/console/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ export const ipc_consoleMirrorStatusUpdatedEvent = makeEndpoint.renderer(
"console_consoleMirrorStatusUpdated",
<{ ip: string; info: Partial<ConsoleMirrorStatusUpdate> }>_,
);

export const ipc_consoleMirrorErrorMessageEvent = makeEndpoint.renderer(
"console_consoleMirrorErrorMessageEvent",
<{ message: string }>_,
);
2 changes: 1 addition & 1 deletion src/console/mirrorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class MirrorManager extends EventEmitter {

public async connect(config: MirrorConfig) {
if (this.mirrors[config.ipAddress]) {
this.emit(MirrorEvent.LOG, `Already connected to Wii @ ${config.ipAddress}`);
this.emit(MirrorEvent.ERROR, `Already connected to Wii @ ${config.ipAddress}`);
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/console/workerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { app } from "electron";
import electronLog from "electron-log";
import { spawn, Thread, Worker } from "threads";

import { ipc_consoleMirrorStatusUpdatedEvent } from "./ipc";
import { ipc_consoleMirrorErrorMessageEvent, ipc_consoleMirrorStatusUpdatedEvent } from "./ipc";
import { Methods as MirrorWorkerMethods, WorkerSpec as MirrorWorkerSpec } from "./mirrorWorker";

const log = electronLog.scope("console/workerInterface");
Expand All @@ -20,6 +20,8 @@ export const mirrorWorker: Promise<Thread & MirrorWorkerMethods> = new Promise((
});
worker.getErrorObservable().subscribe((errorMessage) => {
mirrorLog.error(errorMessage);
const message = errorMessage instanceof Error ? errorMessage.message : errorMessage;
ipc_consoleMirrorErrorMessageEvent.main!.trigger({ message }).catch(mirrorLog.error);
});
worker.getMirrorDetailsObservable().subscribe(({ playbackId, filePath, isRealtime }) => {
const replayComm: ReplayCommunication = {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/containers/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const Console: React.FC = () => {
// Close the dialog
onCancel();
};

return (
<Outer>
<div
Expand Down
16 changes: 15 additions & 1 deletion src/renderer/lib/hooks/useAppListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
ipc_dolphinStatusChangedEvent,
ipc_slippiStatusChangedEvent,
} from "@broadcast/ipc";
import { ipc_consoleMirrorStatusUpdatedEvent, ipc_discoveredConsolesUpdatedEvent } from "@console/ipc";
import {
ipc_consoleMirrorErrorMessageEvent,
ipc_consoleMirrorStatusUpdatedEvent,
ipc_discoveredConsolesUpdatedEvent,
} from "@console/ipc";
import { ipc_dolphinDownloadLogReceivedEvent } from "@dolphin/ipc";
import { ipc_loadProgressUpdatedEvent, ipc_statsPageRequestedEvent } from "@replays/ipc";
import { ipc_openSettingsModalEvent, ipc_settingsUpdatedEvent } from "@settings/ipc";
Expand All @@ -20,6 +24,7 @@ import log from "electron-log";
import firebase from "firebase";
import throttle from "lodash/throttle";
import React from "react";
import { useToasts } from "react-toast-notifications";

import { useAppInitialization, useAppStore } from "@/lib/hooks/useApp";
import { useConsole } from "@/lib/hooks/useConsole";
Expand Down Expand Up @@ -193,4 +198,13 @@ export const useAppListeners = () => {
React.useEffect(() => {
init(rootSlpPath, extraSlpPaths, true).catch(console.error);
}, [rootSlpPath, extraSlpPaths, init]);

const { addToast } = useToasts();
ipc_consoleMirrorErrorMessageEvent.renderer!.useEvent(async ({ message }) => {
addToast(message, {
id: message,
appearance: "error",
autoDismiss: true,
});
}, []);
};