diff --git a/core/src/utils.rs b/core/src/utils.rs index 0e48410f..b272e11c 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -1,6 +1,7 @@ use google_authenticator_converter::{process_data, Account}; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; +use serde::{Deserialize, Serialize}; use std::io::Write; use std::{env, fs}; use sysinfo::{CpuExt, System, SystemExt}; @@ -70,16 +71,31 @@ pub fn write_logs(name: String, message: String) { write!(file, "{}", message).unwrap(); } +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SystemInfo { + pub os_name: String, + pub os_arch: String, + pub cpu_name: String, + pub total_mem: u64, +} + #[tauri::command] -pub fn system_info() -> String { +pub fn system_info() -> SystemInfo { let mut sys = System::new_all(); sys.refresh_all(); - let name = sys.name().unwrap(); - let cpu = sys.cpus()[0].brand(); - let mem = sys.total_memory(); - - let res = format!("{}+{}+{}", name, cpu, mem); + let os_name = sys.name().unwrap(); + let cpu_name = sys.cpus()[0].brand().to_string(); + let total_mem = sys.total_memory(); + let os_arch = env::consts::ARCH.to_string(); + + let res = SystemInfo { + os_name, + cpu_name, + total_mem, + os_arch, + }; res.into() } diff --git a/interface/windows/settings/index.ts b/interface/windows/settings/index.ts index f67eb396..fa1ba907 100644 --- a/interface/windows/settings/index.ts +++ b/interface/windows/settings/index.ts @@ -7,26 +7,33 @@ import { getSettings } from "interface/stores/settings" const settings = getSettings() +interface SystemInfo { + osName: string + osArch: string + cpuName: string + totalMem: number +} + export const about = async () => { const tauriVersion = await app.getTauriVersion() const osVersion = await os.version() const browser = new UAParser().getBrowser() - const osArch = (await os.arch()).replace("x86_64", "x64").replace("aarch64", "arm64") // Browser version const browserName = browser.name.replace("Edge", "Chromium").replace("Safari", "WebKit") const browserVersion = browser.version // System info - const systemInfo: string = await invoke("system_info") - const hardware = systemInfo.split("+") - const cpu = hardware[1] + const systemInfo: SystemInfo = await invoke("system_info") + + const cpu = systemInfo.cpuName .split("@")[0] .replaceAll("(R)", "") .replaceAll("(TM)", "") .replace(/ +(?= )/g, "") - const memory = `${Math.round(parseInt(hardware[2]) / 1024 / 1024 / 1024)} GB` - const osName = hardware[0] + const memory = `${Math.round(systemInfo.totalMem / 1024 / 1024 / 1024)} GB` + const osName = systemInfo.osName + const osArch = systemInfo.osArch.replace("x86_64", "x64").replace("aarch64", "arm64") const info = `Authme: ${build.version} \n\nTauri: ${tauriVersion}\n${browserName}: ${browserVersion}\n\nOS version: ${osName} ${osArch} ${osVersion}\nHardware info: ${cpu} ${memory} RAM\n\nRelease date: ${build.date}\nBuild number: ${build.number}\n\nCreated by: LÅ‘rik Levente`