Merge pull request #57 from NoPlagiarism/fix/windows_disks

fix: disks stats for windows
This commit is contained in:
Abdenasser Elidrissi 2024-11-09 13:03:00 +01:00 committed by GitHub
commit adb99e9ce1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 18 deletions

View File

@ -5,6 +5,7 @@ use sysinfo::{
ProcessStatus, ProcessStatus,
NetworksExt, NetworksExt,
NetworkExt, NetworkExt,
Disk,
DiskExt, DiskExt,
SystemExt, SystemExt,
CpuExt, CpuExt,
@ -75,6 +76,21 @@ pub struct SystemStats {
pub disk_free_bytes: u64, pub disk_free_bytes: u64,
} }
// Assume MacOS or Linux
#[cfg(not(target_os = "windows"))]
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]) -> Vec<&sysinfo::Disk> {
disks.iter().collect()
}
#[tauri::command] #[tauri::command]
async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>, SystemStats), String> { async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>, SystemStats), String> {
let processes_data; let processes_data;
@ -121,12 +137,9 @@ async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>,
*last_update = (current_time, current_rx, current_tx); *last_update = (current_time, current_rx, current_tx);
// Calculate total disk usage - only for physical disks // Calculate total disk usage
let disk_stats = sys.disks().iter() let disk_stats = filter_disks(&sys.disks())
.filter(|disk| { .iter()
// Filter for physical disks - typically those mounted at "/"
disk.mount_point() == std::path::Path::new("/")
})
.fold((0, 0, 0), |acc, disk| { .fold((0, 0, 0), |acc, disk| {
( (
acc.0 + disk.total_space(), acc.0 + disk.total_space(),

View File

@ -2,35 +2,49 @@ import { writable } from 'svelte/store';
import { themes, type Theme } from '$lib/styles'; import { themes, type Theme } from '$lib/styles';
function createThemeStore() { function createThemeStore() {
// Get initial theme from localStorage or default to catppuccin // Default theme
const storedTheme = typeof window !== 'undefined' const defaultTheme = themes.catppuccin;
? localStorage.getItem('theme')
: 'catppuccin'; // Initialize with default theme
const { subscribe, set } = writable<Theme>(defaultTheme);
const { subscribe, set } = writable<Theme>(themes[storedTheme || 'catppuccin']);
// Initialize theme on client-side only
if (typeof window !== 'undefined') {
const storedTheme = localStorage.getItem('theme');
if (storedTheme && themes[storedTheme]) {
set(themes[storedTheme]);
}
}
return { return {
subscribe, subscribe,
setTheme: (themeName: string) => { setTheme: (themeName: string) => {
const theme = themes[themeName]; const theme = themes[themeName];
if (theme) { if (theme) {
localStorage.setItem('theme', themeName); if (typeof window !== 'undefined') {
localStorage.setItem('theme', themeName);
}
set(theme); set(theme);
applyTheme(theme); applyTheme(theme);
} }
}, },
init: () => { init: () => {
const theme = themes[storedTheme || 'catppuccin']; const storedTheme = typeof window !== 'undefined'
? localStorage.getItem('theme')
: null;
const theme = (storedTheme && themes[storedTheme]) || defaultTheme;
applyTheme(theme); applyTheme(theme);
} }
}; };
} }
function applyTheme(theme: Theme) { function applyTheme(theme: Theme) {
const root = document.documentElement; if (typeof window !== 'undefined') {
Object.entries(theme.colors).forEach(([key, value]) => { const root = document.documentElement;
root.style.setProperty(`--${key}`, value); Object.entries(theme.colors).forEach(([key, value]) => {
}); root.style.setProperty(`--${key}`, value);
});
}
} }
export const themeStore = createThemeStore(); export const themeStore = createThemeStore();