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