mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
* chore(phone/settings): Removed unused state * cleanup(phone/photos): Added type safety to photo state * tweak(phone/marketplace): Added type safety to marketplace state * chore(phone/match): Removed unnecessary console.log * tweak(phone/messages): Added type safety to messages state Also fixed ESLint warning for exported anonymous hook in useMessages.ts * tweak(phone/match): Added type safety to match state * tweak(phone/dialer): Cleanup & type safety for state Renamed some types to better represent their data * cleanup(phone/gen): Added NUI event enums for phone events * tweak(phone/contacts): Type safety for contacts state & variable rename Renamed and type variable in setFilteredContacts to better represent its use * tweak(phone/gen-state): Added type-safety to gen phone global state * tweak(phone/settings): Type safety for settings state * tweak(phone/photos): Tweaked type for photo referral * fix(phone/notification-comp): Fix reference to old theme config * chore(phone/hooks): Remove keyboard service Removed as this was unused and ESLint was not happy with it * chore(phone): Cleaned up eslint warnings No more warnings hooray! * tweak(phone): Set time in dev mode * fix(phone): Remove useNuiService that appeared somehow * fix(phone/gallery): Fixed missing import for gallery * Revert removing the keyboard service as this is built upon in another PR This reverts commit 82d12255a84e918da087d988b599af98ce1fe54d. * fix(phone/keyboard): Add useKeyboardService hook back to Phone.tsx * fix(phone/gallery): Fix and standardized GalleryPhoto type
128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
import { IPhoto, PhotoEvents } from '../../typings/photo';
|
|
import { Delay } from '../utils/fivem';
|
|
import { sendMessage, sendCameraEvent } from '../utils/messages';
|
|
import { PhoneEvents } from '../../typings/phone';
|
|
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
|
|
|
|
const exp = (global as any).exports;
|
|
|
|
let inCameraMode = false;
|
|
|
|
function closePhoneTemp() {
|
|
SetNuiFocus(false, false);
|
|
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
|
|
}
|
|
|
|
function openPhoneTemp() {
|
|
SetNuiFocus(true, true);
|
|
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
|
|
}
|
|
|
|
function CellFrontCamActivate(activate: boolean) {
|
|
return Citizen.invokeNative('0x2491A93618B7D838', activate);
|
|
}
|
|
|
|
const displayHelperText = () => {
|
|
BeginTextCommandDisplayHelp('TWOSTRINGS');
|
|
AddTextComponentString('Exit Camera Mode: ~INPUT_CELLPHONE_CANCEL~');
|
|
AddTextComponentString('Toggle Front/Back: ~INPUT_PHONE~');
|
|
EndTextCommandDisplayHelp(0, true, false, -1);
|
|
};
|
|
|
|
RegisterNuiCallbackType(PhotoEvents.TAKE_PHOTO);
|
|
on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
|
|
cb();
|
|
// Create Phone Prop
|
|
let frontCam = false;
|
|
CreateMobilePhone(1);
|
|
// Active Camera Change
|
|
CellCamActivate(true, true);
|
|
// Hide phone from rendering temporary
|
|
closePhoneTemp();
|
|
|
|
SetNuiFocus(false, false);
|
|
|
|
inCameraMode = true;
|
|
|
|
while (inCameraMode) {
|
|
await Delay(0);
|
|
displayHelperText();
|
|
if (IsControlJustPressed(1, 27)) {
|
|
frontCam = !frontCam;
|
|
CellFrontCamActivate(frontCam);
|
|
} else if (IsControlJustPressed(1, 176)) {
|
|
await handleTakePicture();
|
|
} else if (IsControlJustPressed(1, 177)) {
|
|
handleCameraExit();
|
|
break;
|
|
}
|
|
}
|
|
ClearHelp(true);
|
|
});
|
|
|
|
const handleTakePicture = async () => {
|
|
takePhoto();
|
|
await Delay(200);
|
|
DestroyMobilePhone();
|
|
CellCamActivate(false, false);
|
|
openPhoneTemp();
|
|
sendCameraEvent(PhotoEvents.UPLOAD_PHOTO, true);
|
|
inCameraMode = false;
|
|
};
|
|
|
|
const handleCameraExit = () => {
|
|
DestroyMobilePhone();
|
|
CellCamActivate(false, false);
|
|
openPhoneTemp();
|
|
sendCameraEvent(PhotoEvents.TAKE_PHOTO_SUCCESS, false);
|
|
inCameraMode = false;
|
|
};
|
|
|
|
onNet(PhotoEvents.SEND_PHOTOS, (photos: string[]) => {
|
|
sendCameraEvent(PhotoEvents.SEND_PHOTOS, photos);
|
|
});
|
|
|
|
function takePhoto() {
|
|
// Return and log error if screenshot basic token not found
|
|
if (SCREENSHOT_BASIC_TOKEN === 'none') {
|
|
return console.error('Screenshot basic token not found. Please set in server.cfg');
|
|
}
|
|
exp['screenshot-basic'].requestScreenshotUpload(
|
|
'https://api.imgur.com/3/image',
|
|
'imgur',
|
|
{
|
|
headers: {
|
|
authorization: `Client-ID ${SCREENSHOT_BASIC_TOKEN}`,
|
|
'content-type': 'multipart/form-data',
|
|
},
|
|
},
|
|
(data: string) => {
|
|
try {
|
|
const imageLink = JSON.parse(data).data.link;
|
|
emitNet(PhotoEvents.UPLOAD_PHOTO, imageLink);
|
|
} catch (e) {
|
|
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
onNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, (photo: IPhoto) => {
|
|
if (photo && photo.image) {
|
|
return sendCameraEvent(PhotoEvents.TAKE_PHOTO_SUCCESS, photo);
|
|
}
|
|
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
|
|
});
|
|
|
|
// delete photo
|
|
|
|
RegisterNuiCallbackType(PhotoEvents.DELETE_PHOTO);
|
|
on(`__cfx_nui:${PhotoEvents.DELETE_PHOTO}`, (data: any, cb: Function) => {
|
|
emitNet(PhotoEvents.DELETE_PHOTO, data);
|
|
cb();
|
|
});
|
|
|
|
onNet(PhotoEvents.DELETE_PHOTO_SUCCESS, () => {
|
|
emitNet(PhotoEvents.FETCH_PHOTOS);
|
|
});
|