桌面小工具挂入 Progman 常驻:Win+D 显示桌面不再隐藏小工具

- SetParent 进 Progman 子窗口栈顶:显示桌面/最小化所有窗口只作用于顶层窗口,收养后小工具幸免(Wallpaper Engine 同款);仍位于其他应用窗口之下
- 5 秒看门狗:explorer 重启或子级被重新排布时自动重新收养,收养失败退回 HWND_BOTTOM 桌面层
- 本机验证:MinimizeAll(Win+D 等价)后窗口 visible=true 未最小化
- 重新打包 0.1.10(sha256 见 SHA256SUMS),release 文件同步刷新
dev
lijunjie 2026-11-19 10:03:43 +08:00
parent a3253ad38f
commit 9e613042bf
6 changed files with 106 additions and 17 deletions

View File

@ -21,5 +21,9 @@ Squid 0.1.10 更新说明
开着时 Squid 全家 CPU 占用接近 0%。
调整
- 桌面小工具现在真正「常驻」:小工具窗口挂入系统桌面(Progman)窗口,
Win+D / 任务栏「显示桌面」不会再把它最小化隐藏(同 Wallpaper Engine
的做法);explorer 重启后 5 秒内自动归位。仍处于桌面层:在壁纸与图标
之上、其他软件窗口之下。
- Windows 上所有「废纸篓」文案改为「回收站」(清理、卸载、历史、设置等随系统
名称联动);macOS 仍为「废纸篓」。

View File

@ -1,2 +1,2 @@
5e46b4aa28ef410a32cb609c937055cff611627d99384f78ada5cea7ff2991ba *Squid-Setup-0.1.10-win-x64.exe
aa11e2293b521e16bb1d6bdde25a8cd12d2021308dddba6c8936fee0ac363cf0 *Squid-0.1.10-portable-win-x64.zip
9d008dbc0bf671d08b5f1fe801a4b2d9e588a4bb656b49061860eeb4840bf9a9 *Squid-Setup-0.1.10-win-x64.exe
a8f548aaa218868fb127006ca518c79741480d9b742d71ca978e7be688d83e9e *Squid-0.1.10-portable-win-x64.zip

View File

@ -1,13 +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 仍为「废纸篓」。",
"date": "2026-11-19",
"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- 桌面小工具现在真正「常驻」:小工具窗口挂入系统桌面(Progman)窗口,\n Win+D / 任务栏「显示桌面」不会再把它最小化隐藏(同 Wallpaper Engine\n 的做法);explorer 重启后 5 秒内自动归位。仍处于桌面层:在壁纸与图标\n 之上、其他软件窗口之下。\n- Windows 上所有「废纸篓」文案改为「回收站」(清理、卸载、历史、设置等随系统\n 名称联动);macOS 仍为「废纸篓」。",
"artifacts": {
"windows": {
"file": "Squid-Setup-0.1.10-win-x64.exe",
"sha256": "5e46b4aa28ef410a32cb609c937055cff611627d99384f78ada5cea7ff2991ba",
"size": 3566497
"sha256": "9d008dbc0bf671d08b5f1fe801a4b2d9e588a4bb656b49061860eeb4840bf9a9",
"size": 3572815
}
}
}

View File

@ -151,6 +151,7 @@ pub fn run() {
update::spawn_startup_check(app.handle());
manage::spawn_watcher(app.handle().clone());
widget::spawn_startup(app.handle());
widget::spawn_desktop_watch(app.handle());
Ok(())
})
.build(tauri::generate_context!())

View File

@ -16,15 +16,31 @@ use tauri::{AppHandle, Emitter, Manager, WebviewUrl, WebviewWindowBuilder};
pub const WIDGET_LABEL: &str = "widget";
/// `HWND_BOTTOM` + no-activate flags: the widget lives on the desktop layer —
/// above wallpaper and icons, below every ordinary app window.
/// Desktop residency (Windows). Two stacked tricks:
///
/// 1. *Adoption*: re-parent the widget into `Progman`, the shell's desktop
/// window. Win+D ("Show desktop") minimises top-level application windows
/// only, and a child of Progman is not one — the widget survives it
/// (Wallpaper Engine / Rainmeter use the same technique). Inside Progman
/// we ask for the top of the child stack: still under every ordinary app
/// window, now above the desktop icons.
/// 2. *Fallback*: if adoption is unavailable, park the window at
/// `HWND_BOTTOM` with no-activate flags so it at least lives on the
/// desktop layer (above wallpaper and icons, below app windows).
#[cfg(windows)]
mod desktop_layer {
use std::ffi::c_void;
use std::ptr;
#[link(name = "user32")]
extern "system" {
fn FindWindowW(class: *const u16, window: *const u16) -> *mut c_void;
fn SetParent(child: *mut c_void, new_parent: *mut c_void) -> *mut c_void;
fn GetParent(child: *mut c_void) -> *mut c_void;
fn IsWindow(handle: *mut c_void) -> i32;
fn SetWindowPos(
hwnd: *mut core::ffi::c_void,
insert_after: *mut core::ffi::c_void,
hwnd: *mut c_void,
insert_after: *mut c_void,
x: i32,
y: i32,
cx: i32,
@ -32,12 +48,52 @@ mod desktop_layer {
flags: u32,
) -> i32;
}
const HWND_BOTTOM: *mut core::ffi::c_void = 1usize as *mut core::ffi::c_void;
const SWP_NOMOVE: u32 = 0x0002;
const HWND_BOTTOM: *mut c_void = 1usize as *mut c_void;
const HWND_TOP: *mut c_void = ptr::null_mut();
const SWP_NOSIZE: u32 = 0x0001;
const SWP_NOMOVE: u32 = 0x0002;
const SWP_NOACTIVATE: u32 = 0x0010;
// L"Progman"
const PROGMAN: &[u16] = &[80, 114, 111, 103, 109, 97, 110, 0];
pub fn lower(hwnd: *mut core::ffi::c_void) {
fn progman() -> *mut c_void {
// SAFETY: FindWindowW reads only the null-terminated literal above.
unsafe { FindWindowW(PROGMAN.as_ptr(), ptr::null()) }
}
/// Move `hwnd` under Progman (top of its child stack, no focus steal).
/// Idempotent; returns false when there is no desktop to adopt into.
pub fn adopt(hwnd: *mut c_void) -> bool {
let parent = progman();
if parent.is_null() || hwnd.is_null() || unsafe { IsWindow(hwnd) } == 0 {
return false;
}
if unsafe { GetParent(hwnd) } != parent {
// SAFETY: both handles are live (IsWindow checked above).
unsafe { SetParent(hwnd, parent) };
}
// SAFETY: NOMOVE|NOSIZE|NOACTIVATE only re-stacks the child order.
unsafe {
SetWindowPos(
hwnd,
HWND_TOP,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE,
);
}
true
}
/// Whether `hwnd` currently lives under Progman (watchdog probe).
pub fn adopted(hwnd: *mut c_void) -> bool {
let parent = progman();
!parent.is_null() && unsafe { GetParent(hwnd) } == parent
}
pub fn lower(hwnd: *mut c_void) {
// SAFETY: hwnd comes from Tauri's own window handle; SetWindowPos with
// NOMOVE|NOSIZE|NOACTIVATE only edits the z-order.
unsafe {
@ -54,9 +110,9 @@ mod desktop_layer {
}
}
/// Park the widget at the bottom of the window stack (desktop layer).
/// macOS/Linux keep plain floating behaviour for now (no equivalent need:
/// the widget story is Windows-first).
/// Keep the widget on the desktop: adopt into Progman where possible (Win+D
/// proof), otherwise park at the bottom of the z-order. macOS/Linux keep the
/// plain floating behaviour (the widget story is Windows-first).
pub fn lower_window(app: &AppHandle) {
#[cfg(windows)]
{
@ -64,7 +120,10 @@ pub fn lower_window(app: &AppHandle) {
return;
};
if let Ok(hwnd) = window.hwnd() {
desktop_layer::lower(hwnd.0.cast());
let hwnd = hwnd.0.cast();
if !desktop_layer::adopt(hwnd) {
desktop_layer::lower(hwnd);
}
}
}
#[cfg(not(windows))]
@ -73,6 +132,31 @@ pub fn lower_window(app: &AppHandle) {
}
}
/// explorer.exe can recreate its desktop window while Squid runs; the shell
/// may also re-stack Progman's children. A slow heartbeat re-adopts a widget
/// that fell out, so 常驻 stays true without user action.
#[cfg(windows)]
pub fn spawn_desktop_watch(app: &AppHandle) {
let app = app.clone();
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_secs(5));
let Some(window) = app.get_webview_window(WIDGET_LABEL) else {
continue;
};
if !window.is_visible().unwrap_or(false) {
continue;
}
let Ok(hwnd) = window.hwnd() else { continue };
let hwnd: *mut std::ffi::c_void = hwnd.0.cast();
if !desktop_layer::adopted(hwnd) && !desktop_layer::adopt(hwnd) {
desktop_layer::lower(hwnd);
}
});
}
#[cfg(not(windows))]
pub fn spawn_desktop_watch(_app: &AppHandle) {}
fn default_interval_ms() -> u64 {
2_000
}