Оптимизация ядра, исправление гонки потоков при получении версии
This commit is contained in:
33
app/providers/DeviceProvider/useCoreDevice.ts
Normal file
33
app/providers/DeviceProvider/useCoreDevice.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useCore } from "@/app/hooks/useCore";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useCoreDevice() : {
|
||||
deviceId: string;
|
||||
deviceName: string;
|
||||
platform: string;
|
||||
} {
|
||||
const { getDeviceId, getDeviceName, getPlatform } = useCore();
|
||||
const [deviceId, setDeviceId] = useState<string>("");
|
||||
const [deviceName, setDeviceName] = useState<string>("");
|
||||
const [platform, setPlatform] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
fetchDeviceInfo();
|
||||
}, []);
|
||||
|
||||
const fetchDeviceInfo = async () => {
|
||||
const deviceId = await getDeviceId();
|
||||
const deviceName = await getDeviceName();
|
||||
const platform = await getPlatform();
|
||||
setDeviceId(deviceId);
|
||||
setDeviceName(deviceName);
|
||||
setPlatform(platform);
|
||||
console.info("Device info - ID:", deviceId, "Name:", deviceName);
|
||||
}
|
||||
|
||||
return {
|
||||
deviceId,
|
||||
deviceName,
|
||||
platform
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user