refactor: register modal in electron

This commit is contained in:
Carlos Valente
2024-10-27 10:20:01 +01:00
committed by Carlos Valente
parent 80ff3251ea
commit 43b390a079
4 changed files with 23 additions and 12 deletions
@@ -4,15 +4,20 @@ import { useNavigate } from 'react-router-dom';
const isElectron = window.process?.type === 'renderer';
const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null;
export default function useElectronEvent() {
const navigate = useNavigate();
export function useElectronEvent() {
const sendToElectron = useCallback((channel: string, args?: string | Record<string, unknown>) => {
if (isElectron && ipcRenderer) {
ipcRenderer.send(channel, args);
}
}, []);
return { isElectron, sendToElectron };
}
export function useElectronListener() {
const navigate = useNavigate();
const { isElectron } = useElectronEvent();
// listen to requests to change the editor location
useEffect(() => {
if (isElectron) {
@@ -25,7 +30,5 @@ export default function useElectronEvent() {
return () => {
ipcRenderer?.removeAllListeners();
};
}, [navigate]);
return { isElectron, sendToElectron };
}, [isElectron, navigate]);
}