Fix: Workaround for ESX errors pertaining to player loading (#153)

* Set phone ready before sending any init events + Show initializing phone message if not ready yet

* Send phone ready to nui
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-03-06 19:25:32 -05:00
1 parent 6e72e2c50e
commit 1a09fa57ae
7 files changed
+76 -31

No files matched your search

+42 -16
View File
@@ -4,7 +4,7 @@ import './i18n';
import { Route } from 'react-router-dom'; import { Route } from 'react-router-dom';
import { CallModal } from './os/call/components/CallModal'; import { CallModal } from './os/call/components/CallModal';
import { HomeApp } from './apps/home/components/Home'; import { HomeApp } from './apps/home/components/Home';
import { Slide } from '@material-ui/core'; import { Box, Paper, Slide, Typography } from '@material-ui/core';
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService'; import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
import { NotificationBar } from './os/notifications/components/NotificationBar'; import { NotificationBar } from './os/notifications/components/NotificationBar';
import { Navigation } from './os/navigation-bar/components/Navigation'; import { Navigation } from './os/navigation-bar/components/Navigation';
@@ -29,8 +29,11 @@ import { PhoneSnackbar } from './ui/components/PhoneSnackbar';
import { NotificationAlert } from './os/notifications/components/NotificationAlert'; import { NotificationAlert } from './os/notifications/components/NotificationAlert';
import { useCallModal } from './os/call/hooks/useCallModal'; import { useCallModal } from './os/call/hooks/useCallModal';
import WindowSnackbar from './ui/components/WindowSnackbar'; import WindowSnackbar from './ui/components/WindowSnackbar';
import { usePhone } from './os/phone/hooks/usePhone';
import { useTranslation } from 'react-i18next';
function Phone() { function Phone() {
const { t } = useTranslation();
const { apps } = useApps(); const { apps } = useApps();
const [settings] = useSettings(); const [settings] = useSettings();
@@ -51,6 +54,7 @@ function Phone() {
const { modal: callModal } = useCallModal(); const { modal: callModal } = useCallModal();
const { bottom, visibility } = usePhoneVisibility(); const { bottom, visibility } = usePhoneVisibility();
const { isPhoneReady } = usePhone();
return ( return (
<div> <div>
@@ -79,21 +83,38 @@ function Phone() {
backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`, backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`,
}} }}
> >
<> {isPhoneReady ? (
<NotificationBar /> <>
<div className="PhoneAppContainer"> <NotificationBar />
<> <div className="PhoneAppContainer">
<Route exact path="/" component={HomeApp} /> <>
{callModal && <Route exact path="/call" component={CallModal} />} <Route exact path="/" component={HomeApp} />
{apps.map((App) => ( {callModal && <Route exact path="/call" component={CallModal} />}
<App.Route key={App.id} /> {apps.map((App) => (
))} <App.Route key={App.id} />
</> ))}
<NotificationAlert /> </>
<PhoneSnackbar /> <NotificationAlert />
</div> <PhoneSnackbar />
<Navigation /> </div>
</> <Navigation />
</>
) : (
<Box
component={Paper}
height="100%"
width="100%"
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
>
<Typography paragraph variant="h6">
NPWD {t('INITIALIZING')}
</Typography>
<Typography paragraph>{t('GENERIC_WAIT')}</Typography>
</Box>
)}
</div> </div>
</div> </div>
</div> </div>
@@ -110,4 +131,9 @@ InjectDebugData([
method: 'setVisibility', method: 'setVisibility',
data: true, data: true,
}, },
{
app: 'PHONE',
method: 'setPhoneReady',
data: true,
},
]); ]);
@@ -4,8 +4,7 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar'; import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useMessageNotifications } from './useMessageNotifications'; import { useMessageNotifications } from './useMessageNotifications';
import { useCallback, useEffect } from 'react'; import { useCallback } from 'react';
import Nui from '../../../os/nui-events/utils/Nui';
export const useMessagesService = () => { export const useMessagesService = () => {
const setMessageGroups = useSetRecoilState(messageState.messageGroups); const setMessageGroups = useSetRecoilState(messageState.messageGroups);
@@ -15,10 +14,6 @@ export const useMessagesService = () => {
const { setNotification } = useMessageNotifications(); const { setNotification } = useMessageNotifications();
const { t } = useTranslation(); const { t } = useTranslation();
useEffect(() => {
Nui.send('phone:fetchMessageGroups');
}, []);
const handleAddAlert = useCallback( const handleAddAlert = useCallback(
({ message, type }: IAlert) => { ({ message, type }: IAlert) => {
addAlert({ addAlert({
+2
View File
@@ -4,6 +4,7 @@
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A", "DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
"COMING_SOON": "Coming soon...", "COMING_SOON": "Coming soon...",
"INITIALIZING": "Initializing",
"APPS_DIALER": "Phone", "APPS_DIALER": "Phone",
"APPS_CONTACTS": "Contacts", "APPS_CONTACTS": "Contacts",
@@ -119,6 +120,7 @@
"APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing", "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
"APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing", "APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing",
"GENERIC_WAIT": "Please wait...",
"GENERIC_SAVE": "Save", "GENERIC_SAVE": "Save",
"GENERIC_UPDATE": "Update", "GENERIC_UPDATE": "Update",
"GENERIC_DELETE": "Delete", "GENERIC_DELETE": "Delete",
+3 -3
View File
@@ -9,8 +9,8 @@ export const phoneState = {
key: 'phoneConfig', key: 'phoneConfig',
default: undefined, default: undefined,
}), }),
forceUpdateState: atom({ phoneReady: atom({
key: 'fuckingupdate', key: 'phoneReady',
default: 0, default: false,
}), }),
}; };
+3 -1
View File
@@ -10,10 +10,12 @@ interface IUsePhone {
openPhone(): void; openPhone(): void;
closePhone(): void; closePhone(): void;
isPhoneOpen: boolean; isPhoneOpen: boolean;
isPhoneReady: boolean;
} }
export const usePhone = (): IUsePhone => { export const usePhone = (): IUsePhone => {
const isPhoneOpen = useRecoilValue(phoneState.visibility); const isPhoneOpen = useRecoilValue(phoneState.visibility);
const isPhoneReady = useRecoilValue(phoneState.phoneReady);
const { removeAlerts } = useNotifications(); const { removeAlerts } = useNotifications();
@@ -25,5 +27,5 @@ export const usePhone = (): IUsePhone => {
Nui.send('phone:open'); Nui.send('phone:open');
}; };
return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen }; return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen, isPhoneReady };
}; };
@@ -5,6 +5,8 @@ import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
export const usePhoneService = () => { export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility); const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
useNuiEvent('PHONE', 'setVisibility', setVisibility); useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig); useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
}; };
+23 -5
View File
@@ -3,6 +3,26 @@ import events from '../utils/events';
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions'; import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
let isPhoneOpen = false; let isPhoneOpen = false;
let isPhoneReady = false;
/* * * * * * * * * * * * *
*
* Phone initialize data
*
* * * * * * * * * * * * */
function fetchOnInitialize() {
isPhoneReady = true;
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS);
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE);
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setPhoneReady',
data: true,
}),
);
}
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1'); RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
@@ -90,6 +110,8 @@ async function Phone(): Promise<void> {
} }
} }
onNet('esx:playerLoaded', fetchOnInitialize);
AddEventHandler('onResourceStop', function (resource: string) { AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) { if (resource === GetCurrentResourceName()) {
SendNuiMessage( SendNuiMessage(
@@ -116,17 +138,13 @@ onNet('phone:sendCredentials', (number: string) => {
}); });
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP // DO NOT CHANGE THIS EITHER, PLEASE - CHIP
// ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ
/* * * * * * * * * * * * * /* * * * * * * * * * * * *
* *
* NUI Service Callback Registration * NUI Service Callback Registration
* *
* * * * * * * * * * * * */ * * * * * * * * * * * * */
function fetchOnInitialize() {
emitNet(events.CONTACTS_GET_CONTACTS);
}
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS); RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => { on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
emitNet(events.SELLOUT_FETCH_LISTING); emitNet(events.SELLOUT_FETCH_LISTING);