mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +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
+61
-16
No files matched your search
+27
-1
@@ -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,6 +83,7 @@ function Phone() {
|
|||||||
backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`,
|
backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{isPhoneReady ? (
|
||||||
<>
|
<>
|
||||||
<NotificationBar />
|
<NotificationBar />
|
||||||
<div className="PhoneAppContainer">
|
<div className="PhoneAppContainer">
|
||||||
@@ -94,6 +99,22 @@ function Phone() {
|
|||||||
</div>
|
</div>
|
||||||
<Navigation />
|
<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({
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -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);
|
||||||
};
|
};
|
||||||
@@ -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);
|
||||||
|
|||||||
Reference in new issue
Block a user