fix(phone): only listen to UI Ready

This commit is contained in:
Christopher committed 2021-05-21 00:35:05 +02:00
1 parent 2411c39b95
commit fb32aaef15
6 files changed
+26 -47

No files matched your search

+3 -17
View File
@@ -12,8 +12,6 @@ import { CallEvents } from '../../typings/call';
import { config } from './client';
let isPhoneOpen = false;
let isPlayerReady = false;
let isUiReady = false;
/* * * * * * * * * * * * *
*
@@ -24,7 +22,6 @@ function fetchOnInitialize() {
emitNet(ContactEvents.GET_CONTACTS);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS);
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE);
sendMessage('PHONE', PhoneEvents.SET_PHONE_READY, true);
sendMessage('PHONE', PhoneEvents.SET_CONFIG, config);
}
@@ -113,14 +110,10 @@ async function Phone(): Promise<void> {
}
}
// Set the global depending on the response from event
onNet(PhoneEvents.PLAYER_IS_READY, (ready: boolean) => {
isPlayerReady = ready;
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
});
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number)
})
AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) {
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
@@ -132,15 +125,8 @@ AddEventHandler('onResourceStop', function (resource: string) {
RegisterNuiCallbackType(PhoneEvents.UI_IS_READY);
on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => {
isUiReady = true;
if (isPlayerReady) {
fetchOnInitialize();
}
cb();
});
onNet(PhoneEvents.ON_INIT, () => {
fetchOnInitialize();
cb();
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP