mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
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:
1 parent
6e72e2c50e
commit
1a09fa57ae
7 files changed
+76
-31
No files matched your search
+42
-16
@@ -4,7 +4,7 @@ import './i18n';
|
||||
import { Route } from 'react-router-dom';
|
||||
import { CallModal } from './os/call/components/CallModal';
|
||||
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 { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||
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 { useCallModal } from './os/call/hooks/useCallModal';
|
||||
import WindowSnackbar from './ui/components/WindowSnackbar';
|
||||
import { usePhone } from './os/phone/hooks/usePhone';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
function Phone() {
|
||||
const { t } = useTranslation();
|
||||
const { apps } = useApps();
|
||||
|
||||
const [settings] = useSettings();
|
||||
@@ -51,6 +54,7 @@ function Phone() {
|
||||
|
||||
const { modal: callModal } = useCallModal();
|
||||
const { bottom, visibility } = usePhoneVisibility();
|
||||
const { isPhoneReady } = usePhone();
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -79,21 +83,38 @@ function Phone() {
|
||||
backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`,
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<NotificationBar />
|
||||
<div className="PhoneAppContainer">
|
||||
<>
|
||||
<Route exact path="/" component={HomeApp} />
|
||||
{callModal && <Route exact path="/call" component={CallModal} />}
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
<NotificationAlert />
|
||||
<PhoneSnackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</>
|
||||
{isPhoneReady ? (
|
||||
<>
|
||||
<NotificationBar />
|
||||
<div className="PhoneAppContainer">
|
||||
<>
|
||||
<Route exact path="/" component={HomeApp} />
|
||||
{callModal && <Route exact path="/call" component={CallModal} />}
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
<NotificationAlert />
|
||||
<PhoneSnackbar />
|
||||
</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>
|
||||
@@ -110,4 +131,9 @@ InjectDebugData([
|
||||
method: 'setVisibility',
|
||||
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 { useTranslation } from 'react-i18next';
|
||||
import { useMessageNotifications } from './useMessageNotifications';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export const useMessagesService = () => {
|
||||
const setMessageGroups = useSetRecoilState(messageState.messageGroups);
|
||||
@@ -15,10 +14,6 @@ export const useMessagesService = () => {
|
||||
const { setNotification } = useMessageNotifications();
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send('phone:fetchMessageGroups');
|
||||
}, []);
|
||||
|
||||
const handleAddAlert = useCallback(
|
||||
({ message, type }: IAlert) => {
|
||||
addAlert({
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
|
||||
|
||||
"COMING_SOON": "Coming soon...",
|
||||
"INITIALIZING": "Initializing",
|
||||
|
||||
"APPS_DIALER": "Phone",
|
||||
"APPS_CONTACTS": "Contacts",
|
||||
@@ -119,6 +120,7 @@
|
||||
"APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
|
||||
"APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing",
|
||||
|
||||
"GENERIC_WAIT": "Please wait...",
|
||||
"GENERIC_SAVE": "Save",
|
||||
"GENERIC_UPDATE": "Update",
|
||||
"GENERIC_DELETE": "Delete",
|
||||
|
||||
@@ -9,8 +9,8 @@ export const phoneState = {
|
||||
key: 'phoneConfig',
|
||||
default: undefined,
|
||||
}),
|
||||
forceUpdateState: atom({
|
||||
key: 'fuckingupdate',
|
||||
default: 0,
|
||||
phoneReady: atom({
|
||||
key: 'phoneReady',
|
||||
default: false,
|
||||
}),
|
||||
};
|
||||
@@ -10,10 +10,12 @@ interface IUsePhone {
|
||||
openPhone(): void;
|
||||
closePhone(): void;
|
||||
isPhoneOpen: boolean;
|
||||
isPhoneReady: boolean;
|
||||
}
|
||||
|
||||
export const usePhone = (): IUsePhone => {
|
||||
const isPhoneOpen = useRecoilValue(phoneState.visibility);
|
||||
const isPhoneReady = useRecoilValue(phoneState.phoneReady);
|
||||
|
||||
const { removeAlerts } = useNotifications();
|
||||
|
||||
@@ -25,5 +27,5 @@ export const usePhone = (): IUsePhone => {
|
||||
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 = () => {
|
||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
|
||||
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
|
||||
useNuiEvent('PHONE', 'setVisibility', setVisibility);
|
||||
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
|
||||
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
|
||||
};
|
||||
@@ -3,6 +3,26 @@ import events from '../utils/events';
|
||||
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
|
||||
|
||||
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');
|
||||
|
||||
@@ -90,6 +110,8 @@ async function Phone(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
onNet('esx:playerLoaded', fetchOnInitialize);
|
||||
|
||||
AddEventHandler('onResourceStop', function (resource: string) {
|
||||
if (resource === GetCurrentResourceName()) {
|
||||
SendNuiMessage(
|
||||
@@ -116,17 +138,13 @@ onNet('phone:sendCredentials', (number: string) => {
|
||||
});
|
||||
|
||||
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
|
||||
// ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ
|
||||
|
||||
/* * * * * * * * * * * * *
|
||||
*
|
||||
* NUI Service Callback Registration
|
||||
*
|
||||
* * * * * * * * * * * * */
|
||||
|
||||
function fetchOnInitialize() {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
}
|
||||
|
||||
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
|
||||
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
|
||||
Reference in new issue
Block a user