Оптимизация ядра, исправление гонки потоков при получении версии
This commit is contained in:
@@ -2,6 +2,7 @@ import { decodeWithPassword, encodeWithPassword } from "@/app/workers/crypto/cry
|
||||
import { useFileStorage } from "@/app/hooks/useFileStorage";
|
||||
import { generateRandomKey } from "@/app/utils/utils";
|
||||
import { createContext, useEffect, useState } from "react";
|
||||
import { useCore } from "@/app/hooks/useCore";
|
||||
|
||||
interface SystemProviderContextValue {
|
||||
id: string;
|
||||
@@ -21,7 +22,10 @@ export interface SystemProviderProps {
|
||||
*/
|
||||
export function SystemProvider(props: SystemProviderProps) {
|
||||
const [deviceId, setDeviceId] = useState<string>("");
|
||||
const [deviceName, setDeviceName] = useState<string>("");
|
||||
const [deviceOs, setDeviceOs] = useState<string>("");
|
||||
const {writeFile, readFile} = useFileStorage();
|
||||
const { getDeviceId, getDeviceName, getPlatform } = useCore();
|
||||
|
||||
useEffect(() => {
|
||||
fetchDeviceId();
|
||||
@@ -29,6 +33,10 @@ export function SystemProvider(props: SystemProviderProps) {
|
||||
|
||||
const fetchDeviceId = async () => {
|
||||
const device = await readFile("device");
|
||||
const name = await getDeviceName();
|
||||
const platform = await getPlatform();
|
||||
setDeviceName(name);
|
||||
setDeviceOs(platform);
|
||||
if(device){
|
||||
const decoded = await decodeDevice(Buffer.from(device).toString('utf-8'));
|
||||
if(decoded){
|
||||
@@ -47,12 +55,11 @@ export function SystemProvider(props: SystemProviderProps) {
|
||||
}
|
||||
|
||||
const decodeDevice = async (data: string) => {
|
||||
const hwid = window.deviceId;
|
||||
const platform = window.deviceName;
|
||||
const hwid = await getDeviceId();
|
||||
const deviceName = await getDeviceName();
|
||||
const salt = "rosetta-device-salt";
|
||||
|
||||
try {
|
||||
const decoded = await decodeWithPassword(hwid + platform + salt, data);
|
||||
const decoded = await decodeWithPassword(hwid + deviceName + salt, data);
|
||||
return decoded;
|
||||
} catch (e) {
|
||||
console.error("Failed to decode device data:", e);
|
||||
@@ -61,29 +68,24 @@ export function SystemProvider(props: SystemProviderProps) {
|
||||
}
|
||||
|
||||
const encodeDevice = async (data: string) => {
|
||||
const hwid = window.deviceId;
|
||||
const platform = window.deviceName;
|
||||
const hwid = await getDeviceId();
|
||||
const deviceName = await getDeviceName();
|
||||
const salt = "rosetta-device-salt";
|
||||
|
||||
try {
|
||||
const encoded = await encodeWithPassword(hwid + platform + salt, data);
|
||||
const encoded = await encodeWithPassword(hwid + deviceName + salt, data);
|
||||
return encoded;
|
||||
} catch (e) {
|
||||
console.error("Failed to encode device data:", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const systemName = window.deviceName || "Unknown Device";
|
||||
const systemOs = window.platform || "Unknown OS";
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<SystemProviderContext.Provider value={{
|
||||
id: deviceId,
|
||||
name: systemName,
|
||||
os: systemOs
|
||||
name: deviceName || "Unknown Device",
|
||||
os: deviceOs || "Unknown OS"
|
||||
}}>
|
||||
{props.children}
|
||||
</SystemProviderContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user