feat(client/debug): Phone restart command (#145)

Trigger a UI restart by entering the command `phone:restart` in the F8 console.
This commit is contained in:
Taso authored and GitHub committed 2021-03-06 10:38:10 -05:00
1 parent 531a341ffd
commit 605f957f9a
3 files changed
+53 -11

No files matched your search

+2
View File
@@ -28,6 +28,7 @@ import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
import { Snackbar } from './ui/components/Snackbar';
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
import { useCallModal } from './os/call/hooks/useCallModal';
import WindowSnackbar from './ui/components/WindowSnackbar';
function Phone() {
const { apps } = useApps();
@@ -53,6 +54,7 @@ function Phone() {
return (
<div>
<WindowSnackbar />
<Slide direction="up" timeout={{ enter: 500, exit: 500 }} in={visibility}>
<div className="PhoneWrapper">
<div
@@ -0,0 +1,42 @@
import React, { useState } from 'react';
import { Snackbar, Typography } from '@material-ui/core';
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
import { Alert } from './Alert';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles({
root: {
position: 'absolute',
width: 'auto',
bottom: 20,
},
});
// NOTE: Will make this more generic at some point for error handling as well
const WindowSnackbar = () => {
const [open, setOpen] = useState<boolean>(false);
const [message, setMessage] = useState<string>('');
const [severity, setSeverity] = useState<'info' | 'error' | 'success'>('info');
const classes = useStyles();
useNuiEvent('PHONE', 'startRestart', () => {
setMessage('Restarting UI');
setOpen(true);
setSeverity('error');
setTimeout(() => window.location.reload(), 3000);
});
const handleClose = () => {
setOpen(false);
};
return (
<Snackbar open={open} onClose={handleClose} className={classes.root}>
<Alert severity={severity}>
<Typography variant="body1">Phone - {message}</Typography>
</Alert>
</Snackbar>
);
};
export default WindowSnackbar;
+9 -11
View File
@@ -46,15 +46,6 @@ const hidePhone = async (): Promise<void> => {
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
async () => {
await hidePhone();
},
false,
);
RegisterCommand(
'phone',
async () => {
@@ -65,9 +56,16 @@ RegisterCommand(
);
RegisterCommand(
'phone:open',
'phone:restart',
async () => {
await showPhone();
await hidePhone();
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'startRestart',
data: {},
}),
);
},
false,
);