The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(install): download size, rate and ETA next to the rebuild spinner
David4eadfeaa913c
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rsindex 7b8e8aea..1ba02c0a 100644--- a/src-tauri/src/commands/install.rs+++ b/src-tauri/src/commands/install.rs@@ -2,7 +2,7 @@ use std::fs;use std::io::{BufRead, BufReader, Read as IoRead};use std::path::{Path, PathBuf};use std::process::{Command, Stdio};-use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};use std::sync::{Arc, Mutex};use std::time::Instant;@@ -425,6 +425,15 @@ pub fn pip_install_streaming_with_retry_cancellable(delay_seconds = (delay_seconds * 3).min(180);}+ // Fresh download stats per pip run; a retry must not double the+ // announced total by counting the same wheels twice.+ if let Ok(mut s) = install_state.lock() {+ s.download_progress = 0;+ s.download_total = 0;+ s.download_speed = 0.0;+ }+ let announced_total = Arc::new(AtomicU64::new(0));+let mut cmd = Command::new(python_bin);cmd.args(args).stdout(Stdio::piped())@@ -443,12 +452,16 @@ pub fn pip_install_streaming_with_retry_cancellable(// Stream stdout to install logslet stdout_state = install_state.clone();+ let announced = announced_total.clone();let stdout_handle = std::thread::spawn(move || {if let Some(out) = stdout {let reader = BufReader::new(out);for line in reader.lines().map_while(Result::ok) {let trimmed = line.trim();if !trimmed.is_empty() {+ if let Some(bytes) = parse_pip_download_size(trimmed) {+ announced.fetch_add(bytes, Ordering::Relaxed);+ }if let Ok(mut s) = stdout_state.lock() {s.logs.push(trimmed.to_string());}@@ -480,6 +493,12 @@ pub fn pip_install_streaming_with_retry_cancellable(// Poll for either the child to exit or the cancel flag to flip.// try_wait avoids blocking the cancel check; sleep keeps CPU idle.+ // Once a second the child's cumulative read bytes turn the announced+ // wheel sizes into progress and speed for the install status, which+ // the UI renders next to the rebuild spinner.+ let pid = child.id();+ let mut io_baseline: Option<(u64, Instant)> = None;+ let mut tick: u32 = 0;let exit_status = loop {if cancel.as_ref().map(|c| c.load(Ordering::SeqCst)).unwrap_or(false) {// Kill the child so pip doesn't keep saturating disk.@@ -491,13 +510,43 @@ pub fn pip_install_streaming_with_retry_cancellable(}match child.try_wait() {Ok(Some(s)) => break s,- Ok(None) => std::thread::sleep(std::time::Duration::from_millis(200)),+ Ok(None) => {+ tick += 1;+ if tick % 5 == 0 {+ let total = announced_total.load(Ordering::Relaxed);+ if total > 0 {+ if let Some(read) = process_read_bytes(pid) {+ let (base, since) =+ *io_baseline.get_or_insert((read, Instant::now()));+ let progress = read.saturating_sub(base).min(total);+ let elapsed = since.elapsed().as_secs_f64();+ let speed =+ if elapsed > 0.5 { progress as f64 / elapsed } else { 0.0 };+ if let Ok(mut s) = install_state.lock() {+ s.download_progress = progress;+ s.download_total = total;+ s.download_speed = speed;+ }+ }+ }+ }+ std::thread::sleep(std::time::Duration::from_millis(200));+ }Err(e) => return Err(format!("pip wait failed: {}", e)),}};let _ = stdout_handle.join();let _ = stderr_handle.join();+ // The run is over either way; a frozen speed would read as a live+ // download next to a finished or failed step.+ if let Ok(mut s) = install_state.lock() {+ if exit_status.success() && s.download_total > 0 {+ s.download_progress = s.download_total;+ }+ s.download_speed = 0.0;+ }+if exit_status.success() {return Ok(());}@@ -539,6 +588,77 @@ pub(crate) fn pytorch_pip_args(index_url: Option<&str>) -> Vec<String> {args}+/// Bytes a pip "Downloading <thing> (<size>)" stdout line announces. pip+/// prints decimal units, kB means 1000 bytes. "Using cached" lines are not+/// network traffic and must not count.+pub(crate) fn parse_pip_download_size(line: &str) -> Option<u64> {+ let rest = line.trim().strip_prefix("Downloading ")?;+ let inner = rest[rest.rfind('(')? + 1..].strip_suffix(')')?;+ let mut parts = inner.split_whitespace();+ let num: f64 = parts.next()?.parse().ok()?;+ let unit = parts.next()?;+ if parts.next().is_some() {+ return None;+ }+ let factor = match unit {+ "bytes" | "B" => 1.0,+ "kB" => 1e3,+ "MB" => 1e6,+ "GB" => 1e9,+ _ => return None,+ };+ Some((num * factor).round() as u64)+}++/// Cumulative bytes the process has read from files and sockets. pip+/// downloads in-process, so this is the live counter behind the progress+/// display next to the rebuild spinner. None where the platform has no+/// cheap probe and on any probe error; the caller then keeps the plain+/// spinner instead of guessing.+#[cfg(target_os = "windows")]+pub(crate) fn process_read_bytes(pid: u32) -> Option<u64> {+ #[repr(C)]+ struct IoCounters {+ read_ops: u64,+ write_ops: u64,+ other_ops: u64,+ read_bytes: u64,+ write_bytes: u64,+ other_bytes: u64,+ }+ #[link(name = "kernel32")]+ extern "system" {+ fn OpenProcess(access: u32, inherit: i32, pid: u32) -> isize;+ fn GetProcessIoCounters(handle: isize, counters: *mut IoCounters) -> i32;+ fn CloseHandle(handle: isize) -> i32;+ }+ const PROCESS_QUERY_INFORMATION: u32 = 0x0400;+ unsafe {+ let handle = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);+ if handle == 0 {+ return None;+ }+ let mut counters = std::mem::zeroed::<IoCounters>();+ let ok = GetProcessIoCounters(handle, &mut counters);+ CloseHandle(handle);+ (ok != 0).then_some(counters.read_bytes)+ }+}++#[cfg(target_os = "linux")]+pub(crate) fn process_read_bytes(pid: u32) -> Option<u64> {+ std::fs::read_to_string(format!("/proc/{}/io", pid))+ .ok()?+ .lines()+ .find_map(|l| l.strip_prefix("rchar:"))+ .and_then(|v| v.trim().parse().ok())+}++#[cfg(not(any(target_os = "windows", target_os = "linux")))]+pub(crate) fn process_read_bytes(_pid: u32) -> Option<u64> {+ None+}+/// GPU probe + wheel choice + pip args, shared between the first install and/// `repair_comfyui_env` so the two can never drift apart (same cu128/cu121//// CPU decision, same flags).@@ -3463,6 +3583,47 @@ fn is_permission_denied_pip_error(output: &str) -> bool {mod tests {use super::*;+ // ── Download-Anzeige am Rebuilding-Spinner (#162) ───────────────────++ #[test]+ fn pip_download_size_parses_decimal_units() {+ assert_eq!(+ parse_pip_download_size(+ "Downloading torch-2.5.1+cu121-cp311-cp311-win_amd64.whl (2445.5 MB)"+ ),+ Some(2_445_500_000)+ );+ assert_eq!(+ parse_pip_download_size(+ "Downloading https://download.pytorch.org/whl/jinja2-3.1.6-py3-none-any.whl (134 kB)"+ ),+ Some(134_000)+ );+ assert_eq!(+ parse_pip_download_size("Downloading foo-1.0.tar.gz (1.2 GB)"),+ Some(1_200_000_000)+ );+ assert_eq!(+ parse_pip_download_size("Downloading mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)"),+ Some(1_600)+ );+ }++ #[test]+ fn pip_download_size_ignores_lines_that_are_no_download() {+ // Negative controls: cache hits and chatter must not inflate the total.+ assert_eq!(+ parse_pip_download_size("Using cached torch-2.5.1-cp311-win_amd64.whl (2445.5 MB)"),+ None+ );+ assert_eq!(parse_pip_download_size("Installing collected packages: torch"), None);+ assert_eq!(parse_pip_download_size("Downloading build artifacts"), None);+ assert_eq!(+ parse_pip_download_size("Collecting torch (from -r requirements.txt (line 10))"),+ None+ );+ }+// ── PyTorch-Args, geteilt zwischen Install und Repair (GH #98) ──────#[test]diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex a4474214..2e465648 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -10,6 +10,7 @@ import { PersonaPanel } from '../personas/PersonaPanel'import { AccountPanel } from '../auth/AccountPanel'import { useVoiceStore } from '../../stores/voiceStore'import { checkWhisperAvailable, checkTtsAvailable, downloadPiperVoice, listInstalledPiperVoices } from '../../api/voice'+import { downloadSuffix } from '../../lib/formatters'// Curated local neural (Piper) voices the user can pick. Selecting one not yet// on disk downloads it (~63 MB). Ids match rhasspy/piper-voices.@@ -321,6 +322,8 @@ function ComfyUISettings() {const [installPhase, setInstallPhase] = useState<'idle' | 'python' | 'comfyui' | 'repair' | 'error'>('idle')const [installLogs, setInstallLogs] = useState<string[]>([])const [installErr, setInstallErr] = useState('')+ // #162: size, rate and remaining time in the bracket next to the spinner.+ const [installDl, setInstallDl] = useState({ progress: 0, total: 0, speed: 0 })useEffect(() => {let cancelled = false@@ -375,6 +378,7 @@ function ComfyUISettings() {setStartError('')setInstallPhase('repair')setInstallLogs(['Repairing the ComfyUI environment…'])+ setInstallDl({ progress: 0, total: 0, speed: 0 })try {const { backendCall } = await import('../../api/backend')await backendCall('repair_comfyui_env')@@ -382,6 +386,7 @@ function ComfyUISettings() {try {const data: any = await backendCall('install_comfyui_status')setInstallLogs(data.logs || [])+ setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })if (data.status === 'complete') {clearInterval(poll)setInstallPhase('idle')@@ -640,6 +645,7 @@ function ComfyUISettings() {try {const data: any = await backendCall('install_comfyui_status')setInstallLogs(data.logs || [])+ setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })if (data.status === 'complete') {clearInterval(poll)setInstallPhase('idle')@@ -677,6 +683,7 @@ function ComfyUISettings() {try {const data: any = await backendCall('install_comfyui_status')setInstallLogs(data.logs || [])+ setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })if (data.status === 'complete') {clearInterval(poll)setInstallPhase('idle')@@ -709,8 +716,8 @@ function ComfyUISettings() {{installPhase !== 'error' && <Loader2 size={10} className="animate-spin" />}<span>{installPhase === 'python' && 'Installing Python 3.12 (~30 MB)…'}- {installPhase === 'comfyui' && 'Installing ComfyUI…'}- {installPhase === 'repair' && 'Rebuilding the ComfyUI environment…'}+ {installPhase === 'comfyui' && `Installing ComfyUI…${downloadSuffix(installDl)}`}+ {installPhase === 'repair' && `Rebuilding the ComfyUI environment…${downloadSuffix(installDl)}`}{installPhase === 'error' && 'Install failed'}</span></div>diff --git a/src/lib/__tests__/download-suffix.test.ts b/src/lib/__tests__/download-suffix.test.tsnew file mode 100644index 00000000..5631be65--- /dev/null+++ b/src/lib/__tests__/download-suffix.test.ts@@ -0,0 +1,39 @@+import { describe, it, expect } from 'vitest'+import { downloadSuffix, formatEta } from '../formatters'++// #162: the bracket next to "Rebuilding the ComfyUI environment…" must say+// how big the download is, how fast it runs and roughly how long is left.+describe('downloadSuffix', () => {+ it('shows size, rate and remaining time while a total is known', () => {+ const s = downloadSuffix({ progress: 1024 ** 3, total: 2 * 1024 ** 3, speed: 10 * 1024 ** 2 })+ expect(s).toBe(' (1.0 GB of 2.0 GB, 10.0 MB/s, ~2 min left)')+ })++ it('reports seconds when the rest is short', () => {+ const s = downloadSuffix({ progress: 900 * 1024 ** 2, total: 1000 * 1024 ** 2, speed: 10 * 1024 ** 2 })+ expect(s).toBe(' (900.0 MB of 1000.0 MB, 10.0 MB/s, ~10s left)')+ })++ it('drops rate and remaining time when the rate is unknown', () => {+ const s = downloadSuffix({ progress: 512 * 1024 ** 2, total: 1024 ** 3, speed: 0 })+ expect(s).toBe(' (512.0 MB of 1.0 GB)')+ })++ it('stays empty before any download is announced', () => {+ // Negative control: the plain spinner must never grow a "(0 B of 0 B)".+ expect(downloadSuffix({ progress: 0, total: 0, speed: 0 })).toBe('')+ })++ it('never shows a negative remainder when progress overshoots the total', () => {+ const s = downloadSuffix({ progress: 1100, total: 1000, speed: 100 })+ expect(s).toContain('~0s left')+ })+})++describe('formatEta', () => {+ it('scales from seconds to minutes to hours', () => {+ expect(formatEta(45)).toBe('45s')+ expect(formatEta(102.4)).toBe('2 min')+ expect(formatEta(6600)).toBe('1 h 50 min')+ })+})diff --git a/src/lib/formatters.ts b/src/lib/formatters.tsindex c9bebd9d..d93dae4c 100644--- a/src/lib/formatters.ts+++ b/src/lib/formatters.ts@@ -6,6 +6,25 @@ export function formatBytes(bytes: number): string {return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`}+export function formatEta(seconds: number): string {+ const s = Math.round(seconds)+ if (s < 60) return `${s}s`+ if (s < 3600) return `${Math.round(s / 60)} min`+ return `${Math.floor(s / 3600)} h ${Math.round((s % 3600) / 60)} min`+}++// #162: the bracket next to the Rebuilding spinner. Empty until the backend+// has announced a total, so a plain spinner never grows a "(0 B of 0 B)".+export function downloadSuffix(p: { progress: number; total: number; speed: number }): string {+ if (!p.total) return ''+ const parts = [`${formatBytes(p.progress)} of ${formatBytes(p.total)}`]+ if (p.speed > 0) {+ parts.push(`${formatBytes(p.speed)}/s`)+ parts.push(`~${formatEta(Math.max(0, p.total - p.progress) / p.speed)} left`)+ }+ return ` (${parts.join(', ')})`+}+export function formatDate(timestamp: number): string {const date = new Date(timestamp)const now = new Date()