Skip to content

Commit

Permalink
Refactor system info
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 5, 2023
1 parent dcfea73 commit 6a34ca8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
28 changes: 22 additions & 6 deletions core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
}
Expand Down
19 changes: 13 additions & 6 deletions interface/windows/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down

0 comments on commit 6a34ca8

Please sign in to comment.