mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
Add: Simcard, simcardService + Add: nuiEvent, nuiService
This commit is contained in:
1 parent
ec37fcde46
commit
f862100d4b
14 files changed
+101
-5
No files matched your search
+21
-4
@@ -3,9 +3,6 @@ import "./Phone.css";
|
||||
import "./i18n";
|
||||
import { Route } from "react-router-dom";
|
||||
import { useSettings } from "./apps/settings/hooks/useSettings";
|
||||
import { NotificationBar } from "./os/components/NotificationBar";
|
||||
import { NotificationIcon } from "./os/components/NotificationIcon";
|
||||
import { Navigation } from "./os/components/Navigation";
|
||||
import MessageIcon from "@material-ui/icons/Email";
|
||||
|
||||
import { HomeApp } from "./apps/home/components/Home";
|
||||
@@ -15,9 +12,29 @@ import { PhoneApp } from "./apps/phone/components/PhoneApp";
|
||||
import { BankApp } from "./apps/bank/components/BankApp";
|
||||
import { ThemeProvider } from "@material-ui/core";
|
||||
import { CalculatorApp } from "./apps/calculator/components/CalculatorApp";
|
||||
import { useInitKeyboard } from "./os/hooks/useKeyboard";
|
||||
import { useInitKeyboard } from "./os/keyboard/hooks/useKeyboard";
|
||||
import { NotificationIcon } from "./os/notifications/components/NotificationIcon";
|
||||
import { NotificationBar } from "./os/notifications/components/NotificationBar";
|
||||
import { Navigation } from "./os/navigation-bar/components/Navigation";
|
||||
import { useNuiService } from "./os/nui-events/hooks/useNuiService";
|
||||
import { useSimcardService } from "./os/simcard/hooks/useSimcardService";
|
||||
|
||||
// @TODO: Remove this testing shit
|
||||
setTimeout(() => {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent("message", {
|
||||
data: {
|
||||
app: "simcard",
|
||||
method: "setNumber",
|
||||
data: "111-1111",
|
||||
},
|
||||
})
|
||||
);
|
||||
}, 3000);
|
||||
|
||||
function Phone() {
|
||||
useNuiService();
|
||||
useSimcardService();
|
||||
useInitKeyboard();
|
||||
const { settings, currentTheme } = useSettings();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useSettings } from "../hooks/useSettings";
|
||||
import { useApps } from "../../appmarket/hooks/useApps";
|
||||
import { List } from "../../../ui/components/List";
|
||||
import { ListItem } from "../../../ui/components/ListItem";
|
||||
import { useSimcard } from "../../../os/simcard/hooks/useSimcard";
|
||||
|
||||
export const SettingItem = ({ options, label, value, onClick }) => {
|
||||
return (
|
||||
@@ -30,6 +31,7 @@ export const SettingsApp = () => {
|
||||
const [config] = useConfig();
|
||||
const { getApp } = useApps();
|
||||
const { setSettings, settings } = useSettings();
|
||||
const simcard = useSimcard();
|
||||
|
||||
const wallpapers = config.wallpapers.map(
|
||||
MapStringOptions(settings.wallpaper, (val) => setSettings("wallpaper", val))
|
||||
@@ -67,6 +69,10 @@ export const SettingsApp = () => {
|
||||
options={frames}
|
||||
onClick={openMenu}
|
||||
/>
|
||||
<SettingItem
|
||||
label="Phone Number"
|
||||
value={simcard.number}
|
||||
/>
|
||||
</List>
|
||||
</AppContent>
|
||||
<ContextMenu />
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { eventNameFactory } from "../utils/nuiUtils";
|
||||
|
||||
export const useNuiEvent = (app, method, handler, options = {}) => {
|
||||
const savedHandler = useRef();
|
||||
const { capture, passive, once } = options;
|
||||
|
||||
useEffect(() => {
|
||||
savedHandler.current = event => {
|
||||
const { data } = event;
|
||||
if (handler && handler.call) {
|
||||
handler(data);
|
||||
}
|
||||
};
|
||||
}, [handler]);
|
||||
|
||||
useEffect(() => {
|
||||
const eventListener = (event) => savedHandler.current(event);
|
||||
const opts = { capture, passive, once };
|
||||
const eventName = eventNameFactory(app, method);
|
||||
window.addEventListener(eventName, eventListener, opts);
|
||||
return () => window.removeEventListener(eventName, eventListener, opts);
|
||||
}, [app, method, capture, passive, once]);
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useEffect } from "react";
|
||||
import { eventNameFactory } from "../utils/nuiUtils";
|
||||
|
||||
export const useNuiService = (options = {}) => {
|
||||
const { capture, passive, once } = options;
|
||||
const eventListener = (event) => {
|
||||
console.log(event);
|
||||
const { app, method, data } = event.data;
|
||||
if (app && method && data) {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent(eventNameFactory(app, method), {
|
||||
data,
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
const opts = { capture, passive, once };
|
||||
window.addEventListener("message", eventListener, opts);
|
||||
return () => window.removeEventListener("message", eventListener, opts);
|
||||
}, [capture, passive, once]);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export const eventNameFactory = (app, method) => `${app}:${method}`;
|
||||
export const eventNameMethod = (name) => name.split(":")[1] || null;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { atom } from "recoil";
|
||||
|
||||
export const simcardState = {
|
||||
number: atom({
|
||||
key: "simcardNumber",
|
||||
default: null,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { simcardState } from "./state";
|
||||
|
||||
export const useSimcard = () => {
|
||||
const number = useRecoilValue(simcardState.number);
|
||||
return { number };
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useNuiEvent } from "../../nui-events/hooks/useNuiEvent";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { simcardState } from "./state";
|
||||
|
||||
export const useSimcardService = () => {
|
||||
const setNumber = useSetRecoilState(simcardState.number);
|
||||
useNuiEvent("simcard", "setNumber", (data) => {
|
||||
setNumber(data);
|
||||
});
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import React, { useEffect } from "react";
|
||||
import { AppIcon } from "./AppIcon";
|
||||
import { Grid, makeStyles } from "@material-ui/core";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useKeyboard } from "../../os/hooks/useKeyboard";
|
||||
import { useKeyboard } from "../../os/keyboard/hooks/useKeyboard";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
|
||||
Reference in new issue
Block a user