diff --git a/phone/src/apps/messages/components/form/MessageInput.tsx b/phone/src/apps/messages/components/form/MessageInput.tsx index 1b81063..5f8a7cf 100644 --- a/phone/src/apps/messages/components/form/MessageInput.tsx +++ b/phone/src/apps/messages/components/form/MessageInput.tsx @@ -43,6 +43,8 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => { { + const { send } = useNuiRequest(); + + // Let client know UI is ready to accept events + useEffect(() => { + send(PhoneEvents.UI_IS_READY); + }, [send]); + const setVisibility = useSetRecoilState(phoneState.visibility); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneReady = useSetRecoilState(phoneState.phoneReady); diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index 5d1080a..0291c65 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -13,7 +13,8 @@ import { CallEvents } from '../../typings/call'; import { MatchEvents } from '../../typings/match'; let isPhoneOpen = false; -let isPhoneReady = false; +let isPlayerReady = false; +let isUiReady = false; /* * * * * * * * * * * * * * @@ -21,11 +22,10 @@ let isPhoneReady = false; * * * * * * * * * * * * * */ function fetchOnInitialize() { - isPhoneReady = true; emitNet(ContactEvents.GET_CONTACTS); emitNet(MessageEvents.FETCH_MESSAGE_GROUPS); emitNet(TwitterEvents.GET_OR_CREATE_PROFILE); - sendMessage('PHONE', 'setPhoneReady', isPhoneReady); + sendMessage('PHONE', 'setPhoneReady', true); sendMessage('PHONE', 'phoneConfig', config); } @@ -97,7 +97,6 @@ RegisterCommand( * * * * * * * * * * * * */ async function Phone(): Promise { - fetchOnInitialize(); if (config.PhoneAsItem) { // TODO: Do promise callback here // const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem') @@ -111,7 +110,12 @@ async function Phone(): Promise { } // triggerd when the player is ready -onNet(PhoneEvents.PLAYER_IS_READY, fetchOnInitialize); +onNet(PhoneEvents.PLAYER_IS_READY, () => { + isPlayerReady = true; + if (isUiReady) { + fetchOnInitialize(); + } +}); AddEventHandler('onResourceStop', function (resource: string) { if (resource === GetCurrentResourceName()) { @@ -126,6 +130,15 @@ onNet('phone:sendCredentials', (number: string) => { sendMessage('SIMCARD', 'setNumber', number); }); +RegisterNuiCallbackType(PhoneEvents.UI_IS_READY); +on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => { + isUiReady = true; + if (isPlayerReady) { + fetchOnInitialize(); + } + cb(); +}); + // DO NOT CHANGE THIS EITHER, PLEASE - CHIP // ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ diff --git a/typings/phone.ts b/typings/phone.ts index a547dfa..ae71cea 100644 --- a/typings/phone.ts +++ b/typings/phone.ts @@ -1,6 +1,7 @@ export const PHONE_NUMBER_REGEX = /^([0-9]{3}-[0-9]{4})|([0-9]{7})$/; export enum PhoneEvents { + UI_IS_READY = 'npwd:uiIsReady', PLAYER_IS_READY = 'npwd:playerIsReady', OPEN_APP_CONTACTS = 'npwd:app:CONTACTS', OPEN_APP_BANK = 'npwd:app:BANK',