Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disks stats for windows #57

Merged
merged 9 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use sysinfo::{
ProcessStatus,
NetworksExt,
NetworkExt,
Disk,
DiskExt,
SystemExt,
CpuExt,
Expand Down Expand Up @@ -75,6 +76,21 @@ pub struct SystemStats {
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]
async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>, SystemStats), String> {
let processes_data;
Expand Down Expand Up @@ -121,12 +137,9 @@ async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>,

*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())
.iter()
.fold((0, 0, 0), |acc, disk| {
(
acc.0 + disk.total_space(),
Expand Down
38 changes: 26 additions & 12 deletions src/lib/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Theme>(themes[storedTheme || 'catppuccin']);
// Default theme
const defaultTheme = themes.catppuccin;

// Initialize with default theme
const { subscribe, set } = writable<Theme>(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();
Loading