mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-02 12:59:09 +00:00
graceful shutdown
- confirmation dialog - shutdown node service
This commit is contained in:
@@ -1,21 +1,68 @@
|
|||||||
import { IconButton } from '@chakra-ui/button';
|
import { Button, IconButton } from '@chakra-ui/button';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogBody,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogOverlay,
|
||||||
|
} from '@chakra-ui/modal';
|
||||||
import { Tooltip } from '@chakra-ui/tooltip';
|
import { Tooltip } from '@chakra-ui/tooltip';
|
||||||
|
import { useRef, useState } from 'react';
|
||||||
import { FiPower } from 'react-icons/fi';
|
import { FiPower } from 'react-icons/fi';
|
||||||
|
|
||||||
export default function QuitIconBtn(props) {
|
export default function QuitIconBtn(props) {
|
||||||
const { clickhandler, ...rest } = props;
|
const { clickhandler, ...rest } = props;
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const onClose = () => setIsOpen(false);
|
||||||
|
const cancelRef = useRef();
|
||||||
|
|
||||||
|
const handleShutdown = () => {
|
||||||
|
onClose();
|
||||||
|
clickhandler();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip label='Quit Application'>
|
<>
|
||||||
<IconButton
|
<Tooltip label='Quit Application'>
|
||||||
size={props.size || 'xs'}
|
<IconButton
|
||||||
icon={<FiPower />}
|
size={props.size || 'xs'}
|
||||||
colorScheme='red'
|
icon={<FiPower />}
|
||||||
variant='outline'
|
colorScheme='red'
|
||||||
isRound
|
variant='outline'
|
||||||
onClick={clickhandler}
|
isRound
|
||||||
_focus={{ boxShadow: 'none' }}
|
onClick={() => setIsOpen(true)}
|
||||||
{...rest}
|
_focus={{ boxShadow: 'none' }}
|
||||||
/>
|
{...rest}
|
||||||
</Tooltip>
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<AlertDialog
|
||||||
|
isOpen={isOpen}
|
||||||
|
leastDestructiveRef={cancelRef}
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
|
<AlertDialogOverlay>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader fontSize='lg' fontWeight='bold'>
|
||||||
|
Server Shutdown
|
||||||
|
</AlertDialogHeader>
|
||||||
|
|
||||||
|
<AlertDialogBody>
|
||||||
|
This will shutdown the program and all running servers. Are you
|
||||||
|
sure?
|
||||||
|
</AlertDialogBody>
|
||||||
|
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<Button ref={cancelRef} onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button colorScheme='red' onClick={handleShutdown} ml={3}>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialogOverlay>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,6 +195,16 @@ ipcMain.on('test-message', (event, arg) => {
|
|||||||
// Terminate
|
// Terminate
|
||||||
ipcMain.on('shutdown', (event, arg) => {
|
ipcMain.on('shutdown', (event, arg) => {
|
||||||
console.log('Got IPC shutdown');
|
console.log('Got IPC shutdown');
|
||||||
|
|
||||||
|
// terminate node service
|
||||||
|
(async () => {
|
||||||
|
const { shutdown } = await import(
|
||||||
|
path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js')
|
||||||
|
);
|
||||||
|
// Start express server
|
||||||
|
await shutdown();
|
||||||
|
})();
|
||||||
|
|
||||||
win.destroy();
|
win.destroy();
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|||||||
+11
-1
@@ -106,7 +106,7 @@ export const startServer = (overrideConfig = null) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Start OSC server
|
// Start OSC server
|
||||||
import { initiateOSC } from './controllers/OscController.js';
|
import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
|
||||||
|
|
||||||
export const startOSCServer = (overrideConfig = null) => {
|
export const startOSCServer = (overrideConfig = null) => {
|
||||||
// Setup default port
|
// Setup default port
|
||||||
@@ -119,3 +119,13 @@ export const startOSCClient = (overrideConfig = null) => {
|
|||||||
const oscOutPort = overrideConfig?.port || config.osc.portOut;
|
const oscOutPort = overrideConfig?.port || config.osc.portOut;
|
||||||
console.log('initialise OSC Client at port: ', oscOutPort);
|
console.log('initialise OSC Client at port: ', oscOutPort);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const shutdown = () => {
|
||||||
|
console.log('Node service shutdown');
|
||||||
|
|
||||||
|
// shutdown express server
|
||||||
|
server.close();
|
||||||
|
// shutdown OSC Server
|
||||||
|
shutdownOSCServer();
|
||||||
|
// shutdown OSC Client
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { Server } from 'node-osc';
|
import { Server } from 'node-osc';
|
||||||
|
|
||||||
|
let oscServer = null;
|
||||||
|
|
||||||
|
export const shutdownOSCServer = () => {
|
||||||
|
if (oscServer != null) oscServer.close();
|
||||||
|
};
|
||||||
|
|
||||||
export const initiateOSC = (config) => {
|
export const initiateOSC = (config) => {
|
||||||
const oscServer = new Server(config.port, '0.0.0.0', () => {
|
oscServer = new Server(config.port, '0.0.0.0', () => {
|
||||||
console.log(`OSC Server is listening on port ${config.port}`);
|
console.log(`OSC Server is listening on port ${config.port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user