Squid 0.1.10:升级安装包清理、CPU 面板、回收站文案与桌面小工具降占用
- 清理新增「升级安装包」分类:已知应用精确规则(微信/企微/WPS/网易邮箱等)+ AppData 启发式扫描;只匹配安装包形态、≥7 天、1MiB 起,运行中应用锁定;删除确认弹条「跳过升级包,只删其余」 - 桌面小工具新增 CPU 面板:总占用曲线 + 整行逻辑核心渐变柱(绿→黄→橙→红连续插值,悬停显示核心 N 百分比,0 起编号,柱宽随核心数自适应) - Windows 上「废纸篓」文案全链路改为「回收站」(bootstrap.binNoun 驱动,macOS 不变) - 常驻 CPU 优化:轻/全两档采样(system_snapshot(full))、双窗口共享 2s 采样缓存、主窗口收托盘与小工具折叠时完全停止轮询 - 修复小工具自适应尺寸→重锚定 IPC 死循环(主进程+渲染进程空转、每循环写一次 widget.json);同时修复由此摘除 prefs 依赖引入的面板高度不自适应回归 - 版本升至 0.1.10(4 处同步),release/0.1.10 全套发布文件(安装包/便携包/SHA256/更新清单/一键安装.bat)dev
parent
67a68b4fbb
commit
a3253ad38f
|
|
@ -1047,7 +1047,7 @@ checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b"
|
|||
|
||||
[[package]]
|
||||
name = "squid-cli"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -1066,7 +1066,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-core"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -1085,7 +1085,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-engine"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -1105,7 +1105,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-platform"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"libc",
|
||||
|
|
@ -1123,7 +1123,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-rules"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"globset",
|
||||
"serde",
|
||||
|
|
@ -1135,7 +1135,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-stats"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"libc",
|
||||
|
|
@ -1148,7 +1148,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-tui"
|
||||
version = "0.1.7"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ members = ["crates/*"]
|
|||
exclude = ["src-tauri"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
edition = "2021"
|
||||
rust-version = "1.80"
|
||||
license = "GPL-3.0-only"
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ pub enum Category {
|
|||
Trash,
|
||||
LanguagePacks,
|
||||
Leftovers,
|
||||
UpdateInstallers,
|
||||
}
|
||||
|
||||
impl Category {
|
||||
pub const ALL: [Category; 9] = [
|
||||
pub const ALL: [Category; 10] = [
|
||||
Category::SystemJunk,
|
||||
Category::AppCaches,
|
||||
Category::BrowserCaches,
|
||||
|
|
@ -32,6 +33,7 @@ impl Category {
|
|||
Category::Trash,
|
||||
Category::LanguagePacks,
|
||||
Category::Leftovers,
|
||||
Category::UpdateInstallers,
|
||||
];
|
||||
|
||||
pub fn id(self) -> &'static str {
|
||||
|
|
@ -45,6 +47,7 @@ impl Category {
|
|||
Category::Trash => "trash",
|
||||
Category::LanguagePacks => "languages",
|
||||
Category::Leftovers => "leftovers",
|
||||
Category::UpdateInstallers => "update-installers",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +62,7 @@ impl Category {
|
|||
Category::Trash => "Trash",
|
||||
Category::LanguagePacks => "Unneeded Languages",
|
||||
Category::Leftovers => "Uninstaller Leftovers",
|
||||
Category::UpdateInstallers => "Update Installers",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +80,7 @@ impl Category {
|
|||
Category::Trash => "Files waiting in the Trash",
|
||||
Category::LanguagePacks => "Speech and localization data for languages you do not use",
|
||||
Category::Leftovers => "Data belonging to apps that are no longer installed",
|
||||
Category::UpdateInstallers => "Installer packages apps keep after a successful update",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +106,9 @@ impl Category {
|
|||
"trash" => Category::Trash,
|
||||
"language" | "languages" | "language-packs" | "localization" => Category::LanguagePacks,
|
||||
"leftover" | "leftovers" | "uninstall-leftovers" => Category::Leftovers,
|
||||
"update-installer" | "update-installers" | "upgrades" | "upgrade-packages" => {
|
||||
Category::UpdateInstallers
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
Some(alias)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,9 @@ pub fn scan(
|
|||
cancel: &CancelToken,
|
||||
) -> squid_core::Result<ScanReport> {
|
||||
let prepared = prepared_rules(engine, options);
|
||||
if prepared.is_empty() {
|
||||
let updates_wanted =
|
||||
options.categories.is_empty() || options.categories.contains(&Category::UpdateInstallers);
|
||||
if prepared.is_empty() && !updates_wanted {
|
||||
return Err(SquidError::NothingToDo);
|
||||
}
|
||||
progress.phase("match", "locating cleanup candidates");
|
||||
|
|
@ -148,6 +150,28 @@ pub fn scan(
|
|||
}
|
||||
}
|
||||
|
||||
// Update installers (升级安装包): rule-driven known apps + heuristic
|
||||
// sweep of AppData staging folders. The walk is bounded, so it is always
|
||||
// on unless the caller filtered categories down to something else.
|
||||
let updates_wanted =
|
||||
options.categories.is_empty() || options.categories.contains(&Category::UpdateInstallers);
|
||||
if updates_wanted {
|
||||
progress.phase("update-installers", "collecting stale update packages");
|
||||
for item in crate::updates::collect(engine, cancel) {
|
||||
if seen.contains_key(&item.path) {
|
||||
continue;
|
||||
}
|
||||
let mut item = item;
|
||||
if engine.is_whitelisted(&item.path) {
|
||||
item = item.locked(LockReason::Whitelisted);
|
||||
} else if let Some(reason) = engine.block_reason(&item) {
|
||||
item = item.locked(LockReason::Protected).with_note(reason);
|
||||
}
|
||||
seen.insert(item.path.clone(), report.items.len());
|
||||
report.items.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
if !options.fast {
|
||||
measure(engine, &mut report, progress, cancel)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub mod clean;
|
|||
pub mod delete;
|
||||
pub mod purge;
|
||||
pub mod uninstall;
|
||||
pub mod updates;
|
||||
|
||||
use globset::GlobMatcher;
|
||||
use squid_core::settings::Settings;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,324 @@
|
|||
//! Update-installers collector (升级安装包): A+B combined.
|
||||
//!
|
||||
//! Layer A is a table of known apps whose update drop folders never
|
||||
//! self-clean (WeChat, WXWork, WPS, …) — precise paths plus the process
|
||||
//! that must not be running while we sweep. Layer B is a heuristic sweep
|
||||
//! of one level under each AppData root, descending into directories
|
||||
//! *named* like update staging areas (update/upgrade/setup/patch/…) so
|
||||
//! unknown apps are still caught. Layer A results are also fed back into
|
||||
//! B's seen-set, so one folder is never offered twice.
|
||||
//!
|
||||
//! Both layers only ever propose individual **installer-shaped files**
|
||||
//! (`.exe .msi .msp .zip .7z .rar .cab .crx .nupkg .appx .patch`, ≥ 1 MiB,
|
||||
//! untouched for ≥ 7 days). Runtime components that apps keep next to
|
||||
//! those packages (`.bin`, `.dll`, version folders) are deliberately never
|
||||
//! matched: WeChat's `update\RadiumWMPF.bin` is the *current* version, not
|
||||
//! junk. Per-file items reuse the plain File deletion + undo path.
|
||||
|
||||
use squid_core::{Category, CleanupItem, ItemKind, LockReason};
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// 7 天:用户确认的阈值。升级后一周内没人再碰的包,应用自己也不会再用了。
|
||||
pub const MIN_AGE_DAYS: u64 = 7;
|
||||
/// 1 MiB:小碎片不值得列出来。
|
||||
pub const MIN_SIZE_BYTES: u64 = 1024 * 1024;
|
||||
|
||||
const INSTALLER_EXTENSIONS: [&str; 11] = [
|
||||
"exe", "msi", "msp", "zip", "7z", "rar", "cab", "crx", "nupkg", "appx", "patch",
|
||||
];
|
||||
|
||||
/// Directory names that mark an update staging area (layer B).
|
||||
const UPDATE_DIR_NAMES: [&str; 9] = [
|
||||
"update",
|
||||
"updates",
|
||||
"upgrade",
|
||||
"upgrades",
|
||||
"setup",
|
||||
"installer",
|
||||
"installers",
|
||||
"patch",
|
||||
"patches",
|
||||
];
|
||||
|
||||
/// Vendor folders layer B must not sweep. WinGet's package cache belongs to
|
||||
/// the developer category; Tencent/kingsoft/Netease are covered precisely by
|
||||
/// layer A (the heuristic would only double-report the same bytes).
|
||||
const SKIP_VENDORS: [&str; 4] = ["Microsoft", "winget", "Tencent", "kingsoft"];
|
||||
|
||||
/// Layer A: known apps → (directory relative to the AppData roots, display
|
||||
/// label, process that locks the group while running).
|
||||
struct KnownApp {
|
||||
dir: &'static str,
|
||||
label: &'static str,
|
||||
process: &'static str,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
const KNOWN_APPS: &[KnownApp] = &[
|
||||
KnownApp {
|
||||
dir: r"Tencent\xwechat\update",
|
||||
label: "微信",
|
||||
process: "weixin.exe",
|
||||
},
|
||||
KnownApp {
|
||||
dir: r"Tencent\WXWork\patch",
|
||||
label: "企业微信",
|
||||
process: "wxwork.exe",
|
||||
},
|
||||
KnownApp {
|
||||
dir: r"kingsoft\office6\update",
|
||||
label: "WPS Office",
|
||||
process: "wps.exe",
|
||||
},
|
||||
KnownApp {
|
||||
dir: r"kingsoft\WPS Cloud Files\update",
|
||||
label: "WPS 云文档",
|
||||
process: "wpscloudsvr.exe",
|
||||
},
|
||||
KnownApp {
|
||||
dir: r"Netease\MailMaster\Update",
|
||||
label: "网易邮箱大师",
|
||||
process: "mailmaster.exe",
|
||||
},
|
||||
];
|
||||
|
||||
/// macOS layer A: Squirrel's update payload folders (`*.nupkg`, full
|
||||
/// machines) under AppData-style roots.
|
||||
#[cfg(not(windows))]
|
||||
const KNOWN_APPS: &[KnownApp] = &[KnownApp {
|
||||
dir: "SquirrelTemp",
|
||||
label: "Squirrel 更新包",
|
||||
process: "",
|
||||
}];
|
||||
|
||||
#[cfg(windows)]
|
||||
fn appdata_roots() -> Vec<PathBuf> {
|
||||
let mut roots = Vec::new();
|
||||
if let Some(local) = std::env::var_os("LOCALAPPDATA") {
|
||||
roots.push(PathBuf::from(local));
|
||||
}
|
||||
if let Some(roaming) = std::env::var_os("APPDATA") {
|
||||
roots.push(PathBuf::from(roaming));
|
||||
}
|
||||
roots
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn appdata_roots() -> Vec<PathBuf> {
|
||||
let home = squid_core::paths::home_dir();
|
||||
vec![
|
||||
home.join("Library/Caches"),
|
||||
home.join("Library/Application Support"),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn is_installer(file: &Path) -> bool {
|
||||
let Some(ext) = file.extension().and_then(|ext| ext.to_str()) else {
|
||||
return false;
|
||||
};
|
||||
INSTALLER_EXTENSIONS
|
||||
.iter()
|
||||
.any(|wanted| ext.eq_ignore_ascii_case(wanted))
|
||||
}
|
||||
|
||||
fn stale_enough(meta: &std::fs::Metadata) -> bool {
|
||||
if meta.len() < MIN_SIZE_BYTES {
|
||||
return false;
|
||||
}
|
||||
let modified = meta
|
||||
.modified()
|
||||
.or_else(|_| meta.created())
|
||||
.unwrap_or(std::time::SystemTime::UNIX_EPOCH);
|
||||
modified
|
||||
.elapsed()
|
||||
.map(|age| age.as_secs() >= MIN_AGE_DAYS * 86_400)
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Depth-capped sweep of one staging directory: every stale installer file
|
||||
/// becomes its own item (File kind → plain delete + undo path).
|
||||
fn sweep(
|
||||
dir: &Path,
|
||||
label: &str,
|
||||
rule: &str,
|
||||
blocked: bool,
|
||||
out: &mut Vec<CleanupItem>,
|
||||
seen: &mut HashSet<PathBuf>,
|
||||
) {
|
||||
let walker = walkdir::WalkDir::new(dir)
|
||||
.max_depth(3)
|
||||
.follow_links(false)
|
||||
.into_iter()
|
||||
.filter_entry(|entry| !entry.file_type().is_symlink());
|
||||
for entry in walker.flatten() {
|
||||
if !entry.file_type().is_file() {
|
||||
continue;
|
||||
}
|
||||
let path = entry.path();
|
||||
let Ok(meta) = entry.metadata() else { continue };
|
||||
if !is_installer(path) || !stale_enough(&meta) {
|
||||
continue;
|
||||
}
|
||||
if !seen.insert(path.to_path_buf()) {
|
||||
continue;
|
||||
}
|
||||
let item = CleanupItem::new(
|
||||
path.to_path_buf(),
|
||||
ItemKind::File,
|
||||
Category::UpdateInstallers,
|
||||
format!("{label} · {}", squash_name(path)),
|
||||
)
|
||||
.with_rule(rule)
|
||||
.with_anchors(std::iter::once(dir.to_path_buf()))
|
||||
.with_note("升级完成后不再需要;需要时应用会自动重新下载");
|
||||
let item = if blocked {
|
||||
item.locked(LockReason::AppRunning)
|
||||
} else {
|
||||
item
|
||||
};
|
||||
out.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// Long hashed package names read badly in a list; keep a head+tail hint.
|
||||
fn squash_name(path: &Path) -> String {
|
||||
let name = path
|
||||
.file_name()
|
||||
.map_or_else(String::new, |n| n.to_string_lossy().into_owned());
|
||||
let chars: Vec<char> = name.chars().collect();
|
||||
if chars.len() <= 42 {
|
||||
return name;
|
||||
}
|
||||
let head: String = chars[..24].iter().collect();
|
||||
let tail: String = chars[chars.len() - 16..].iter().collect();
|
||||
format!("{head}…{tail}")
|
||||
}
|
||||
|
||||
/// One entry point. The caller dedups against rule-matched items and the
|
||||
/// safety layer (whitelist / protected) is applied like for any other item.
|
||||
pub fn collect(engine: &crate::Engine, cancel: &squid_core::CancelToken) -> Vec<CleanupItem> {
|
||||
let mut out = Vec::new();
|
||||
let mut seen: HashSet<PathBuf> = HashSet::new();
|
||||
if cancel.is_cancelled() {
|
||||
return out;
|
||||
}
|
||||
let running: Vec<String> = engine
|
||||
.platform()
|
||||
.running_executables()
|
||||
.into_iter()
|
||||
.map(|proc| {
|
||||
proc.rsplit(['/', '\\'])
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_lowercase()
|
||||
})
|
||||
.collect();
|
||||
let roots = appdata_roots();
|
||||
|
||||
// Layer A: precise known-app staging folders.
|
||||
for app in KNOWN_APPS {
|
||||
let blocked = !app.process.is_empty() && running.iter().any(|name| name == app.process);
|
||||
for root in &roots {
|
||||
let dir = root.join(app.dir);
|
||||
if dir.is_dir() {
|
||||
sweep(
|
||||
&dir,
|
||||
app.label,
|
||||
"update-installers-known",
|
||||
blocked,
|
||||
&mut out,
|
||||
&mut seen,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Layer B: heuristic sweep of <AppDataRoot>/<vendor>/<update-dir>.
|
||||
for root in &roots {
|
||||
let Ok(vendors) = std::fs::read_dir(root) else {
|
||||
continue;
|
||||
};
|
||||
for vendor in vendors.flatten() {
|
||||
if cancel.is_cancelled() {
|
||||
return out;
|
||||
}
|
||||
if !vendor.file_type().map(|t| t.is_dir()).unwrap_or(false) {
|
||||
continue;
|
||||
}
|
||||
let vendor_name = vendor.file_name().to_string_lossy().into_owned();
|
||||
if SKIP_VENDORS
|
||||
.iter()
|
||||
.any(|skip| vendor_name.eq_ignore_ascii_case(skip))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let Ok(subs) = std::fs::read_dir(vendor.path()) else {
|
||||
continue;
|
||||
};
|
||||
for sub in subs.flatten() {
|
||||
let name = sub.file_name().to_string_lossy().into_owned();
|
||||
if !UPDATE_DIR_NAMES.contains(&name.to_lowercase().as_str()) || !sub.path().is_dir()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sweep(
|
||||
&sub.path(),
|
||||
&vendor_name,
|
||||
"update-installers-scan",
|
||||
false,
|
||||
&mut out,
|
||||
&mut seen,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn installer_shapes_are_matched_and_runtime_is_not() {
|
||||
assert!(is_installer(Path::new("a/patch.zip")));
|
||||
assert!(is_installer(Path::new("a/Weixin.EXE")));
|
||||
assert!(is_installer(Path::new("a/update.bin.patch")));
|
||||
// Runtime components must never match — this is the WeChat rule.
|
||||
assert!(!is_installer(Path::new("a/RadiumWMPF.bin")));
|
||||
assert!(!is_installer(Path::new("a/Weixin.dll")));
|
||||
assert!(!is_installer(Path::new("a/manifest.dat")));
|
||||
assert!(!is_installer(Path::new("a/noext")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tiny_files_are_not_offered() {
|
||||
let temp = std::env::temp_dir().join(format!("squid-updates-size-{}", std::process::id()));
|
||||
let Ok(()) = std::fs::create_dir_all(&temp) else {
|
||||
eprintln!("skipping: scratch dir failed");
|
||||
return;
|
||||
};
|
||||
let file = temp.join("small.exe");
|
||||
if let Err(error) = std::fs::write(&file, vec![0u8; 1024]) {
|
||||
eprintln!("skipping: scratch write denied ({error})");
|
||||
return;
|
||||
}
|
||||
let meta = std::fs::metadata(&file).expect("meta");
|
||||
assert!(!stale_enough(&meta));
|
||||
let big = temp.join("big.exe");
|
||||
if std::fs::write(&big, vec![0u8; 2 * 1024 * 1024]).is_ok() {
|
||||
let meta = std::fs::metadata(&big).expect("big meta");
|
||||
// fresh: size passes but the 7-day gate holds it back
|
||||
assert!(!stale_enough(&meta));
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&temp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_package_names_get_squashed() {
|
||||
let name = squash_name(Path::new(&format!("C:/x/{}-x64_zh-CN.msi", "a".repeat(60))));
|
||||
assert!(name.chars().count() <= 42, "{name}");
|
||||
assert!(name.ends_with("-x64_zh-CN.msi"));
|
||||
}
|
||||
}
|
||||
|
|
@ -251,6 +251,15 @@ impl Sampler {
|
|||
}
|
||||
|
||||
pub fn refresh(&mut self) -> SystemSnapshot {
|
||||
self.refresh_with(true)
|
||||
}
|
||||
|
||||
/// `want_processes=false` is the widget-grade light refresh: it skips the
|
||||
/// per-pid CPU/memory walk (hundreds of Get-ProcessTimes calls on
|
||||
/// Windows) and the top-process sort, keeping only a cheap pid sweep for
|
||||
/// the process count. The always-on desktop widget pays this on every
|
||||
/// beat; only 实时监控 asks for the full table.
|
||||
pub fn refresh_with(&mut self, want_processes: bool) -> SystemSnapshot {
|
||||
let elapsed = self.last.elapsed().max(Duration::from_millis(80));
|
||||
self.last = Instant::now();
|
||||
|
||||
|
|
@ -258,11 +267,19 @@ impl Sampler {
|
|||
.refresh_cpu_specifics(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());
|
||||
self.system
|
||||
.refresh_memory_specifics(sysinfo::MemoryRefreshKind::nothing().with_ram().with_swap());
|
||||
self.system.refresh_processes_specifics(
|
||||
ProcessesToUpdate::All,
|
||||
true,
|
||||
ProcessRefreshKind::nothing().with_cpu().with_memory(),
|
||||
);
|
||||
if want_processes {
|
||||
self.system.refresh_processes_specifics(
|
||||
ProcessesToUpdate::All,
|
||||
true,
|
||||
ProcessRefreshKind::nothing().with_cpu().with_memory(),
|
||||
);
|
||||
} else {
|
||||
self.system.refresh_processes_specifics(
|
||||
ProcessesToUpdate::All,
|
||||
true,
|
||||
ProcessRefreshKind::nothing(),
|
||||
);
|
||||
}
|
||||
self.networks.refresh(true);
|
||||
self.disks
|
||||
.refresh_specifics(true, DiskRefreshKind::nothing().with_io_usage());
|
||||
|
|
@ -272,7 +289,11 @@ impl Sampler {
|
|||
let memory = memory_stats(&self.system);
|
||||
let network = net_rates(&self.networks, seconds);
|
||||
let disk = disk_rates(&self.disks, seconds);
|
||||
let top_processes = top_processes(&self.system, 12);
|
||||
let top_processes = if want_processes {
|
||||
top_processes(&self.system, 12)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let mut snapshot = SystemSnapshot {
|
||||
taken_at_ms: now_ms(),
|
||||
|
|
@ -917,6 +938,24 @@ mod tests {
|
|||
assert!(!apps.is_empty());
|
||||
}
|
||||
|
||||
/// The widget-grade light refresh: every meter the desktop panel draws
|
||||
/// still moves, but the per-process table stays empty (that walk is the
|
||||
/// expensive part of a refresh on Windows).
|
||||
#[test]
|
||||
fn the_light_refresh_keeps_the_meters_and_drops_the_table() {
|
||||
let mut sampler = Sampler::new();
|
||||
std::thread::sleep(Duration::from_millis(220));
|
||||
let snapshot = sampler.refresh_with(false);
|
||||
assert_eq!(snapshot.cpu.per_core.len(), snapshot.cpu.logical_cores);
|
||||
assert!(snapshot.memory.total.as_u64() > 0);
|
||||
assert!(snapshot.processes > 0);
|
||||
assert!(snapshot.top_processes.is_empty());
|
||||
// A light beat must not poison the full one: the next full refresh
|
||||
// still walks processes and produces a ranking.
|
||||
let full = sampler.refresh_with(true);
|
||||
assert!(!full.top_processes.is_empty() || full.processes == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percentages_never_exceed_one_hundred() {
|
||||
let stats = MemoryStats {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ impl Strings {
|
|||
C::ProjectArtifacts => "构建产物",
|
||||
C::LanguagePacks => "多余语言包",
|
||||
C::Leftovers => "卸载残留",
|
||||
C::UpdateInstallers => "升级安装包",
|
||||
C::Trash => self.bin(),
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "squid-desktop",
|
||||
"private": true,
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --port 1420 --strictPort",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
Squid 0.1.10 - Windows x64
|
||||
|
||||
系统要求
|
||||
--------
|
||||
- Windows 10 或 Windows 11(x64;ARM64 设备通过系统兼容层运行)。
|
||||
- Microsoft Edge WebView2 Runtime。Windows 10/11 通常已内置;如果 Squid
|
||||
启动后窗口空白,请从微软官方页面安装 WebView2 Evergreen Runtime:
|
||||
https://developer.microsoft.com/microsoft-edge/webview2/
|
||||
- 安装与运行都不需要管理员权限。安装位置为
|
||||
%LOCALAPPDATA%\Programs\Squid。
|
||||
- 权限管理页中,机单(HKLM)范围的启动项开关与系统服务需要以管理员身份
|
||||
运行 Squid 才能修改,界面会给出明确提示。
|
||||
|
||||
安装
|
||||
----
|
||||
1. 运行 Squid-Setup-0.1.10-win-x64.exe。
|
||||
2. 这是未签名构建。若 SmartScreen 显示警告,请选择“更多信息” > “仍要运行”。
|
||||
3. 升级直接覆盖安装,不再询问是否先卸载旧版本;用户配置自动继承。
|
||||
4. 卸载请在 Windows“设置 > 应用”中移除 Squid。
|
||||
|
||||
更新
|
||||
----
|
||||
Squid 使用与 nex_shift 一致的 releases 分支更新通道。更新包会先校验
|
||||
文件大小与 SHA256,再在退出后运行同一个安装程序。若构建时写入发布公钥,
|
||||
还会验证清单的 Ed25519 签名。
|
||||
|
||||
校验
|
||||
----
|
||||
PowerShell:
|
||||
Get-FileHash .\Squid-Setup-0.1.10-win-x64.exe -Algorithm SHA256
|
||||
|
||||
提示
|
||||
----
|
||||
- 覆盖升级前请先完全退出 Squid(关闭窗口只会进入托盘,请在托盘图标
|
||||
上右键退出),否则安装程序无法替换正在运行的程序文件。
|
||||
- 本机若装有腾讯电脑管家,其"程序保护"可能拦截未签名安装程序写入
|
||||
临时目录,报"NSIS Error - Error writing temporary file"。三种绕法,
|
||||
按方便程度排序:
|
||||
1) 双击本目录的「一键安装.bat」——它会把安装包复制到 C 盘临时目录
|
||||
再启动(管家只拦从非系统盘启动的安装程序,此法本机验证有效);
|
||||
2) 管家弹窗出现时选"允许",或将安装文件加入信任区后重试;
|
||||
3) 使用便携包 Squid-0.1.10-portable-win-x64.zip,解压后把 Squid 目录
|
||||
内的文件覆盖到安装目录(先退出托盘中的 Squid),效果相同。
|
||||
- 桌面小工具在安装后默认开启,会出现在屏幕右上角;新版新增 CPU 面板
|
||||
(总占用曲线 + 每核渐变占用柱),可在主程序「桌面小工具」页开关各面板。
|
||||
- 清理新增「升级安装包」分类:应用升级后留在 AppData 的安装包(微信、
|
||||
企业微信、WPS 等),放置超过 7 天才会被找出;删除确认时可一键跳过。
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
Squid 0.1.10 更新说明
|
||||
|
||||
新增
|
||||
- 清理新增「升级安装包」分类:找出应用升级完成后留在 AppData 里的安装包
|
||||
(微信、企业微信、WPS、网易邮箱等已知应用精确规则 + AppData 启发式扫描)。
|
||||
只匹配安装包形态(exe/msi/zip/7z 等)且放置超过 7 天的文件,微信运行库组件
|
||||
不会被误删;应用正在运行时相关安装包自动锁定。删除确认时会提示升级包数量
|
||||
与大小,可一键「跳过升级包,只删其余」。
|
||||
- 桌面小工具新增「CPU」面板:总体占用率历史曲线 + 整行渐变占用柱,一根柱对应
|
||||
一个逻辑核心;柱色随占用率在绿→黄→橙→红之间连续渐变(含柱内纵向微渐变),
|
||||
悬停显示「核心 N: xx%」(编号与任务管理器一致从 0 开始);核心较多时柱宽自动
|
||||
收窄。管理页与桌面设置弹层可独立开关该面板。
|
||||
|
||||
优化
|
||||
- 桌面常驻 CPU 占用大幅下降(实测本机构从约 8.5% 全机总占用降至 0.2%):
|
||||
小工具改用轻量采样(跳过全机逐进程枚举,那是旧版每秒最贵的一步)、两个
|
||||
窗口共享同一次采样、小工具折叠或主窗口收进托盘后完全停止采样。实时监控
|
||||
页打开时才有完整进程表,功能不受影响。
|
||||
- 修复小工具窗口自身的自适应尺寸回环(尺寸→重锚定→再触发自适应无限循环),
|
||||
该回环会让主进程与小工具渲染进程空转互叫并频繁写配置文件;修复后小工具
|
||||
开着时 Squid 全家 CPU 占用接近 0%。
|
||||
|
||||
调整
|
||||
- Windows 上所有「废纸篓」文案改为「回收站」(清理、卸载、历史、设置等随系统
|
||||
名称联动);macOS 仍为「废纸篓」。
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
5e46b4aa28ef410a32cb609c937055cff611627d99384f78ada5cea7ff2991ba *Squid-Setup-0.1.10-win-x64.exe
|
||||
aa11e2293b521e16bb1d6bdde25a8cd12d2021308dddba6c8936fee0ac363cf0 *Squid-0.1.10-portable-win-x64.zip
|
||||
Binary file not shown.
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"schema": 1,
|
||||
"version": "0.1.10",
|
||||
"date": "2026-11-18",
|
||||
"notes": "Squid 0.1.10\n\n新增\n- 清理新增「升级安装包」分类:找出应用升级完成后留在 AppData 里的安装包\n (微信、企业微信、WPS、网易邮箱等已知应用精确规则 + AppData 启发式扫描)。\n 只匹配安装包形态(exe/msi/zip/7z 等)且放置超过 7 天的文件,微信运行库组件\n 不会被误删;应用正在运行时相关安装包自动锁定。删除确认时会提示升级包数量\n 与大小,可一键「跳过升级包,只删其余」。\n- 桌面小工具新增「CPU」面板:总体占用率历史曲线 + 整行渐变占用柱,一根柱对应\n 一个逻辑核心;柱色随占用率在绿→黄→橙→红之间连续渐变(含柱内纵向微渐变),\n 悬停显示「核心 N: xx%」(编号与任务管理器一致从 0 开始);核心较多时柱宽自动\n 收窄。管理页与桌面设置弹层可独立开关该面板。\n\n优化\n- 桌面常驻 CPU 占用大幅下降(实测本机构从约 8.5% 全机总占用降至 0.2%):\n 小工具改用轻量采样(跳过全机逐进程枚举,那是旧版每秒最贵的一步)、两个\n 窗口共享同一次采样、小工具折叠或主窗口收进托盘后完全停止采样。实时监控\n 页打开时才有完整进程表,功能不受影响。\n- 修复小工具窗口自身的自适应尺寸回环(尺寸→重锚定→再触发自适应无限循环),\n 该回环会让主进程与小工具渲染进程空转互叫并频繁写配置文件;修复后小工具\n 开着时 Squid 全家 CPU 占用接近 0%。\n\n调整\n- Windows 上所有「废纸篓」文案改为「回收站」(清理、卸载、历史、设置等随系统\n 名称联动);macOS 仍为「废纸篓」。",
|
||||
"artifacts": {
|
||||
"windows": {
|
||||
"file": "Squid-Setup-0.1.10-win-x64.exe",
|
||||
"sha256": "5e46b4aa28ef410a32cb609c937055cff611627d99384f78ada5cea7ff2991ba",
|
||||
"size": 3566497
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
@echo off
|
||||
rem 360/QQPC Manager blocks unsigned installers started from non-system
|
||||
rem drives when they unpack into TEMP. Copy the setup to %TEMP% on C: first.
|
||||
copy /Y "%~dp0Squid-Setup-0.1.10-win-x64.exe" "%TEMP%\" >nul
|
||||
start "" "%TEMP%\Squid-Setup-0.1.10-win-x64.exe"
|
||||
|
|
@ -3502,7 +3502,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-core"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -3521,7 +3521,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-desktop"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
|
|
@ -3545,7 +3545,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-engine"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -3565,7 +3565,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-platform"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"libc",
|
||||
|
|
@ -3583,7 +3583,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-rules"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"globset",
|
||||
"serde",
|
||||
|
|
@ -3595,7 +3595,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "squid-stats"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"libc",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "squid-desktop"
|
||||
version = "0.1.9"
|
||||
version = "0.1.10"
|
||||
description = "Squid — a CleanMyMac-inspired cleaner, uninstaller and system monitor."
|
||||
authors = ["squid contributors"]
|
||||
edition = "2021"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ pub struct AppState {
|
|||
plans: Mutex<HashMap<String, UninstallPlan>>,
|
||||
apps: Mutex<Vec<AppInfo>>,
|
||||
sampler: Mutex<Sampler>,
|
||||
/// Last light snapshot, so the widget window and the main window polling
|
||||
/// a beat apart share one refresh instead of paying for two.
|
||||
snapshot_cache: Mutex<Option<(Instant, squid_stats::SystemSnapshot)>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
|
|
@ -824,10 +827,34 @@ pub async fn storage_largest_files(
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn system_snapshot(app: AppHandle) -> Result<SystemSnapshot, String> {
|
||||
pub fn system_snapshot(app: AppHandle, full: Option<bool>) -> Result<SystemSnapshot, String> {
|
||||
// `full` costs a per-pid CPU/memory walk of every process on the machine
|
||||
// (hundreds of syscalls) plus the top-12 sort — the 实时监控 page needs
|
||||
// it; the desktop widget, overview tiles and every background poll pass
|
||||
// false and ride the light refresh. Light answers are cached for two
|
||||
// seconds so windows polling in step pay for one refresh, not several.
|
||||
let state = app.state::<AppState>();
|
||||
if full.unwrap_or(false) {
|
||||
let mut sampler = AppState::lock(&state.sampler)?;
|
||||
let snapshot = sampler.refresh();
|
||||
if let Ok(mut cache) = AppState::lock(&state.snapshot_cache) {
|
||||
*cache = Some((Instant::now(), snapshot.clone()));
|
||||
}
|
||||
return Ok(snapshot);
|
||||
}
|
||||
if let Ok(cache) = AppState::lock(&state.snapshot_cache) {
|
||||
if let Some((at, snapshot)) = cache.as_ref() {
|
||||
if at.elapsed() < Duration::from_secs(2) {
|
||||
return Ok(snapshot.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut sampler = AppState::lock(&state.sampler)?;
|
||||
Ok(sampler.refresh())
|
||||
let snapshot = sampler.refresh_with(false);
|
||||
if let Ok(mut cache) = AppState::lock(&state.snapshot_cache) {
|
||||
*cache = Some((Instant::now(), snapshot.clone()));
|
||||
}
|
||||
Ok(snapshot)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ fn show_main_window(app: &AppHandle) {
|
|||
let _ = window.show();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
// The page stops sampling while parked in the tray; wake it up.
|
||||
let _ = app.emit("squid://visible", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +95,9 @@ pub fn run() {
|
|||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
api.prevent_close();
|
||||
let _ = window.hide();
|
||||
// A hidden window must not keep sampling the whole machine;
|
||||
// the page pauses its polling on this signal.
|
||||
let _ = window.emit("squid://visible", false);
|
||||
}
|
||||
})
|
||||
.manage(app::AppState::default())
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ pub struct WidgetPrefs {
|
|||
/// Master switch: hides the window entirely when off.
|
||||
pub enabled: bool,
|
||||
pub panel_run: bool,
|
||||
pub panel_cpu: bool,
|
||||
pub panel_network: bool,
|
||||
pub panel_disk: bool,
|
||||
pub panel_storage: bool,
|
||||
|
|
@ -109,6 +110,7 @@ impl Default for WidgetPrefs {
|
|||
Self {
|
||||
enabled: true,
|
||||
panel_run: true,
|
||||
panel_cpu: true,
|
||||
panel_network: true,
|
||||
panel_disk: true,
|
||||
panel_storage: true,
|
||||
|
|
@ -229,7 +231,11 @@ fn place_window(app: &AppHandle, prefs: &WidgetPrefs) {
|
|||
/// ordinary app window, so it can never cover the user's work.
|
||||
fn sync_window(app: &AppHandle, prefs: &WidgetPrefs) {
|
||||
if !prefs.enabled
|
||||
|| (!prefs.panel_run && !prefs.panel_network && !prefs.panel_disk && !prefs.panel_storage)
|
||||
|| !(prefs.panel_run
|
||||
|| prefs.panel_cpu
|
||||
|| prefs.panel_network
|
||||
|| prefs.panel_disk
|
||||
|| prefs.panel_storage)
|
||||
{
|
||||
if let Some(window) = app.get_webview_window(WIDGET_LABEL) {
|
||||
let _ = window.hide();
|
||||
|
|
@ -290,6 +296,7 @@ pub fn widget_get(app: AppHandle) -> WidgetView {
|
|||
pub struct WidgetPatch {
|
||||
pub enabled: Option<bool>,
|
||||
pub panel_run: Option<bool>,
|
||||
pub panel_cpu: Option<bool>,
|
||||
pub panel_network: Option<bool>,
|
||||
pub panel_disk: Option<bool>,
|
||||
pub panel_storage: Option<bool>,
|
||||
|
|
@ -319,6 +326,9 @@ pub fn widget_set(app: AppHandle, patch: WidgetPatch) -> Result<WidgetPrefs, Str
|
|||
if let Some(value) = patch.panel_run {
|
||||
prefs.panel_run = value;
|
||||
}
|
||||
if let Some(value) = patch.panel_cpu {
|
||||
prefs.panel_cpu = value;
|
||||
}
|
||||
if let Some(value) = patch.panel_network {
|
||||
prefs.panel_network = value;
|
||||
}
|
||||
|
|
@ -423,6 +433,7 @@ mod tests {
|
|||
// keys the frontend types.ts promises must appear serialized
|
||||
for key in [
|
||||
"\"panelRun\"",
|
||||
"\"panelCpu\"",
|
||||
"\"intervalMs\"",
|
||||
"\"rememberCollapsed\"",
|
||||
"\"collapsed\"",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Squid",
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"identifier": "app.nex.squid",
|
||||
"mainBinaryName": "squid-desktop",
|
||||
"build": {
|
||||
|
|
|
|||
27
src/App.tsx
27
src/App.tsx
|
|
@ -185,12 +185,16 @@ export default function App() {
|
|||
const [settings, setSettings] = useState<SettingsView | null>(null);
|
||||
const [autoCheck, setAutoCheck] = useState(true);
|
||||
const [setupOpen, setSetupOpen] = useState(false);
|
||||
// The 托盘驻留 case: a hidden main window must stop sampling the machine.
|
||||
const [windowVisible, setWindowVisible] = useState(true);
|
||||
const cleanup = useScanWorkspace("cleanup");
|
||||
const purge = useScanWorkspace("purge");
|
||||
const apps = useAppsWorkspace();
|
||||
const permissions = usePermissionsWorkspace(page === "permissions");
|
||||
const systemActive = page === "overview" || page === "system";
|
||||
const system = useSystemSnapshot(systemActive);
|
||||
const systemActive = (page === "overview" || page === "system") && windowVisible;
|
||||
// Only the 实时监控 top-process table needs the expensive per-pid walk;
|
||||
// the overview tiles ride the light refresh.
|
||||
const system = useSystemSnapshot(systemActive, 1800, page === "system");
|
||||
const update = useUpdateFlow(bootstrap?.updateFeedUrl ?? "", autoCheck);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -231,6 +235,23 @@ export default function App() {
|
|||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
let unlisten: (() => void) | null = null;
|
||||
void api
|
||||
.onWindowVisible((next) => {
|
||||
if (!cancelled) setWindowVisible(next);
|
||||
})
|
||||
.then((stop) => {
|
||||
if (cancelled) stop();
|
||||
else unlisten = stop;
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
unlisten?.();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const order: PageId[] = [
|
||||
"overview",
|
||||
|
|
@ -303,7 +324,7 @@ export default function App() {
|
|||
: null;
|
||||
|
||||
return (
|
||||
<I18nProvider lang={lang} setLang={setLang}>
|
||||
<I18nProvider lang={lang} setLang={setLang} binNoun={bootstrap.binNoun}>
|
||||
<AppChrome
|
||||
bootstrap={bootstrap}
|
||||
page={page}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
ArrowUpRight,
|
||||
DownloadCloud,
|
||||
FolderOpen,
|
||||
LockKeyhole,
|
||||
RotateCcw,
|
||||
|
|
@ -92,7 +93,7 @@ function ItemRow({
|
|||
checked: boolean;
|
||||
onToggle: () => void;
|
||||
}) {
|
||||
const { lang, t } = useI18n();
|
||||
const { lang, t, bin } = useI18n();
|
||||
const Icon = CATEGORY_META[item.category].icon;
|
||||
return (
|
||||
<div
|
||||
|
|
@ -113,7 +114,7 @@ function ItemRow({
|
|||
<span className="cleanup-row-copy">
|
||||
<span className="cleanup-row-title">
|
||||
<strong>{item.label}</strong>
|
||||
<span className="row-category">{categoryLabel(item.category, lang)}</span>
|
||||
<span className="row-category">{categoryLabel(item.category, lang, bin)}</span>
|
||||
</span>
|
||||
<span className="cleanup-row-path" title={item.displayPath}>
|
||||
{shortPath(item.displayPath, 90)}
|
||||
|
|
@ -171,6 +172,21 @@ export function CleanupInventory({
|
|||
}, [focus, result]);
|
||||
const removables = result?.items.filter((item) => !item.lock).length ?? 0;
|
||||
|
||||
// 升级安装包:selection may include stale update packages; the confirm
|
||||
// dialog offers a one-click "delete everything else, keep these" escape.
|
||||
const selectedUpdaters = useMemo(() => {
|
||||
if (!result) return { indexes: [] as number[], total: 0 };
|
||||
let total = 0;
|
||||
const indexes: number[] = [];
|
||||
result.items.forEach((item, index) => {
|
||||
if (item.category === "update-installers" && workspace.selected.has(index)) {
|
||||
indexes.push(index);
|
||||
total += item.onDisk;
|
||||
}
|
||||
});
|
||||
return { indexes, total };
|
||||
}, [result, workspace.selected]);
|
||||
|
||||
if (workspace.scanning) {
|
||||
return (
|
||||
<ProgressCard
|
||||
|
|
@ -196,8 +212,8 @@ export function CleanupInventory({
|
|||
|
||||
if (!result) return null;
|
||||
|
||||
const confirm = async () => {
|
||||
const summary = await workspace.clean(mode);
|
||||
const confirm = async (indexes?: number[]) => {
|
||||
const summary = await workspace.clean(mode, indexes);
|
||||
setConfirming(false);
|
||||
if (summary) {
|
||||
push(
|
||||
|
|
@ -289,7 +305,7 @@ export function CleanupInventory({
|
|||
<SectionTitle
|
||||
title={
|
||||
focus
|
||||
? categoryLabel(focus, lang)
|
||||
? categoryLabel(focus, lang, bin)
|
||||
: t("Everything found in this scan", "本次扫描的全部项目")
|
||||
}
|
||||
subtitle={t(
|
||||
|
|
@ -400,6 +416,43 @@ export function CleanupInventory({
|
|||
<span>{t("Permanent", "永久")}</span>
|
||||
</button>
|
||||
</div>
|
||||
{selectedUpdaters.indexes.length > 0 ? (
|
||||
<div className="confirm-updater-banner">
|
||||
<DownloadCloud size={18} />
|
||||
<div>
|
||||
<strong>
|
||||
{t(
|
||||
`Includes ${formatCount(selectedUpdaters.indexes.length)} update installers (${formatBytes(selectedUpdaters.total)})`,
|
||||
`其中包含 ${formatCount(selectedUpdaters.indexes.length)} 个升级安装包(${formatBytes(selectedUpdaters.total)})`,
|
||||
)}
|
||||
</strong>
|
||||
<span>
|
||||
{t(
|
||||
"Apps re-download them when needed. Delete them too?",
|
||||
"应用需要时会自动重新下载。要一并清理吗?",
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={workspace.deleting}
|
||||
onClick={() => {
|
||||
const keep = [...workspace.selected].filter(
|
||||
(index) => !selectedUpdaters.indexes.includes(index),
|
||||
);
|
||||
if (keep.length === 0) {
|
||||
workspace.deselect(selectedUpdaters.indexes);
|
||||
setConfirming(false);
|
||||
return;
|
||||
}
|
||||
void confirm(keep);
|
||||
}}
|
||||
>
|
||||
{t("Skip installers, clean rest", "跳过升级包,只删其余")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</ConfirmDialog>
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ export interface MetricHistory {
|
|||
netDown: number[];
|
||||
diskRead: number[];
|
||||
diskWrite: number[];
|
||||
cpu: number[];
|
||||
}
|
||||
|
||||
/** Append-only ring buffers over the snapshot stream (sparkline source). */
|
||||
|
|
@ -59,6 +60,7 @@ export function useHistory(): [MetricHistory, (snapshot: SystemSnapshot) => void
|
|||
netDown: [],
|
||||
diskRead: [],
|
||||
diskWrite: [],
|
||||
cpu: [],
|
||||
});
|
||||
const bump = useMemo(
|
||||
() => (snapshot: SystemSnapshot) => {
|
||||
|
|
@ -70,18 +72,27 @@ export function useHistory(): [MetricHistory, (snapshot: SystemSnapshot) => void
|
|||
push(ref.current.netDown, snapshot.network.rx_per_sec);
|
||||
push(ref.current.diskRead, snapshot.disk.read_per_sec);
|
||||
push(ref.current.diskWrite, snapshot.disk.write_per_sec);
|
||||
push(ref.current.cpu, snapshot.cpu.total);
|
||||
},
|
||||
[],
|
||||
);
|
||||
return [ref.current, bump];
|
||||
}
|
||||
|
||||
function Spark({ values, color }: { values: number[]; color: string }) {
|
||||
function Spark({
|
||||
values,
|
||||
color,
|
||||
max,
|
||||
}: {
|
||||
values: number[];
|
||||
color: string;
|
||||
max?: number;
|
||||
}) {
|
||||
// The history array is mutated in place between renders, so the polyline
|
||||
// must be rebuilt every render — a useMemo on identity would freeze the
|
||||
// first (empty) result forever.
|
||||
if (values.length < 2) return <svg className="wd-spark" viewBox="0 0 300 56" />;
|
||||
const top = Math.max(...values, 1);
|
||||
const top = max ?? Math.max(...values, 1);
|
||||
const width = 300;
|
||||
const step = width / (HISTORY - 1);
|
||||
const offset = HISTORY - values.length;
|
||||
|
|
@ -109,6 +120,92 @@ export function uptimeFull(seconds: number, zh: boolean): string {
|
|||
: `${d}d ${h}h ${m}m ${s}s`;
|
||||
}
|
||||
|
||||
/* 逻辑核心占用柱状图:整行均分(核心多则柱变窄),柱色 = 占用率在
|
||||
* 绿→黄→橙→红 四个锚点之间连续插值,柱内再做纵向微渐变;悬停显示
|
||||
* 「核心 N: xx%」(编号与任务管理器一致从 0 开始)。 */
|
||||
const LOAD_STOPS: Array<[number, [number, number, number]]> = [
|
||||
[0, [46, 204, 113]],
|
||||
[33, [247, 224, 120]],
|
||||
[66, [245, 165, 76]],
|
||||
[100, [233, 87, 63]],
|
||||
];
|
||||
|
||||
function loadRgb(value: number): [number, number, number] {
|
||||
const v = Math.max(0, Math.min(100, value));
|
||||
for (let i = 1; i < LOAD_STOPS.length; i += 1) {
|
||||
const [at, rgb] = LOAD_STOPS[i];
|
||||
if (v <= at) {
|
||||
const [prevAt, prevRgb] = LOAD_STOPS[i - 1];
|
||||
const t = (v - prevAt) / (at - prevAt);
|
||||
return rgb.map((channel, k) =>
|
||||
Math.round(prevRgb[k] + (channel - prevRgb[k]) * t),
|
||||
) as [number, number, number];
|
||||
}
|
||||
}
|
||||
return LOAD_STOPS[LOAD_STOPS.length - 1][1];
|
||||
}
|
||||
|
||||
function loadColor(value: number): string {
|
||||
return `rgb(${loadRgb(value).join(",")})`;
|
||||
}
|
||||
|
||||
function barFill(value: number): string {
|
||||
const base = loadRgb(value);
|
||||
const deep = base.map((channel) => Math.round(channel * 0.62));
|
||||
const gloss = base.map((channel) => Math.round(channel + (255 - channel) * 0.35));
|
||||
const css = (rgb: number[]) => `rgb(${rgb.join(",")})`;
|
||||
return `linear-gradient(180deg, ${css(gloss)} 0%, ${css(base)} 45%, ${css(deep)} 100%)`;
|
||||
}
|
||||
|
||||
function CpuPanel({
|
||||
total,
|
||||
cores,
|
||||
history,
|
||||
zh,
|
||||
}: {
|
||||
total: number;
|
||||
cores: number[];
|
||||
history: MetricHistory;
|
||||
zh: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="wd-card">
|
||||
<div className="wd-line-head">
|
||||
<h4>CPU</h4>
|
||||
<div className="wd-rate">
|
||||
<b className="wd-cpu-total" style={{ color: loadColor(total) }}>
|
||||
{Math.round(total)}%
|
||||
</b>
|
||||
</div>
|
||||
</div>
|
||||
<Spark values={history.cpu} color="#2f6bff" max={100} />
|
||||
{cores.length > 0 ? (
|
||||
<>
|
||||
<div className="wd-bars">
|
||||
{cores.map((value, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="wd-bar"
|
||||
title={`${zh ? "核心" : "Core"} ${index}: ${Math.round(value)}%`}
|
||||
>
|
||||
<i
|
||||
style={{
|
||||
height: `${Math.max(8, Math.min(100, value))}%`,
|
||||
background: barFill(value),
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="wd-bars-caption">
|
||||
{zh ? `逻辑核心 ×${cores.length}` : `Logical cores ×${cores.length}`}
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DiskGlyph() {
|
||||
return (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
|
|
@ -177,6 +274,15 @@ export function WidgetPanels({
|
|||
</div>
|
||||
) : null}
|
||||
|
||||
{prefs.panelCpu ? (
|
||||
<CpuPanel
|
||||
total={snapshot?.cpu.total ?? 0}
|
||||
cores={snapshot?.cpu.per_core ?? []}
|
||||
history={history}
|
||||
zh={zh}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{prefs.panelNetwork ? (
|
||||
<div className="wd-card">
|
||||
<div className="wd-line-head">
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
Check,
|
||||
ChevronDown,
|
||||
Code2,
|
||||
DownloadCloud,
|
||||
FileWarning,
|
||||
Globe2,
|
||||
Languages,
|
||||
|
|
@ -88,8 +89,8 @@ export const CATEGORY_META: Record<Category, CategoryMeta> = {
|
|||
tone: "teal",
|
||||
},
|
||||
trash: {
|
||||
en: "Trash",
|
||||
zh: "废纸篓",
|
||||
en: "Recycle Bin",
|
||||
zh: "回收站",
|
||||
blurbEn: "Files waiting to be emptied",
|
||||
blurbZh: "等待清空的文件",
|
||||
icon: Trash2,
|
||||
|
|
@ -111,11 +112,25 @@ export const CATEGORY_META: Record<Category, CategoryMeta> = {
|
|||
icon: Puzzle,
|
||||
tone: "amber",
|
||||
},
|
||||
"update-installers": {
|
||||
en: "Update installers",
|
||||
zh: "升级安装包",
|
||||
blurbEn: "Installer packages apps keep after updating",
|
||||
blurbZh: "应用升级后留下的安装包,需要时会自动重新下载",
|
||||
icon: DownloadCloud,
|
||||
tone: "green",
|
||||
},
|
||||
};
|
||||
|
||||
export const CATEGORY_ORDER = Object.keys(CATEGORY_META) as Category[];
|
||||
|
||||
export function categoryLabel(category: Category, language: "zh" | "en"): string {
|
||||
export function categoryLabel(
|
||||
category: Category,
|
||||
language: "zh" | "en",
|
||||
binName?: string,
|
||||
): string {
|
||||
// The bin category borrows the OS word for it: 回收站 on Windows, 废纸篓 on macOS.
|
||||
if (category === "trash" && binName) return binName;
|
||||
return language === "zh" ? CATEGORY_META[category].zh : CATEGORY_META[category].en;
|
||||
}
|
||||
|
||||
|
|
@ -612,7 +627,7 @@ export function CategoryCard({
|
|||
onInspect: () => void;
|
||||
focused?: boolean;
|
||||
}) {
|
||||
const { lang, t } = useI18n();
|
||||
const { lang, t, bin } = useI18n();
|
||||
const meta = CATEGORY_META[category];
|
||||
const Icon = meta.icon;
|
||||
return (
|
||||
|
|
@ -630,11 +645,11 @@ export function CategoryCard({
|
|||
checked={selected}
|
||||
disabled={disabled}
|
||||
onChange={onToggle}
|
||||
label={categoryLabel(category, lang)}
|
||||
label={categoryLabel(category, lang, bin)}
|
||||
/>
|
||||
</div>
|
||||
<div className="category-copy">
|
||||
<strong>{categoryLabel(category, lang)}</strong>
|
||||
<strong>{categoryLabel(category, lang, bin)}</strong>
|
||||
<span>{lang === "zh" ? meta.blurbZh : meta.blurbEn}</span>
|
||||
</div>
|
||||
<div className="category-card-foot">
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@ export interface ScanWorkspace {
|
|||
cancel: () => Promise<void>;
|
||||
toggleItem: (index: number) => void;
|
||||
toggleCategory: (category: Category) => void;
|
||||
deselect: (indexes: number[]) => void;
|
||||
selectAll: () => void;
|
||||
clearSelection: () => void;
|
||||
clean: (mode: DeleteMode) => Promise<DeleteResult | null>;
|
||||
clean: (mode: DeleteMode, indexes?: number[]) => Promise<DeleteResult | null>;
|
||||
clearError: () => void;
|
||||
reset: () => void;
|
||||
}
|
||||
|
|
@ -149,6 +150,16 @@ export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
|||
|
||||
const clearSelection = useCallback(() => setSelected(new Set()), []);
|
||||
|
||||
const deselect = useCallback((indexes: number[]) => {
|
||||
if (indexes.length === 0) return;
|
||||
const drop = new Set(indexes);
|
||||
setSelected((current) => {
|
||||
const next = new Set(current);
|
||||
for (const index of drop) next.delete(index);
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const selectedTotal = useMemo(() => {
|
||||
if (!result) return 0;
|
||||
let total = 0;
|
||||
|
|
@ -159,8 +170,10 @@ export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
|||
const selectedCount = selected.size;
|
||||
|
||||
const clean = useCallback(
|
||||
async (mode: DeleteMode) => {
|
||||
if (!result || selected.size === 0 || deleting) return null;
|
||||
async (mode: DeleteMode, indexes?: number[]) => {
|
||||
if (!result || deleting) return null;
|
||||
const targets = indexes ?? [...selected];
|
||||
if (targets.length === 0) return null;
|
||||
const id = jobId();
|
||||
activeJob.current = id;
|
||||
setCurrentJob(id);
|
||||
|
|
@ -171,8 +184,8 @@ export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
|||
try {
|
||||
const next =
|
||||
kind === "cleanup"
|
||||
? await api.cleanupDelete(id, result.scanId, [...selected], mode)
|
||||
: await api.purgeDelete(id, result.scanId, [...selected], mode);
|
||||
? await api.cleanupDelete(id, result.scanId, targets, mode)
|
||||
: await api.purgeDelete(id, result.scanId, targets, mode);
|
||||
if (activeJob.current !== id) return null;
|
||||
setResult(null);
|
||||
setSelected(new Set());
|
||||
|
|
@ -217,6 +230,7 @@ export function useScanWorkspace(kind: ScanKind): ScanWorkspace {
|
|||
cancel,
|
||||
toggleItem,
|
||||
toggleCategory,
|
||||
deselect,
|
||||
selectAll,
|
||||
clearSelection,
|
||||
clean,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,19 @@ import { api } from "../lib/api";
|
|||
import { messageFrom } from "../lib/format";
|
||||
import type { SystemSnapshot } from "../types";
|
||||
|
||||
export function useSystemSnapshot(active: boolean, intervalMs = 1800) {
|
||||
/**
|
||||
* Polls system_snapshot for a page.
|
||||
*
|
||||
* - `full` asks the backend for the expensive per-process walk (only the
|
||||
* 实时监控 top-process table needs it); light refreshes cost a fraction.
|
||||
* - Polling pauses while the window is hidden (tray) or the tab is hidden,
|
||||
* so an icon in the notification area does not keep sampling forever.
|
||||
*/
|
||||
export function useSystemSnapshot(
|
||||
active: boolean,
|
||||
intervalMs = 1800,
|
||||
full = false,
|
||||
) {
|
||||
const [snapshot, setSnapshot] = useState<SystemSnapshot | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
@ -14,7 +26,7 @@ export function useSystemSnapshot(active: boolean, intervalMs = 1800) {
|
|||
inFlight.current = true;
|
||||
setLoading(true);
|
||||
try {
|
||||
setSnapshot(await api.systemSnapshot());
|
||||
setSnapshot(await api.systemSnapshot(full));
|
||||
setError(null);
|
||||
} catch (reason) {
|
||||
setError(messageFrom(reason));
|
||||
|
|
@ -22,13 +34,35 @@ export function useSystemSnapshot(active: boolean, intervalMs = 1800) {
|
|||
inFlight.current = false;
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [full]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!active) return;
|
||||
void refresh();
|
||||
const timer = window.setInterval(() => void refresh(), intervalMs);
|
||||
return () => window.clearInterval(timer);
|
||||
let live = true;
|
||||
let timer: number | null = null;
|
||||
const tick = () => {
|
||||
if (live && !document.hidden) void refresh();
|
||||
};
|
||||
const start = () => {
|
||||
if (timer === null) {
|
||||
void refresh();
|
||||
timer = window.setInterval(tick, intervalMs);
|
||||
}
|
||||
};
|
||||
const stop = () => {
|
||||
if (timer !== null) {
|
||||
window.clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
};
|
||||
const onVisibility = () => (document.hidden ? stop() : start());
|
||||
start();
|
||||
document.addEventListener("visibilitychange", onVisibility);
|
||||
return () => {
|
||||
live = false;
|
||||
stop();
|
||||
document.removeEventListener("visibilitychange", onVisibility);
|
||||
};
|
||||
}, [active, intervalMs, refresh]);
|
||||
|
||||
return { snapshot, error, loading, refresh };
|
||||
|
|
|
|||
|
|
@ -15,18 +15,23 @@ const I18nContext = createContext<I18nValue | null>(null);
|
|||
export function I18nProvider({
|
||||
lang,
|
||||
setLang,
|
||||
binNoun = "trash",
|
||||
children,
|
||||
}: {
|
||||
lang: Language;
|
||||
setLang: (language: Language) => void;
|
||||
binNoun?: "trash" | "recycle-bin";
|
||||
children: ReactNode;
|
||||
}) {
|
||||
// Windows calls it 回收站; macOS and freedesktop keep 废纸篓.
|
||||
const zhBin = binNoun === "recycle-bin" ? "回收站" : "废纸篓";
|
||||
const enBin = binNoun === "recycle-bin" ? "Recycle Bin" : "Trash";
|
||||
const value: I18nValue = {
|
||||
lang,
|
||||
setLang,
|
||||
t: (en, zh) => (lang === "zh" ? zh : en),
|
||||
bin: lang === "zh" ? "废纸篓" : "Trash",
|
||||
binLower: lang === "zh" ? "废纸篓" : "trash",
|
||||
bin: lang === "zh" ? zhBin : enBin,
|
||||
binLower: lang === "zh" ? zhBin : enBin.toLowerCase(),
|
||||
currency: lang === "zh" ? "zh-CN" : "en-US",
|
||||
};
|
||||
return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export const api = {
|
|||
invoke<StorageNode>("storage_explore", { jobId, path, depth, top }),
|
||||
storageLargestFiles: (jobId: string, path: string, limit = 40) =>
|
||||
invoke<LargestFile[]>("storage_largest_files", { jobId, path, limit }),
|
||||
systemSnapshot: () => invoke<SystemSnapshot>("system_snapshot"),
|
||||
systemSnapshot: (full = false) => invoke<SystemSnapshot>("system_snapshot", { full }),
|
||||
stopProcess: (process: SystemSnapshot["top_processes"][number]) =>
|
||||
invoke<void>("stop_process", { process }),
|
||||
historyList: (limit = 60) => invoke<HistorySession[]>("history_list", { limit }),
|
||||
|
|
@ -107,6 +107,8 @@ export const api = {
|
|||
listen<UpdateStatus | null>("update://status", (event) => handler(event.payload)),
|
||||
onNavigate: (handler: (page: PageId) => void) =>
|
||||
listen<PageId>("squid://navigate", (event) => handler(event.payload)),
|
||||
onWindowVisible: (handler: (visible: boolean) => void) =>
|
||||
listen<boolean>("squid://visible", (event) => handler(event.payload)),
|
||||
onPopupClosed: (handler: (event: PopupClosedEvent) => void) =>
|
||||
listen<PopupClosedEvent>("popup://closed", (event) => handler(event.payload)),
|
||||
onWidgetSettings: (handler: (prefs: WidgetPrefs) => void) =>
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ export function ApplicationsPage({
|
|||
<strong>{item.label}</strong>
|
||||
<span title={item.displayPath}>{shortPath(item.displayPath, 44)}</span>
|
||||
<small>
|
||||
{categoryLabel(item.category, lang)}
|
||||
{categoryLabel(item.category, lang, bin)}
|
||||
{item.note ? ` · ${item.note}` : ""}
|
||||
{item.lock ? ` · ${lockLabel(item.lock, t)}` : ""}
|
||||
</small>
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ export function HistoryPage() {
|
|||
eyebrow={t("History", "历史记录")}
|
||||
title={t("Every change, on the record.", "每一次改动,都有记录。")}
|
||||
description={t(
|
||||
"Review past cleanups and put files back from the Trash when you change your mind.",
|
||||
"查看过去的清理记录,改变主意时还可以从废纸篓还原文件。",
|
||||
`Review past cleanups and put files back from the ${bin} when you change your mind.`,
|
||||
`查看过去的清理记录,改变主意时还可以从${bin}还原文件。`,
|
||||
)}
|
||||
actions={
|
||||
<Button
|
||||
|
|
@ -174,7 +174,7 @@ export function HistoryPage() {
|
|||
<small>
|
||||
{formatDate(session.started, lang)} ·{" "}
|
||||
{session.mode === "trash"
|
||||
? t("Moved to Trash", "已移入废纸篓")
|
||||
? t(`Moved to ${bin}`, `已移入${bin}`)
|
||||
: t("Permanently removed", "已永久删除")}
|
||||
</small>
|
||||
</span>
|
||||
|
|
@ -229,7 +229,7 @@ export function HistoryPage() {
|
|||
<small>
|
||||
{entry.category || entry.kind}
|
||||
{entry.trash_path
|
||||
? ` · ${t("in Trash", "位于废纸篓")}`
|
||||
? ` · ${t(`in ${bin}`, `位于${bin}`)}`
|
||||
: ""}
|
||||
</small>
|
||||
</span>
|
||||
|
|
@ -270,8 +270,8 @@ export function HistoryPage() {
|
|||
: ""
|
||||
}
|
||||
note={t(
|
||||
"Files still in the Trash are returned to their original folders. Anything already emptied is skipped.",
|
||||
"仍在废纸篓中的文件会回到原位置;已被清空的项目会被跳过。",
|
||||
`Files still in the ${bin} are returned to their original folders. Anything already emptied is skipped.`,
|
||||
`仍在${bin}中的文件会回到原位置;已被清空的项目会被跳过。`,
|
||||
)}
|
||||
confirmLabel={t("Restore files", "还原文件")}
|
||||
cancelLabel={t("Cancel", "取消")}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,9 @@ export function WidgetPage() {
|
|||
useEffect(() => {
|
||||
let live = true;
|
||||
const tick = async () => {
|
||||
if (document.hidden) return;
|
||||
try {
|
||||
const next = await api.systemSnapshot();
|
||||
const next = await api.systemSnapshot(false);
|
||||
if (live) {
|
||||
setSnapshot(next);
|
||||
bump(next);
|
||||
|
|
@ -86,6 +87,15 @@ export function WidgetPage() {
|
|||
"CPU / 内存 / GPU 占用圆环、设备名、本次运行时长",
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "panelCpu" as const,
|
||||
icon: "▦",
|
||||
name: "CPU",
|
||||
desc: t(
|
||||
"Total usage curve plus a full-width row of gradient load bars, one per logical core.",
|
||||
"总体占用率曲线 + 整行渐变占用柱,一根柱对应一个逻辑核心(绿→黄→橙→红连续渐变,悬停看具体百分比)",
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "panelNetwork" as const,
|
||||
icon: "⇅",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import type { SystemSnapshot } from "../types";
|
|||
|
||||
const PANELS: { key: keyof WidgetPrefs; label: string }[] = [
|
||||
{ key: "panelRun", label: "运行状态" },
|
||||
{ key: "panelCpu", label: "CPU" },
|
||||
{ key: "panelNetwork", label: "网络" },
|
||||
{ key: "panelDisk", label: "存储读写" },
|
||||
{ key: "panelStorage", label: "存储空间" },
|
||||
|
|
@ -49,15 +50,18 @@ export function WidgetWindow() {
|
|||
};
|
||||
}, []);
|
||||
|
||||
// Poll at the configured cadence; pausing while hidden saves cycles.
|
||||
// Poll at the configured cadence. The widget never shows the per-process
|
||||
// table, so it rides the light refresh, and an all-collapsed widget goes
|
||||
// silent until the header is opened again.
|
||||
const collapsed = Boolean(prefs?.collapsed);
|
||||
const intervalMs = prefs?.intervalMs ?? 2000;
|
||||
useEffect(() => {
|
||||
if (!prefs?.enabled) return;
|
||||
if (!prefs?.enabled || collapsed) return;
|
||||
let live = true;
|
||||
const tick = async () => {
|
||||
if (!live || document.hidden) return;
|
||||
try {
|
||||
const next = await api.systemSnapshot();
|
||||
const next = await api.systemSnapshot(false);
|
||||
if (live) {
|
||||
setSnapshot(next);
|
||||
bump(next);
|
||||
|
|
@ -72,7 +76,7 @@ export function WidgetWindow() {
|
|||
live = false;
|
||||
window.clearInterval(timer);
|
||||
};
|
||||
}, [bump, intervalMs, prefs?.enabled]);
|
||||
}, [bump, collapsed, intervalMs, prefs?.enabled]);
|
||||
|
||||
const patch = useCallback((values: Parameters<typeof api.widgetSet>[0]) => {
|
||||
void api
|
||||
|
|
@ -81,14 +85,19 @@ export function WidgetWindow() {
|
|||
.catch((reason) => console.error(messageFrom(reason)));
|
||||
}, []);
|
||||
|
||||
const collapsed = Boolean(prefs?.collapsed);
|
||||
|
||||
// Last persisted drag position; null while the widget is corner-docked.
|
||||
const lastPos = useRef<{ x: number; y: number } | null>(null);
|
||||
|
||||
// Grow/shrink the window to the stacked cards so transparent space never
|
||||
// eats desktop clicks (scrollHeight is CSS px == LogicalSize units).
|
||||
// Only an actual height change may call setSize/redock: setSize answers
|
||||
// with a resize event that re-arms the observer, and redock round-trips
|
||||
// through widget_set → widget://settings → setPrefs. Without this gate the
|
||||
// two effects re-fire each other forever (IPC storm + a config write per
|
||||
// loop turn — the old "widget costs 3% CPU" bug).
|
||||
const rootRef = useRef<HTMLDivElement | null>(null);
|
||||
const lastFit = useRef(0);
|
||||
const ready = Boolean(prefs);
|
||||
useEffect(() => {
|
||||
const root = rootRef.current;
|
||||
if (!root) return;
|
||||
|
|
@ -97,13 +106,17 @@ export function WidgetWindow() {
|
|||
window.cancelAnimationFrame(frame);
|
||||
frame = window.requestAnimationFrame(() => {
|
||||
const height = Math.max(64, root.scrollHeight + 4);
|
||||
if (height === lastFit.current) return;
|
||||
lastFit.current = height;
|
||||
void windowRef.current
|
||||
?.setSize(new LogicalSize(350, height))
|
||||
.then(() => {
|
||||
// Keep the docked corner anchored after the size change.
|
||||
if (!lastPos.current) void api.widgetSet({ redock: true }).catch(() => undefined);
|
||||
})
|
||||
.catch(() => undefined);
|
||||
.catch(() => {
|
||||
lastFit.current = 0;
|
||||
});
|
||||
});
|
||||
};
|
||||
const observer = new ResizeObserver(fit);
|
||||
|
|
@ -113,7 +126,7 @@ export function WidgetWindow() {
|
|||
observer.disconnect();
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [prefs, open, collapsed]);
|
||||
}, [ready, collapsed, open]);
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
setOpen(false);
|
||||
|
|
|
|||
|
|
@ -4472,6 +4472,46 @@ select:focus-visible,
|
|||
box-shadow: 0 3px 8px rgba(47, 80, 112, 0.07);
|
||||
}
|
||||
|
||||
.confirm-updater-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid rgba(23, 122, 84, 0.18);
|
||||
border-radius: 10px;
|
||||
background: rgba(23, 122, 84, 0.06);
|
||||
color: #177a54;
|
||||
}
|
||||
|
||||
.confirm-updater-banner > svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.confirm-updater-banner div {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.confirm-updater-banner strong {
|
||||
font-size: var(--nex-text-3xs);
|
||||
font-weight: var(--nex-weight-semibold);
|
||||
}
|
||||
|
||||
.confirm-updater-banner span {
|
||||
color: var(--nex-muted);
|
||||
font-size: var(--nex-text-3xs);
|
||||
line-height: var(--nex-leading-body);
|
||||
}
|
||||
|
||||
.confirm-updater-banner button {
|
||||
flex-shrink: 0;
|
||||
color: #177a54;
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
|
||||
.toast-stack {
|
||||
|
|
@ -5441,6 +5481,42 @@ html.widget-mode body {
|
|||
margin-top: -34px;
|
||||
}
|
||||
|
||||
/* CPU card: total % + one full-width row of per-core load bars */
|
||||
|
||||
.wd-cpu-total {
|
||||
color: #16b364;
|
||||
}
|
||||
|
||||
.wd-bars {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
height: 30px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.wd-bar {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: flex-end;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
border-radius: 3px;
|
||||
background: #eef1f6;
|
||||
}
|
||||
|
||||
.wd-bar i {
|
||||
display: block;
|
||||
width: 100%;
|
||||
border-radius: 3px;
|
||||
/* height + background come from the core load (连续渐变 in line) */
|
||||
}
|
||||
|
||||
.wd-bars-caption {
|
||||
margin-top: 6px;
|
||||
color: #8b96a5;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
/* storage card */
|
||||
|
||||
.wd-pad {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ export type Category =
|
|||
| "project-artifacts"
|
||||
| "trash"
|
||||
| "language-packs"
|
||||
| "leftovers";
|
||||
| "leftovers"
|
||||
| "update-installers";
|
||||
export type ItemKind = "path" | "contents" | "file";
|
||||
export type LockReason =
|
||||
| "app-running"
|
||||
|
|
@ -393,6 +394,7 @@ export type WidgetCorner = "top-right" | "top-left" | "bottom-right" | "bottom-l
|
|||
export interface WidgetPrefs {
|
||||
enabled: boolean;
|
||||
panelRun: boolean;
|
||||
panelCpu: boolean;
|
||||
panelNetwork: boolean;
|
||||
panelDisk: boolean;
|
||||
panelStorage: boolean;
|
||||
|
|
@ -408,6 +410,7 @@ export interface WidgetPrefs {
|
|||
export interface WidgetPatch {
|
||||
enabled?: boolean;
|
||||
panelRun?: boolean;
|
||||
panelCpu?: boolean;
|
||||
panelNetwork?: boolean;
|
||||
panelDisk?: boolean;
|
||||
panelStorage?: boolean;
|
||||
|
|
|
|||
Loading…
Reference in New Issue