mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-01 20:39:18 +00:00
refactor: register modal in electron
This commit is contained in:
committed by
Carlos Valente
parent
80ff3251ea
commit
43b390a079
@@ -4,15 +4,20 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
const isElectron = window.process?.type === 'renderer';
|
const isElectron = window.process?.type === 'renderer';
|
||||||
const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null;
|
const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null;
|
||||||
|
|
||||||
export default function useElectronEvent() {
|
export function useElectronEvent() {
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const sendToElectron = useCallback((channel: string, args?: string | Record<string, unknown>) => {
|
const sendToElectron = useCallback((channel: string, args?: string | Record<string, unknown>) => {
|
||||||
if (isElectron && ipcRenderer) {
|
if (isElectron && ipcRenderer) {
|
||||||
ipcRenderer.send(channel, args);
|
ipcRenderer.send(channel, args);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
return { isElectron, sendToElectron };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useElectronListener() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { isElectron } = useElectronEvent();
|
||||||
|
|
||||||
// listen to requests to change the editor location
|
// listen to requests to change the editor location
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
@@ -25,7 +30,5 @@ export default function useElectronEvent() {
|
|||||||
return () => {
|
return () => {
|
||||||
ipcRenderer?.removeAllListeners();
|
ipcRenderer?.removeAllListeners();
|
||||||
};
|
};
|
||||||
}, [navigate]);
|
}, [isElectron, navigate]);
|
||||||
|
|
||||||
return { isElectron, sendToElectron };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ export default function ManageProjects() {
|
|||||||
|
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const isCreatingProject = searchParams.get('create') === 'true';
|
const isCreatingProject = searchParams.get('new') === 'true';
|
||||||
|
|
||||||
const handleToggleCreate = () => {
|
const handleToggleCreate = () => {
|
||||||
searchParams.set('create', isCreatingProject ? 'false' : 'true');
|
searchParams.set('new', isCreatingProject ? 'false' : 'true');
|
||||||
setSearchParams(searchParams);
|
setSearchParams(searchParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ export default function ManageProjects() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseForm = () => {
|
const handleCloseForm = () => {
|
||||||
searchParams.delete('create');
|
searchParams.delete('new');
|
||||||
setSearchParams(searchParams);
|
setSearchParams(searchParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { IoClose } from '@react-icons/all-files/io5/IoClose';
|
|||||||
import { IoSettingsOutline } from '@react-icons/all-files/io5/IoSettingsOutline';
|
import { IoSettingsOutline } from '@react-icons/all-files/io5/IoSettingsOutline';
|
||||||
|
|
||||||
import ProductionNavigationMenu from '../../common/components/navigation-menu/ProductionNavigationMenu';
|
import ProductionNavigationMenu from '../../common/components/navigation-menu/ProductionNavigationMenu';
|
||||||
|
import { useElectronListener } from '../../common/hooks/useElectronEvent';
|
||||||
import { useWindowTitle } from '../../common/hooks/useWindowTitle';
|
import { useWindowTitle } from '../../common/hooks/useWindowTitle';
|
||||||
import AppSettings from '../app-settings/AppSettings';
|
import AppSettings from '../app-settings/AppSettings';
|
||||||
import useAppSettingsNavigation from '../app-settings/useAppSettingsNavigation';
|
import useAppSettingsNavigation from '../app-settings/useAppSettingsNavigation';
|
||||||
@@ -26,6 +27,9 @@ export default function Editor() {
|
|||||||
|
|
||||||
useWindowTitle('Editor');
|
useWindowTitle('Editor');
|
||||||
|
|
||||||
|
// we need to register the listener to change the editor location
|
||||||
|
useElectronListener();
|
||||||
|
|
||||||
// listen to shutdown request from electron process
|
// listen to shutdown request from electron process
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.process?.type === 'renderer') {
|
if (window.process?.type === 'renderer') {
|
||||||
|
|||||||
@@ -81,14 +81,18 @@ function makeFileMenu(serverUrl, redirectWindow, download) {
|
|||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'New project...',
|
label: 'New project...',
|
||||||
click: () => redirectWindow('/editor?settings=project__manage&create=true'),
|
click: () => redirectWindow('/editor?settings=project__manage&new=true'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Edit project info',
|
label: 'Quick start...',
|
||||||
|
click: () => redirectWindow('/editor?settings=project__create'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Edit project info...',
|
||||||
click: () => redirectWindow('/editor?settings=project__data'),
|
click: () => redirectWindow('/editor?settings=project__data'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Manage projects...',
|
label: 'Manage projects',
|
||||||
click: () => redirectWindow('/editor?settings=project__manage'),
|
click: () => redirectWindow('/editor?settings=project__manage'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user