From 2345556161ca2b225f15971007fca8f48212d581 Mon Sep 17 00:00:00 2001 From: NoPlagiarism <37241775+NoPlagiarism@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:56:04 +0500 Subject: [PATCH 1/4] fix: disks stats for windows --- src-tauri/src/main.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0b3e98a..6d1968f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -5,12 +5,13 @@ use sysinfo::{ ProcessStatus, NetworksExt, NetworkExt, - DiskExt, + Disk, SystemExt, CpuExt, ProcessExt, PidExt, }; +use std::slice::Iter; use tauri::State; use std::sync::Mutex; use std::collections::HashMap; @@ -75,6 +76,20 @@ pub struct SystemStats { pub disk_free_bytes: u64, } +// Assume MacOS or Linux +#[cfg(not(target_os = "windows"))] +fn filter_disks(disks: &[Disk]) -> Iter { + disks.iter().filter(|disk| { + // Filter for physical disks - typically those mounted at "/" + disk.mount_point() == std::path::Path::new("/") + }) +} + +#[cfg(target_os = "windows")] +fn filter_disks(disks: &[Disk]) -> Iter { + disks.iter() +} + #[tauri::command] async fn get_processes(state: State<'_, AppState>) -> Result<(Vec, SystemStats), String> { let processes_data; @@ -121,12 +136,8 @@ async fn get_processes(state: State<'_, AppState>) -> Result<(Vec, *last_update = (current_time, current_rx, current_tx); - // Calculate total disk usage - only for physical disks - let disk_stats = sys.disks().iter() - .filter(|disk| { - // Filter for physical disks - typically those mounted at "/" - disk.mount_point() == std::path::Path::new("/") - }) + // Calculate total disk usage + let disk_stats = filter_disks(& sys.disks()) .fold((0, 0, 0), |acc, disk| { ( acc.0 + disk.total_space(), From 4ef8320b0c2e4e6cf0c3668f05323edea916786c Mon Sep 17 00:00:00 2001 From: NoPlagiarism <37241775+NoPlagiarism@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:40:06 +0500 Subject: [PATCH 2/4] fix: re-add DiskExt --- src-tauri/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6d1968f..98a364e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -6,6 +6,7 @@ use sysinfo::{ NetworksExt, NetworkExt, Disk, + DiskExt, SystemExt, CpuExt, ProcessExt, From 250eb37fb611c20457746f2ac3e7dc7f50ba8920 Mon Sep 17 00:00:00 2001 From: Abdenasser Date: Sat, 9 Nov 2024 12:35:50 +0100 Subject: [PATCH 3/4] fix mistmach return types --- src-tauri/src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 98a364e..0486dfa 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -12,7 +12,6 @@ use sysinfo::{ ProcessExt, PidExt, }; -use std::slice::Iter; use tauri::State; use std::sync::Mutex; use std::collections::HashMap; @@ -79,16 +78,17 @@ pub struct SystemStats { // Assume MacOS or Linux #[cfg(not(target_os = "windows"))] -fn filter_disks(disks: &[Disk]) -> Iter { +fn filter_disks(disks: &[Disk]) -> Vec<&sysinfo::Disk> { disks.iter().filter(|disk| { // Filter for physical disks - typically those mounted at "/" disk.mount_point() == std::path::Path::new("/") }) + .collect() } #[cfg(target_os = "windows")] -fn filter_disks(disks: &[Disk]) -> Iter { - disks.iter() +fn filter_disks(disks: &[Disk]) -> Vec<&sysinfo::Disk> { + disks.iter().collect() } #[tauri::command] @@ -138,7 +138,8 @@ async fn get_processes(state: State<'_, AppState>) -> Result<(Vec, *last_update = (current_time, current_rx, current_tx); // Calculate total disk usage - let disk_stats = filter_disks(& sys.disks()) + let disk_stats = filter_disks(&sys.disks()) + .iter() .fold((0, 0, 0), |acc, disk| { ( acc.0 + disk.total_space(), From a4f2a5e4a9d08ac2c2d8d964283f91d97b02217d Mon Sep 17 00:00:00 2001 From: Abdenasser Date: Sat, 9 Nov 2024 12:36:26 +0100 Subject: [PATCH 4/4] fix default theme selection --- src/lib/stores/index.ts | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index 35b2a40..4a21e08 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -2,35 +2,49 @@ import { writable } from 'svelte/store'; import { themes, type Theme } from '$lib/styles'; function createThemeStore() { - // Get initial theme from localStorage or default to catppuccin - const storedTheme = typeof window !== 'undefined' - ? localStorage.getItem('theme') - : 'catppuccin'; - - const { subscribe, set } = writable(themes[storedTheme || 'catppuccin']); + // Default theme + const defaultTheme = themes.catppuccin; + + // Initialize with default theme + const { subscribe, set } = writable(defaultTheme); + + // Initialize theme on client-side only + if (typeof window !== 'undefined') { + const storedTheme = localStorage.getItem('theme'); + if (storedTheme && themes[storedTheme]) { + set(themes[storedTheme]); + } + } return { subscribe, setTheme: (themeName: string) => { const theme = themes[themeName]; if (theme) { - localStorage.setItem('theme', themeName); + if (typeof window !== 'undefined') { + localStorage.setItem('theme', themeName); + } set(theme); applyTheme(theme); } }, init: () => { - const theme = themes[storedTheme || 'catppuccin']; + const storedTheme = typeof window !== 'undefined' + ? localStorage.getItem('theme') + : null; + const theme = (storedTheme && themes[storedTheme]) || defaultTheme; applyTheme(theme); } }; } function applyTheme(theme: Theme) { - const root = document.documentElement; - Object.entries(theme.colors).forEach(([key, value]) => { - root.style.setProperty(`--${key}`, value); - }); + if (typeof window !== 'undefined') { + const root = document.documentElement; + Object.entries(theme.colors).forEach(([key, value]) => { + root.style.setProperty(`--${key}`, value); + }); + } } export const themeStore = createThemeStore();