Skip to content

Commit

Permalink
About and logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Oct 25, 2022
1 parent d036aae commit ea7ac07
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
5 changes: 2 additions & 3 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use tauri::*;

mod auto_launch;
mod encryption;
mod system_info;
mod utils;

#[derive(Clone, serde::Serialize)]
Expand Down Expand Up @@ -85,7 +84,6 @@ fn main() {
.invoke_handler(tauri::generate_handler![
auto_launch::enable_auto_launch,
auto_launch::disable_auto_launch,
system_info::system_info,
encryption::encrypt_password,
encryption::verify_password,
encryption::encrypt_data,
Expand All @@ -99,7 +97,8 @@ fn main() {
utils::update_tray,
utils::random_values,
utils::logger,
utils::write_logs
utils::write_logs,
utils::system_info,
])
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
println!("{}, {argv:?}, {cwd}", app.package_info().name);
Expand Down
15 changes: 0 additions & 15 deletions core/src/system_info.rs

This file was deleted.

17 changes: 16 additions & 1 deletion core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::{env, fs};
use std::io::Write;
use std::{env, fs};
use sysinfo::{CpuExt, System, SystemExt};
use tauri::{GlobalShortcutManager, Manager};

#[tauri::command]
Expand Down Expand Up @@ -67,3 +68,17 @@ pub fn write_logs(name: String, message: String) {

write!(file, "{}", message).unwrap();
}

#[tauri::command]
pub fn system_info() -> String {
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);

res.into()
}
11 changes: 7 additions & 4 deletions interface/layout/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { Route, router } from "tinro"
import { onMount } from "svelte"
import { state } from "../stores/state"
import { number } from "../../build.json"
import { number, version } from "../../build.json"
import logger from "interface/utils/logger"
import UpdateAlert from "../components/updateAlert.svelte"
Expand All @@ -50,16 +50,19 @@
import Edit from "../windows/edit/edit.svelte"
onMount(() => {
// Debug info
logger.log(`Authme ${version} ${number}`)
// Listen for router events
router.subscribe((data) => {
console.log("Path changed:", data)
logger.log(`Path changed: ${data.path}`)
document.querySelector(".top").scrollIntoView()
})
// Listen for errors
window.addEventListener("unhandledrejection", (error: any) => {
logger.error(`Unknown runtime error occurred: ${error.reason} \nStack: ${error.target.location.href}`)
window.addEventListener("unhandledrejection", (error) => {
logger.error(`Unknown runtime error occurred: ${error.reason}`)
})
})
</script>
15 changes: 7 additions & 8 deletions interface/windows/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ import { getSettings } from "interface/stores/settings"
const settings = getSettings()

export const about = async () => {
const appVersion = await app.getVersion()
const tauriVersion = await app.getTauriVersion()
const osType = await os.type()
const osArch = await os.arch()
const osVersion = await os.version()
const browser = new UAParser().getBrowser()
const osArch = (await os.arch()).replace("x86_64", "x64")

// 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[0]
const cpu = hardware[1]
.split("@")[0]
.replaceAll("(R)", "")
.replaceAll("(TM)", "")
.replace(/ +(?= )/g, "")
const memory = `${Math.round(parseInt(hardware[2]) / 1024 / 1024)}GB`
const osName = hardware[0]

const memory = `${Math.round(parseInt(hardware[1]) / 1024 / 1024)}GB`

dialog.message(`Authme: ${appVersion} \n\nTauri: ${tauriVersion}\n${browserName}: ${browserVersion}\n\nOS version: ${osType} ${osArch.replace("x86_64", "x64")} ${osVersion}\nHardware info: ${cpu}${memory} RAM\n\nRelease date: ${build.date}\nBuild number: ${build.number}\n\nCreated by: Lőrik Levente`)
dialog.message(`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`)
}

export const clearData = async () => {
Expand Down

0 comments on commit ea7ac07

Please sign in to comment.