mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 14:37:06 +01:00
Add listeners and preload for log/toast from main
This commit is contained in:
parent
69f82a9427
commit
b69290f9f2
@ -109,6 +109,19 @@ export const getMainWindow = () => {
|
||||
return mainWindow;
|
||||
};
|
||||
|
||||
export const sendToastToRenderer = ({
|
||||
message,
|
||||
type,
|
||||
}: {
|
||||
message: string;
|
||||
type: 'success' | 'error' | 'warning' | 'info';
|
||||
}) => {
|
||||
getMainWindow()?.webContents.send('toast-from-main', {
|
||||
message,
|
||||
type,
|
||||
});
|
||||
};
|
||||
|
||||
const createWinThumbarButtons = () => {
|
||||
if (isWindows()) {
|
||||
getMainWindow()?.setThumbarButtons([
|
||||
|
@ -18,12 +18,40 @@ const onRestoreQueue = (cb: (event: IpcRendererEvent, data: Partial<PlayerState>
|
||||
ipcRenderer.on('renderer-restore-queue', cb);
|
||||
};
|
||||
|
||||
const playerErrorListener = (cb: (event: IpcRendererEvent, data: { code: number }) => void) => {
|
||||
ipcRenderer.on('player-error-listener', cb);
|
||||
};
|
||||
|
||||
const mainMessageListener = (
|
||||
cb: (
|
||||
event: IpcRendererEvent,
|
||||
data: { message: string; type: 'success' | 'error' | 'warning' | 'info' },
|
||||
) => void,
|
||||
) => {
|
||||
ipcRenderer.on('toast-from-main', cb);
|
||||
};
|
||||
|
||||
const logger = (
|
||||
cb: (
|
||||
event: IpcRendererEvent,
|
||||
data: {
|
||||
message: string;
|
||||
type: 'debug' | 'verbose' | 'error' | 'warning' | 'info';
|
||||
},
|
||||
) => void,
|
||||
) => {
|
||||
ipcRenderer.send('logger', cb);
|
||||
};
|
||||
|
||||
export const utils = {
|
||||
isLinux,
|
||||
isMacOS,
|
||||
isWindows,
|
||||
logger,
|
||||
mainMessageListener,
|
||||
onRestoreQueue,
|
||||
onSaveQueue,
|
||||
playerErrorListener,
|
||||
restoreQueue,
|
||||
saveQueue,
|
||||
};
|
||||
|
@ -1,10 +1,13 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useMemo, useEffect } from 'react';
|
||||
import isElectron from 'is-electron';
|
||||
import { Navigate, Outlet } from 'react-router-dom';
|
||||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import { useCurrentServer } from '/@/renderer/store';
|
||||
import { toast } from '/@/renderer/components';
|
||||
|
||||
const localSettings = isElectron() ? window.electron.localSettings : null;
|
||||
const ipc = isElectron() ? window.electron.ipc : null;
|
||||
const utils = isElectron() ? window.electron.utils : null;
|
||||
|
||||
export const AppOutlet = () => {
|
||||
const currentServer = useCurrentServer();
|
||||
@ -29,6 +32,16 @@ export const AppOutlet = () => {
|
||||
return isActionRequired;
|
||||
}, [currentServer]);
|
||||
|
||||
useEffect(() => {
|
||||
utils?.mainMessageListener((_event, data) => {
|
||||
toast.show(data);
|
||||
});
|
||||
|
||||
return () => {
|
||||
ipc?.removeAllListeners('toast-from-main');
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (isActionsRequired) {
|
||||
return (
|
||||
<Navigate
|
||||
|
Loading…
Reference in New Issue
Block a user