tweak(resources): use 'custom appMessageEvent'

This commit is contained in:
Christopher committed 2021-03-15 10:53:02 +01:00
1 parent 5c9f36f754
commit 458839488e
4 files changed
+17 -95

No files matched your search

+3 -14
View File
@@ -1,13 +1,8 @@
import events from '../utils/events';
import { sendContactsEvent } from '../utils/messages';
onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
SendNuiMessage(
JSON.stringify({
app: 'CONTACTS',
method: 'setContacts',
data: contacts,
}),
);
sendContactsEvent('setContacts', contacts);
});
RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT);
@@ -41,11 +36,5 @@ onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
});
onNet(events.CONTACTS_ACTION_RESULT, (alert: any) => {
SendNuiMessage(
JSON.stringify({
app: 'CONTACTS',
method: 'setAlert',
data: alert,
}),
);
sendContactsEvent('setAlert', alert);
});
+7 -43
View File
@@ -1,5 +1,6 @@
import config from '../utils/config';
import events from '../utils/events';
import { sendMessage } from '../utils/messages';
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
let isPhoneOpen = false;
@@ -15,13 +16,7 @@ function fetchOnInitialize() {
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: isPhoneReady,
}),
);
sendMessage('PHONE', 'setPhoneReady', isPhoneReady);
}
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
@@ -37,26 +32,13 @@ const showPhone = async (): Promise<void> => {
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
SetCursorLocation(0.9, 0.922); //Experimental
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: true,
}),
);
sendMessage('PHONE', 'setVisibility', true);
SetNuiFocus(true, true);
};
const hidePhone = async (): Promise<void> => {
isPhoneOpen = false;
SendNuiMessage(
//Hides phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
}),
);
sendMessage('PHONE', 'setVisibility', false);
await phoneCloseAnim();
SetNuiFocus(false, false);
};
@@ -79,13 +61,7 @@ RegisterCommand(
'phone:restart',
async () => {
await hidePhone();
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'startRestart',
data: {},
}),
);
sendMessage('PHONE', 'phoneRestart', {});
},
false,
);
@@ -115,13 +91,7 @@ onNet(events.PLAYER_IS_READY, fetchOnInitialize);
AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) {
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
}),
);
sendMessage('PHONE', 'setVisibility', false);
SetNuiFocus(false, false);
removePhoneProp(); //Deletes the phone incase it was attached.
ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations.
@@ -129,13 +99,7 @@ AddEventHandler('onResourceStop', function (resource: string) {
});
onNet('phone:sendCredentials', (number: string) => {
SendNuiMessage(
JSON.stringify({
app: 'SIMCARD',
method: 'setNumber',
data: number,
}),
);
sendMessage('SIMCARD', 'setNumber', number);
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
+4 -24
View File
@@ -1,5 +1,6 @@
import events from '../utils/events';
import { Delay } from '../utils/fivem';
import { sendMessage, sendCameraEvent } from '../utils/messages';
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
const exp = (global as any).exports;
@@ -8,26 +9,12 @@ let inCameraMode = false;
function closePhoneTemp() {
SetNuiFocus(false, false);
SendNuiMessage(
//Hides phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
}),
);
sendMessage('PHONE', 'setVisibility', false);
}
function openPhoneTemp() {
SetNuiFocus(true, true);
SendNuiMessage(
//Opens phone
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: true,
}),
);
sendMessage('PHONE', 'setVisibility', true);
}
function CellFrontCamActivate(activate: boolean) {
@@ -89,14 +76,7 @@ const handleCameraExit = () => {
};
onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
// console.log(photos);
SendNuiMessage(
JSON.stringify({
app: 'CAMERA',
method: 'setPhotos',
data: photos,
}),
);
sendCameraEvent('setPhotos', photos);
});
function takePhoto() {
+3 -14
View File
@@ -1,15 +1,10 @@
import events from '../utils/events';
import { MarketplaceListing } from '../../typings/marketplace';
import { IAlertProps } from '../../typings/alerts';
import { sendMarketplaceEvent } from '../utils/messages';
onNet(events.SELLOUT_SEND_LISTING, (listing: MarketplaceListing) => {
SendNuiMessage(
JSON.stringify({
app: 'SELLOUT',
method: 'setListings',
data: listing,
}),
);
sendMarketplaceEvent('setListing', listing);
});
RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING);
@@ -39,11 +34,5 @@ onNet(events.SELLOUT_DELETE_LISTING_SUCCESS, () => {
});
onNet(events.SELLOUT_ACTION_RESULT, (alert: IAlertProps) => {
SendNuiMessage(
JSON.stringify({
app: 'SELLOUT',
method: 'setAlert',
data: alert,
}),
);
sendMarketplaceEvent('setAlert', alert);
});