diff --git a/.gitignore b/.gitignore index d25b165..bd712a6 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ __pycache__/ !release/0.1.5/Squid-Setup-0.1.5-win-x64.exe !release/0.1.6/Squid-0.1.6-macOS-universal.dmg !release/0.1.6/Squid-Setup-0.1.6-win-x64.exe +!release/0.1.7/Squid-0.1.7-macOS-universal.dmg +!release/0.1.7/Squid-Setup-0.1.7-win-x64.exe diff --git a/Cargo.lock b/Cargo.lock index 9b49d00..aab2f40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "gimli 0.33.0", ] +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "aho-corasick" version = "1.1.5" @@ -182,6 +188,29 @@ dependencies = [ "syn 3.0.8", ] +[[package]] +name = "atk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" +dependencies = [ + "atk-sys", + "glib 0.18.5", + "libc", +] + +[[package]] +name = "atk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" +dependencies = [ + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "system-deps 6.2.2", +] + [[package]] name = "atomic" version = "0.6.1" @@ -303,6 +332,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + [[package]] name = "bstr" version = "1.13.1" @@ -335,6 +373,31 @@ version = "1.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" +[[package]] +name = "cairo-rs" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" +dependencies = [ + "bitflags 2.13.2", + "cairo-sys-rs", + "glib 0.18.5", + "libc", + "once_cell", + "thiserror 1.0.69", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" +dependencies = [ + "glib-sys 0.18.1", + "libc", + "system-deps 6.2.2", +] + [[package]] name = "castaway" version = "0.2.4" @@ -354,6 +417,26 @@ dependencies = [ "shlex", ] +[[package]] +name = "cfg-expr" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +dependencies = [ + "smallvec", + "target-lexicon 0.12.16", +] + +[[package]] +name = "cfg-expr" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba9e9ec16c447027685b1f897b720e18e9a8afd00bd7332c483537e38086c9f" +dependencies = [ + "smallvec", + "target-lexicon 0.13.5", +] + [[package]] name = "cfg-if" version = "1.0.5" @@ -406,7 +489,7 @@ version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 3.0.8", @@ -579,7 +662,7 @@ dependencies = [ "serde_derive", "sha2 0.10.9", "smallvec", - "target-lexicon", + "target-lexicon 0.13.5", "wasmtime-internal-core", ] @@ -592,7 +675,7 @@ dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", "cranelift-srcgen", - "heck", + "heck 0.5.0", "pulley-interpreter", ] @@ -633,7 +716,7 @@ dependencies = [ "hashbrown 0.17.1", "log", "smallvec", - "target-lexicon", + "target-lexicon 0.13.5", ] [[package]] @@ -650,7 +733,7 @@ checksum = "649c7b9ad93d5d92287fee74608cacfb139602116293a46e2f25e6ea5402f05c" dependencies = [ "cranelift-codegen", "libc", - "target-lexicon", + "target-lexicon 0.13.5", ] [[package]] @@ -968,6 +1051,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "dispatch2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" +dependencies = [ + "bitflags 2.13.2", + "objc2", +] + [[package]] name = "displaydoc" version = "0.2.7" @@ -1101,6 +1194,15 @@ dependencies = [ "regex", ] +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + [[package]] name = "ff" version = "0.14.0" @@ -1117,6 +1219,33 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "file_icon_provider" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff9f725b347b91d04340444fcbce0770886e4a6513e5f8e9e73a9e344efe73b" +dependencies = [ + "gio 0.22.10", + "gtk", + "log", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-uniform-type-identifiers", + "scopeguard", + "windows 0.62.2", +] + [[package]] name = "filedescriptor" version = "0.8.3" @@ -1146,6 +1275,17 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide 0.9.1", + "zlib-rs", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1194,12 +1334,34 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.8", +] + [[package]] name = "futures-sink" version = "0.3.34" @@ -1221,6 +1383,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-io", + "futures-macro", "futures-sink", "futures-task", "memchr", @@ -1228,6 +1391,64 @@ dependencies = [ "slab", ] +[[package]] +name = "gdk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f245958c627ac99d8e529166f9823fb3b838d1d41fd2b297af3075093c2691" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk-sys", + "gio 0.18.4", + "glib 0.18.5", + "libc", + "pango", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" +dependencies = [ + "gdk-pixbuf-sys", + "gio 0.18.4", + "glib 0.18.5", + "libc", + "once_cell", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" +dependencies = [ + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "gdk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "pango-sys", + "pkg-config", + "system-deps 6.2.2", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -1287,6 +1508,157 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gio" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fc8f532f87b79cbc51a79748f16a6828fb784be93145a322fa14d06d354c73" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys 0.18.1", + "glib 0.18.5", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "gio" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4620fbafdf19dba814473e19f18e75290cb3338662f6ae35f0402affd3b2b699" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys 0.22.9", + "glib 0.22.10", + "libc", + "pin-project-lite", + "smallvec", +] + +[[package]] +name = "gio-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" +dependencies = [ + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "system-deps 6.2.2", + "winapi", +] + +[[package]] +name = "gio-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28739f914c15b87a9856000bed9cbd5b3a8afbca5e982d9a299e1601422cb5" +dependencies = [ + "glib-sys 0.22.9", + "gobject-sys 0.22.9", + "libc", + "system-deps 9.0.1", + "windows-sys 0.61.2", +] + +[[package]] +name = "glib" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" +dependencies = [ + "bitflags 2.13.2", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys 0.18.1", + "glib-macros 0.18.5", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "memchr", + "once_cell", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "glib" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4cf9e5bd8713f1990a92c422998826e0fb34824277b46bc59757373483c6694" +dependencies = [ + "bitflags 2.13.2", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "glib-macros 0.22.9", + "glib-sys 0.22.9", + "gobject-sys 0.22.9", + "libc", + "memchr", + "smallvec", +] + +[[package]] +name = "glib-macros" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" +dependencies = [ + "heck 0.4.1", + "proc-macro-crate 2.0.2", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "glib-macros" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9597c68fa7bdf4154a3079642cd21c4dccac0b0bdd2897d82861523bf91e7b9" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 3.0.8", +] + +[[package]] +name = "glib-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" +dependencies = [ + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "glib-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b38907e67e40dec9b60f858bcada952598719cb512a13eb13d6cdcd16f8295" +dependencies = [ + "libc", + "system-deps 9.0.1", +] + [[package]] name = "globset" version = "0.4.20" @@ -1311,6 +1683,28 @@ dependencies = [ "walkdir", ] +[[package]] +name = "gobject-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" +dependencies = [ + "glib-sys 0.18.1", + "libc", + "system-deps 6.2.2", +] + +[[package]] +name = "gobject-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07595c9ba696bd9819cb6a8df39f08078f3dd679508fe052dd558492c2053834" +dependencies = [ + "glib-sys 0.22.9", + "libc", + "system-deps 9.0.1", +] + [[package]] name = "group" version = "0.14.0" @@ -1322,6 +1716,58 @@ dependencies = [ "subtle", ] +[[package]] +name = "gtk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd56fb197bfc42bd5d2751f4f017d44ff59fbb58140c6b49f9b3b2bdab08506a" +dependencies = [ + "atk", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk", + "gdk-pixbuf", + "gio 0.18.4", + "glib 0.18.5", + "gtk-sys", + "gtk3-macros", + "libc", + "pango", + "pkg-config", +] + +[[package]] +name = "gtk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f29a1c21c59553eb7dd40e918be54dccd60c52b049b75119d5d96ce6b624414" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "pango-sys", + "system-deps 6.2.2", +] + +[[package]] +name = "gtk3-macros" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ff3c5b21f14f0736fed6dcfc0bfb4225ebf5725f3c0209edeec181e4d73e9d" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -1352,6 +1798,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -1745,6 +2197,26 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "mio" version = "1.2.4" @@ -1875,6 +2347,58 @@ dependencies = [ "libc", ] +[[package]] +name = "objc2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-app-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" +dependencies = [ + "bitflags 2.13.2", + "block2", + "libc", + "objc2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-image", + "objc2-core-text", + "objc2-core-video", + "objc2-foundation", + "objc2-quartz-core", +] + +[[package]] +name = "objc2-cloud-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-data" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-foundation", +] + [[package]] name = "objc2-core-foundation" version = "0.3.2" @@ -1882,6 +2406,108 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.13.2", + "dispatch2", + "objc2", +] + +[[package]] +name = "objc2-core-graphics" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" +dependencies = [ + "bitflags 2.13.2", + "dispatch2", + "objc2", + "objc2-core-foundation", + "objc2-io-surface", +] + +[[package]] +name = "objc2-core-image" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-text" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", + "objc2-core-graphics", +] + +[[package]] +name = "objc2-core-video" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-io-surface", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" +dependencies = [ + "bitflags 2.13.2", + "block2", + "libc", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-io-surface" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-uniform-type-identifiers" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7902ac02859fc1f7045f8b598c63f1ae0cc7efeaa06a9bc9f3d9a3c955974fa4" +dependencies = [ + "block2", + "objc2", + "objc2-foundation", ] [[package]] @@ -1992,6 +2618,31 @@ dependencies = [ "libm", ] +[[package]] +name = "pango" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" +dependencies = [ + "gio 0.18.4", + "glib 0.18.5", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" +dependencies = [ + "glib-sys 0.18.1", + "gobject-sys 0.18.0", + "libc", + "system-deps 6.2.2", +] + [[package]] name = "parking_lot" version = "0.12.5" @@ -2155,6 +2806,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + [[package]] name = "plist" version = "1.10.1" @@ -2168,6 +2825,19 @@ dependencies = [ "time", ] +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.8.9", +] + [[package]] name = "portable-atomic" version = "1.15.0" @@ -2219,6 +2889,50 @@ dependencies = [ "wnaf", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +dependencies = [ + "toml_datetime 0.6.3", + "toml_edit 0.20.2", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -2742,6 +3456,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" +dependencies = [ + "serde_core", +] + [[package]] name = "serdect" version = "0.4.3" @@ -2832,6 +3555,12 @@ dependencies = [ "rand_core 0.10.1", ] +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + [[package]] name = "siphasher" version = "1.0.4" @@ -2865,7 +3594,7 @@ dependencies = [ [[package]] name = "squid-cli" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -2885,7 +3614,7 @@ dependencies = [ [[package]] name = "squid-core" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -2897,14 +3626,14 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.21", - "toml", + "toml 0.8.2", "walkdir", "windows 0.58.0", ] [[package]] name = "squid-engine" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -2924,7 +3653,7 @@ dependencies = [ [[package]] name = "squid-guard" -version = "0.1.6" +version = "0.1.7" dependencies = [ "chrono", "hex", @@ -2940,11 +3669,13 @@ dependencies = [ [[package]] name = "squid-platform" -version = "0.1.6" +version = "0.1.7" dependencies = [ "dirs", + "file_icon_provider", "libc", "plist", + "png", "rayon", "serde", "serde_json", @@ -2958,19 +3689,19 @@ dependencies = [ [[package]] name = "squid-rules" -version = "0.1.6" +version = "0.1.7" dependencies = [ "globset", "serde", "serde_json", "squid-core", "squid-platform", - "toml", + "toml 0.8.2", ] [[package]] name = "squid-stats" -version = "0.1.6" +version = "0.1.7" dependencies = [ "chrono", "libc", @@ -2982,7 +3713,7 @@ dependencies = [ [[package]] name = "squid-tui" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -3045,7 +3776,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.119", @@ -3114,12 +3845,44 @@ dependencies = [ "windows 0.57.0", ] +[[package]] +name = "system-deps" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr 0.15.8", + "heck 0.5.0", + "pkg-config", + "toml 0.8.2", + "version-compare", +] + +[[package]] +name = "system-deps" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db551ad38aac61d5e0343e0eeeb0163be3115c4e23b6a025959570ee0c03c67d" +dependencies = [ + "cfg-expr 0.20.10", + "heck 0.5.0", + "pkg-config", + "toml 1.2.1+spec-1.1.0", + "version-compare", +] + [[package]] name = "tap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "target-lexicon" version = "0.13.5" @@ -3301,44 +4064,87 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.23" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" dependencies = [ "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", + "serde_spanned 0.6.9", + "toml_datetime 0.6.3", + "toml_edit 0.20.2", +] + +[[package]] +name = "toml" +version = "1.2.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned 1.1.3", + "toml_datetime 1.1.3+spec-1.1.0", + "toml_parser", + "toml_writer", + "winnow 1.0.5", ] [[package]] name = "toml_datetime" -version = "0.6.11" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + [[package]] name = "toml_edit" -version = "0.22.27" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "toml_write", - "winnow", + "toml_datetime 0.6.3", + "winnow 0.5.40", ] [[package]] -name = "toml_write" -version = "0.1.2" +name = "toml_edit" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap", + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.3", + "winnow 0.5.40", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow 1.0.5", +] + +[[package]] +name = "toml_writer" +version = "1.2.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" [[package]] name = "typenum" @@ -3405,6 +4211,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + [[package]] name = "version_check" version = "0.9.5" @@ -3458,7 +4270,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a9b0525d7ea6e5f906aca581a172e5c91b4c595290dfa8ad4a2bc9ffef33b44" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.119", @@ -3605,7 +4417,7 @@ dependencies = [ "serde", "serde_derive", "smallvec", - "target-lexicon", + "target-lexicon 0.13.5", "wasmparser 0.254.2", "wasmtime-environ", "wasmtime-internal-core", @@ -3641,7 +4453,7 @@ dependencies = [ "serde_derive", "sha2 0.10.9", "smallvec", - "target-lexicon", + "target-lexicon 0.13.5", "wasm-encoder 0.254.2", "wasmparser 0.254.2", "wasmprinter", @@ -3683,7 +4495,7 @@ dependencies = [ "object", "pulley-interpreter", "smallvec", - "target-lexicon", + "target-lexicon 0.13.5", "thiserror 2.0.21", "wasmparser 0.254.2", "wasmtime-environ", @@ -3873,6 +4685,27 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core 0.62.2", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core 0.62.2", +] + [[package]] name = "windows-core" version = "0.57.0" @@ -3911,6 +4744,17 @@ dependencies = [ "windows-strings 0.5.1", ] +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core 0.62.2", + "windows-link", + "windows-threading", +] + [[package]] name = "windows-implement" version = "0.57.0" @@ -3983,6 +4827,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core 0.62.2", + "windows-link", +] + [[package]] name = "windows-result" version = "0.1.2" @@ -4087,6 +4941,15 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -4179,13 +5042,19 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.7.15" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" + [[package]] name = "winreg" version = "0.52.0" @@ -4335,6 +5204,12 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + [[package]] name = "zmij" version = "1.0.23" diff --git a/Cargo.toml b/Cargo.toml index 63d83ae..4490f55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*"] exclude = ["src-tauri"] [workspace.package] -version = "0.1.6" +version = "0.1.7" edition = "2021" rust-version = "1.95" license = "GPL-3.0-only" diff --git a/README.en.md b/README.en.md index 816d075..26e9a7a 100644 --- a/README.en.md +++ b/README.en.md @@ -22,7 +22,7 @@ The desktop app supports macOS 12+ and Windows 10/11 x64. The CLI and TUI share | Feature | Description | | --- | --- | -| Computer overview | Disk health, common actions, and CPU, memory, and storage summaries | +| Overview | Disk health, common actions, and CPU, memory, and storage summaries | | Daily cleanup | 38 built-in rules on macOS and 30 on Windows, covering app and browser caches, logs, crash reports, developer caches, Trash, and more | | Uninstall apps | Finds an app by name and builds one plan containing the app bundle plus preferences, caches, containers, or AppData leftovers | | Deep Clean | Finds rebuildable build output such as `node_modules`, disk images, installers, and stale downloads while protecting recently used projects | @@ -39,7 +39,7 @@ Language settings offer only Simplified Chinese and English, with the current sy ### Sidebar -- **Maintenance**: Computer overview, Daily cleanup, Uninstall apps, Deep Clean +- **Maintenance**: Overview, Daily cleanup, Uninstall apps, Deep Clean - **Protection**: Security, Startup items - **Insights**: Storage, Real-time monitor - **Bottom**: History, Settings diff --git a/README.zh-CN.md b/README.zh-CN.md index 00cbebc..b9d76d0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -22,7 +22,7 @@ Squid 是面向 macOS 与 Windows 的本地系统维护工具:清理可重建 | 功能 | 说明 | | --- | --- | -| 电脑概览 | 磁盘健康、常用操作入口与 CPU、内存、存储摘要 | +| 概览 | 磁盘健康、常用操作入口与 CPU、内存、存储摘要 | | 日常清理 | macOS 38 条 / Windows 30 条内置规则,覆盖应用与浏览器缓存、日志、崩溃报告、开发缓存与废纸篓等 | | 应用卸载 | 按名称定位应用,把应用本体与偏好、缓存、容器或 AppData 残留组成同一个卸载计划 | | 深度清理 | 查找 `node_modules` 等可重建构建产物、磁盘镜像、安装包和陈旧下载,并保护近期仍在使用的项目 | @@ -39,7 +39,7 @@ Squid 是面向 macOS 与 Windows 的本地系统维护工具:清理可重建 ### 左侧菜单 -- **维护**:电脑概览、日常清理、应用卸载、深度清理 +- **维护**:概览、日常清理、应用卸载、深度清理 - **保护**:安全、启动项 - **洞察**:存储空间、实时监控 - **底部**:历史记录、设置 diff --git a/crates/squid-core/src/model.rs b/crates/squid-core/src/model.rs index fcc2e03..9988a37 100644 --- a/crates/squid-core/src/model.rs +++ b/crates/squid-core/src/model.rs @@ -358,6 +358,10 @@ pub struct AppInfo { pub name: String, pub bundle_id: Option, pub path: PathBuf, + /// The file or bundle the desktop icon is read from. `path` may be an + /// install directory or an uninstall helper, neither of which carries the + /// icon the user recognises. + pub icon_source: Option, pub version: Option, pub size: Bytes, /// Where the app was found: /Applications, ~/Applications, Homebrew Cask… diff --git a/crates/squid-engine/src/uninstall.rs b/crates/squid-engine/src/uninstall.rs index 8361d98..c9ef8ea 100644 --- a/crates/squid-engine/src/uninstall.rs +++ b/crates/squid-engine/src/uninstall.rs @@ -464,6 +464,7 @@ mod tests { name: "Demo".into(), bundle_id: Some("com.example.Demo".into()), path: PathBuf::from(path), + icon_source: None, version: Some("1.0".into()), size: Bytes(1_000), source: source.into(), diff --git a/crates/squid-platform/Cargo.toml b/crates/squid-platform/Cargo.toml index aa6e05c..b42260a 100644 --- a/crates/squid-platform/Cargo.toml +++ b/crates/squid-platform/Cargo.toml @@ -32,3 +32,7 @@ windows-sys = { version = "0.59", features = [ "Win32_Security_WinTrust", "Win32_System_Threading", ] } + +[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] +file_icon_provider = "1.0.2" +png = "0.17" diff --git a/crates/squid-platform/src/apps.rs b/crates/squid-platform/src/apps.rs index 5647a28..d10b1f9 100644 --- a/crates/squid-platform/src/apps.rs +++ b/crates/squid-platform/src/apps.rs @@ -111,6 +111,7 @@ pub fn app_from_bundle( name, bundle_id: bundle.bundle_id.clone(), path: path.clone(), + icon_source: Some(path.clone()), version: bundle .short_version .clone() @@ -142,6 +143,32 @@ pub fn app_from_bundle( Some(app) } +/// Render an application's system icon as PNG bytes. +/// +/// macOS and Windows let the file manager do the work, so the result is the +/// same icon Finder or Explorer shows, including HiDPI-safe source artwork. +/// Linux has no equivalent without a GTK dependency; the desktop falls back to +/// the app's initial. +#[cfg(any(target_os = "macos", target_os = "windows"))] +pub fn icon_png(app: &AppInfo, size: u16) -> Option> { + let source = app.icon_source.as_ref()?; + let icon = file_icon_provider::get_file_icon(source, size).ok()?; + let mut output = Vec::new(); + { + let mut encoder = png::Encoder::new(&mut output, icon.width, icon.height); + encoder.set_color(png::ColorType::Rgba); + encoder.set_depth(png::BitDepth::Eight); + let mut writer = encoder.write_header().ok()?; + writer.write_image_data(&icon.pixels).ok()?; + } + Some(output) +} + +#[cfg(not(any(target_os = "macos", target_os = "windows")))] +pub fn icon_png(_app: &AppInfo, _size: u16) -> Option> { + None +} + /// Match "is this app running" against the process executable list. pub fn is_running(dir_name: &str, executable: Option<&str>, running: &[String]) -> bool { let mut candidates: Vec = Vec::with_capacity(3); @@ -167,3 +194,20 @@ pub fn stem_lower(path: &Path) -> String { .map(|n| n.to_string_lossy().trim_end_matches(".app").to_lowercase()) .unwrap_or_default() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[cfg(any(target_os = "macos", target_os = "windows"))] + fn a_system_icon_is_encoded_as_png() { + let app = AppInfo { + name: "Squid".into(), + icon_source: std::env::current_exe().ok(), + ..Default::default() + }; + let png = icon_png(&app, 32).expect("the running executable has a system icon"); + assert_eq!(&png[..8], b"\x89PNG\r\n\x1a\n"); + } +} diff --git a/crates/squid-platform/src/lib.rs b/crates/squid-platform/src/lib.rs index 7f6e138..5d12400 100644 --- a/crates/squid-platform/src/lib.rs +++ b/crates/squid-platform/src/lib.rs @@ -108,6 +108,10 @@ pub trait Platform: Send + Sync { fn display_name(&self) -> String; fn os_version(&self) -> String; fn hardware_model(&self) -> String; + /// Display adapter(s), when the platform exposes a stable name. + fn graphics_adapter(&self) -> String { + String::new() + } /// Directories to scan for installed applications. fn app_sources(&self) -> Vec; diff --git a/crates/squid-platform/src/linux.rs b/crates/squid-platform/src/linux.rs index 93ea2a0..98716a9 100644 --- a/crates/squid-platform/src/linux.rs +++ b/crates/squid-platform/src/linux.rs @@ -112,6 +112,29 @@ impl Platform for Linux { .to_string() } + fn graphics_adapter(&self) -> String { + run("lspci", &[]) + .map(|text| { + text.lines() + .filter(|line| { + line.contains("VGA compatible controller") + || line.contains("3D controller") + || line.contains("Display controller") + }) + .filter_map(|line| line.split_once(": ").map(|(_, value)| value.trim())) + .map(|value| { + value + .split_once(": ") + .map(|(_, name)| name.trim()) + .unwrap_or(value) + .to_string() + }) + .collect::>() + .join(" · ") + }) + .unwrap_or_default() + } + fn app_sources(&self) -> Vec { [ ("/usr/share/applications", "System", 1, true), @@ -193,6 +216,7 @@ impl Platform for Linux { name: desktop.name.clone(), bundle_id: Some(id.clone()), path: path.clone(), + icon_source: None, version: None, size: Bytes::ZERO, source: source.label.clone(), @@ -222,6 +246,7 @@ impl Platform for Linux { .unwrap_or_else(|| id.to_string()), bundle_id: Some(id.to_string()), path: PathBuf::from(format!("flatpak:{id}")), + icon_source: None, version: None, size: cols .get(2) diff --git a/crates/squid-platform/src/macos.rs b/crates/squid-platform/src/macos.rs index e33f505..7b56f59 100644 --- a/crates/squid-platform/src/macos.rs +++ b/crates/squid-platform/src/macos.rs @@ -74,6 +74,25 @@ impl Platform for MacOs { parts.join(" · ") } + fn graphics_adapter(&self) -> String { + run( + "/usr/sbin/system_profiler", + &["SPDisplaysDataType", "-detailLevel", "mini"], + ) + .map(|text| { + text.lines() + .filter_map(|line| { + line.trim() + .strip_prefix("Chipset Model:") + .map(|value| value.trim().to_string()) + .filter(|value| !value.is_empty()) + }) + .collect::>() + .join(" · ") + }) + .unwrap_or_default() + } + fn app_sources(&self) -> Vec { let mut sources = vec![ AppSource { diff --git a/crates/squid-platform/src/process_table.rs b/crates/squid-platform/src/process_table.rs index a39532b..1fdf21d 100644 --- a/crates/squid-platform/src/process_table.rs +++ b/crates/squid-platform/src/process_table.rs @@ -17,6 +17,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use sysinfo::{ProcessRefreshKind, ProcessesToUpdate, RefreshKind, System, Users}; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct ProcessRow { pub pid: u32, pub parent: Option, diff --git a/crates/squid-platform/src/startup.rs b/crates/squid-platform/src/startup.rs index d9525ef..759a6c0 100644 --- a/crates/squid-platform/src/startup.rs +++ b/crates/squid-platform/src/startup.rs @@ -7,6 +7,10 @@ //! default: every entry says whether squid may change it, and the ones it may //! not say why in the same field the UI shows. //! +//! Entries are also attributed to the application that installed them, because +//! nobody reads 800 plist labels: both operating systems show this list per app, +//! and `StartupOwner` is what makes that possible without guessing. +//! //! Disabling an entry means renaming its plist to `*.plist.disabled` on macOS //! and moving its registry value into a sibling backup key on Windows. Both are //! reversible without a privileged helper, which is the whole point: squid never @@ -63,6 +67,9 @@ pub enum StartupRisk { InTempDir, /// The target exists but carries no usable code signature. Unsigned, + /// The target is not readable by this user, so its signature was never asked + /// about. Different from `Unsigned`, which is an answer and an accusation. + SignatureUnreadable, /// Started through a script interpreter rather than a binary. ScriptInterpreter, /// Created within the last fortnight. @@ -73,7 +80,66 @@ pub enum StartupRisk { HiddenHomeDirectory, } +/// Which of the two lists the operating systems themselves show an entry +/// belongs to. macOS splits "Login Items" (apps that open when you log in) from +/// "Allow in the Background" (helpers that keep running); Windows splits the +/// Startup folder and Run keys from scheduled tasks and services. A page that +/// shows one flat list of 800 labels answers neither question. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum StartupCategory { + /// Opens an application or window at login: a login item, a Startup folder + /// shortcut, or a Run value that launches an app. + OpenAtLogin, + /// A helper that keeps running without a window: LaunchAgents and + /// LaunchDaemons, scheduled tasks, services. + Background, +} + +impl StartupCategory { + pub fn as_str(self) -> &'static str { + match self { + StartupCategory::OpenAtLogin => "open-at-login", + StartupCategory::Background => "background", + } + } +} + +/// Why squid will not change an entry. A typed answer rather than a sentence +/// from the platform layer, because the platform layer does not know which +/// language the page is wearing; each variant becomes one short localised phrase. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum StartupLock { + /// Apple's or Microsoft's own entry. + OperatingSystem, + /// Root-owned plist, HKLM value, system task or service: one authorisation away. + NeedsAuthorisation, + /// The declaring file or folder is not writable by this user. + NotWritable, + /// macOS owns the login-item list and changes it through System Settings. + ManagedBySystemSettings, + /// This release reports these entries and leaves them alone. + NotManaged, +} + +/// The application an entry belongs to, worked out from the paths launchd or the +/// registry name, never from the entry's label. This is what lets the list be +/// "Docker · 3 background items" instead of three opaque plist names. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StartupOwner { + /// The name to show the user: the bundle's `CFBundleDisplayName`, or the + /// application folder name when the bundle cannot be read. + pub name: String, + /// The `.app` bundle, or the directory the entry lives in. + pub bundle_path: Option, + /// True when the owning application is Apple's or Microsoft's own. + pub vendor: bool, +} + #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct StartupItem { /// Stable identifier: the plist path, registry value, task path or service. pub id: String, @@ -91,12 +157,17 @@ pub struct StartupItem { /// An entry the operating system vendor owns. pub system_vendor: bool, pub disabled: bool, - /// False means squid will refuse to touch it, with `readonly_reason`. + /// False means squid will refuse to touch it, and `lock` says which kind of + /// refusal it is. pub modifiable: bool, - pub readonly_reason: Option, + pub lock: Option, pub hidden: bool, pub modified_ms: Option, pub risks: Vec, + /// Which list of the operating system's own this entry would appear in. + pub category: StartupCategory, + /// The application that installed the entry, when one could be named. + pub owner: Option, } impl StartupItem { @@ -124,20 +195,66 @@ impl StartupItem { system_vendor: false, disabled: false, modifiable: false, - readonly_reason: None, + lock: None, hidden: false, modified_ms: None, risks: Vec::new(), + category: StartupCategory::Background, + owner: None, } } } /// Everything squid could read. Unreadable folders are simply absent, and the -/// notes say which roots could not be listed. +/// notes say which ones and why. #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct StartupInventory { pub items: Vec, - pub notes: Vec, + pub notes: Vec, +} + +/// Something the page has to admit it could not read. `kind` is typed rather than +/// a sentence, because the platform layer does not know whether the page is +/// wearing Chinese or English; a note that arrives already translated is a note +/// that arrives in the wrong language. `detail` carries the operating system's own +/// words beside it, which are never translated and are therefore honest. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StartupNote { + pub kind: StartupNoteKind, + /// The folder, tool or list this note is about. + pub subject: String, + pub detail: String, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum StartupNoteKind { + /// A folder holding entries that could not be listed. + UnreadableRoot, + /// The login-item list could not be read at all, which on macOS means the + /// automation permission has not been granted. + LoginItemsUnavailable, +} + +/// The command line speaks English, so it prints the note whole; the GUI reads +/// `kind` and translates it. One fact, two honest renderings. +impl std::fmt::Display for StartupNote { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.kind { + StartupNoteKind::UnreadableRoot => { + write!(formatter, "{} could not be listed", self.subject)?; + } + StartupNoteKind::LoginItemsUnavailable => { + write!(formatter, "login items could not be read")?; + } + } + if self.detail.is_empty() { + Ok(()) + } else { + write!(formatter, ": {}", self.detail) + } + } } impl StartupInventory { @@ -215,6 +332,11 @@ pub fn entry_for(program: &Path) -> Option { } } +/// What a refused change says. The reason itself is shown from `StartupLock`, +/// which the page can translate; this is only what the command returns when the +/// inventory it was given has already gone stale. +const LOCK_REFUSAL: &str = "Squid cannot change this entry."; + pub fn home_dir() -> PathBuf { dirs::home_dir().unwrap_or_else(|| PathBuf::from("/")) } @@ -236,7 +358,8 @@ fn now_ms() -> u64 { const RECENT_MS: u64 = 14 * 24 * 60 * 60 * 1000; -/// Judges one resolved program: signature, freshness, and where it lives. +/// Judges one resolved program: freshness and where it lives. The signature half +/// is deliberately not here — see `apply_trust`. fn judge_program(item: &mut StartupItem, program: Option<&Path>) { let Some(program) = program else { return; @@ -286,8 +409,29 @@ fn judge_program(item: &mut StartupItem, program: Option<&Path>) { item.risks.push(StartupRisk::ScriptInterpreter); } } +} - let trust = crate::trust::assess(program); +/// The signature half of the judgement, kept apart from `judge_program` because +/// on macOS it costs one `codesign` process per entry. An M1 Pro has ~870 startup +/// entries, 845 of which Apple owns and nobody is going to inspect, so assessing +/// all of them took 8 s to answer a question about 25. Entries whose target is +/// gone are not assessed either: "not there" is already the finding. +fn apply_trust(item: &mut StartupItem) { + if item.system_vendor || item.risks.contains(&StartupRisk::MissingTarget) { + return; + } + let Some(program) = item.program.clone() else { + return; + }; + // A root-owned helper installed mode 0711 — `/Library/PrivilegedHelperTools/ + // com.docker.socket`, for one — can be run and cannot be read, and `codesign` + // answers that with "Permission denied". Reporting it as *unsigned* would be a + // false accusation against a program that is signed and merely private. + if !program.is_dir() && std::fs::File::open(&program).is_err() { + item.risks.push(StartupRisk::SignatureUnreadable); + return; + } + let trust = crate::trust::assess(&program); item.signed = trust.signed; item.publisher = trust.signer.clone(); if !trust.signed { @@ -295,6 +439,382 @@ fn judge_program(item: &mut StartupItem, program: Option<&Path>) { } } +/// The `.app` bundle an entry belongs to, found in the path launchd will run. +/// macOS nests helpers inside the bundle that owns them, which is why this works +/// without asking Launch Services anything. +#[cfg(target_os = "macos")] +fn bundle_owning(path: &Path) -> Option { + let mut current = Some(path); + while let Some(candidate) = current { + if candidate.to_string_lossy().to_lowercase().ends_with(".app") { + return Some(candidate.to_path_buf()); + } + current = candidate.parent(); + } + None +} + +/// The installed applications, keyed by bundle id. +/// +/// A helper installed in `/Library/PrivilegedHelperTools` says nothing about its +/// owner in its path, but launchd's convention is that its label begins with the +/// bundle id of the app that installed it. Checking that against what is actually +/// installed is a lookup rather than a guess: `com.docker.socket` is Docker's +/// because `com.docker.*` belongs to exactly one installed application. +#[cfg(target_os = "macos")] +#[derive(Default)] +struct AppIndex { + by_id: std::collections::BTreeMap, +} + +#[cfg(target_os = "macos")] +impl AppIndex { + fn scan() -> AppIndex { + let mut out = AppIndex::default(); + let roots = [ + PathBuf::from("/Applications"), + home_dir().join("Applications"), + PathBuf::from("/System/Applications"), + PathBuf::from("/System/Library/CoreServices"), + ]; + for root in roots { + let Ok(entries) = std::fs::read_dir(&root) else { + continue; + }; + for entry in entries.flatten() { + let path = entry.path(); + if !path.to_string_lossy().ends_with(".app") { + continue; + } + let Some(info) = bundle_info(&path) else { + continue; + }; + out.by_id.entry(info.0).or_insert(StartupOwner { + name: info.1, + bundle_path: Some(path.clone()), + vendor: root.starts_with("/System"), + }); + } + } + out + } + + /// The longest bundle-id prefix of `label` that one installed app owns. + fn owner_of(&self, label: &str) -> Option { + let mut parts: Vec = label + .to_lowercase() + .split('.') + .map(|part| part.to_string()) + .collect(); + // The shortest usable prefix has two components. `org` on its own is a + // registry suffix, not a vendor, and stopping there matched + // `org.wireshark.ChmodBPF` to the only `org.*` application installed. + while parts.len() > 2 { + parts.pop(); + let prefix = parts.join("."); + let matches: Vec<&StartupOwner> = self + .by_id + .range(prefix.clone()..) + .take_while(|(id, _)| *id == &prefix || id.starts_with(&format!("{prefix}."))) + .map(|(_, owner)| owner) + .collect(); + // Only claim it when a single application is in the family; two + // installers sharing a vendor prefix is a tie, and a tie is a guess. + if matches.len() == 1 { + return Some(matches[0].clone()); + } + if matches.len() > 1 { + break; + } + } + None + } +} + +/// The bundle id and display name an `.app` declares for itself. +#[cfg(target_os = "macos")] +fn bundle_info(bundle: &Path) -> Option<(String, String)> { + let dict = plist::Value::from_file(bundle.join("Contents/Info.plist")) + .ok()? + .into_dictionary()?; + let id = dict + .get("CFBundleIdentifier") + .and_then(|value| value.as_string())? + .to_lowercase(); + let name = ["CFBundleDisplayName", "CFBundleName"] + .iter() + .find_map(|key| dict.get(key).and_then(|value| value.as_string())) + .map(str::to_string) + .or_else(|| { + bundle + .file_stem() + .map(|stem| stem.to_string_lossy().into_owned()) + })?; + Some((id, name)) +} + +/// Name the application every entry belongs to. +/// +/// macOS nests helpers inside the `.app` that installed them, so the path usually +/// answers it; where it does not, the entry's launchd label is matched against the +/// bundle ids of the applications that are actually installed. Windows has no such +/// nesting, so the install folder under Program Files carries the name. An entry +/// that still names nothing stays ungrouped rather than being filed under a guess. +#[cfg(target_os = "macos")] +fn attribute_owners(items: &mut [StartupItem]) { + let mut index: Option = None; + for item in items { + if item.system_vendor { + continue; + } + let bundle = item + .program + .clone() + .or_else(|| { + (item.id.contains('/') || item.id.ends_with(".app")) + .then(|| PathBuf::from(&item.id)) + }) + .as_deref() + .and_then(bundle_owning); + if let Some(bundle) = bundle { + let vendor = bundle.starts_with("/System"); + let name = bundle_info(&bundle) + .map(|(_, name)| name) + .unwrap_or_else(|| { + bundle + .file_stem() + .map(|stem| stem.to_string_lossy().into_owned()) + .unwrap_or_else(|| bundle.display().to_string()) + }); + item.owner = Some(StartupOwner { + name, + bundle_path: Some(bundle), + vendor, + }); + continue; + } + // Nothing in the path names an application: a helper in + // `/Library/PrivilegedHelperTools`, or an entry whose target is gone. + let label = item + .id + .rsplit('/') + .next() + .unwrap_or(&item.id) + .trim_end_matches(".plist") + .trim_end_matches(".disabled"); + let index = index.get_or_insert_with(AppIndex::scan); + if let Some(owner) = index.owner_of(label) { + item.owner = Some(owner); + continue; + } + // The signing organisation is the last honest answer, and it is the same + // one System Settings groups background items by. + if let Some(organisation) = item.publisher.as_deref().and_then(organisation_of) { + item.owner = Some(StartupOwner { + name: organisation, + bundle_path: None, + vendor: false, + }); + } + } +} + +/// `Developer ID Application: Docker Inc (9P49FL5KQ8)` to `Docker Inc`. +#[cfg(target_os = "macos")] +fn organisation_of(signer: &str) -> Option { + let tail = signer.rsplit(": ").next().unwrap_or(signer); + let name = tail.split(" (").next().unwrap_or(tail).trim(); + (!name.is_empty() && name != "not set").then(|| name.to_string()) +} + +#[cfg(windows)] +fn attribute_owners(items: &mut [StartupItem]) { + for item in items { + if item.system_vendor { + continue; + } + let Some(program) = item.program.as_deref() else { + continue; + }; + // The publisher the Authenticode signature names is what Control Panel and + // Task Manager both show, so it leads where the folder is a vendor directory. + if let Some(name) = item + .publisher + .as_deref() + .and_then(organisation_of) + .or_else(|| install_folder_owning(program)) + { + item.owner = Some(StartupOwner { + name, + bundle_path: None, + vendor: false, + }); + } + } +} + +/// `CN = "Microsoft Corporation"` and `Microsoft Corporation` to one name. +#[cfg(windows)] +fn organisation_of(signer: &str) -> Option { + let tail = signer.rsplit('=').next().unwrap_or(signer); + let name = tail.trim_matches(|c| c == '"' || c == '\'').trim(); + (!name.is_empty()).then(|| name.to_string()) +} + +/// The folder under Program Files that holds one executable, which is the unit +/// Windows itself groups installed programs by. +#[cfg(windows)] +fn install_folder_owning(program: &Path) -> Option { + let text = program.to_string_lossy(); + // Located without regard to case, then cut out of the original: the folder is + // shown to the user, and `MOZILLA firefox` is not what it is called. + let start = text.to_lowercase().find("program files")? + "program files".len(); + let mut parts = text[start..] + .split(['\\', '/']) + .filter(|part| !part.trim().is_empty()); + // ` (x86)` is part of the root, not a product, so the one folder after it is + // the vendor or product a person would recognise. + let first = parts.next()?; + let name = if first.trim_start().starts_with('(') { + parts.next()? + } else { + first + }; + (!name.trim().is_empty()).then(|| name.trim().to_string()) +} + +/// What the operating system shows an entry under. Both platforms keep the same +/// two lists — the things that open a window when you log in, and the helpers +/// that run behind it — so the entry's own source decides it. +fn categorise(item: &mut StartupItem) { + item.category = match item.source { + StartupSource::LoginItem | StartupSource::StartupFolder | StartupSource::RegistryRun => { + StartupCategory::OpenAtLogin + } + _ => StartupCategory::Background, + }; +} + +#[cfg(test)] +mod attribution_tests { + use super::*; + + /// The helper in `/Library/PrivilegedHelperTools` is named after nobody: its + /// path says where helpers live, not who installed it. Its label is matched + /// against installed bundle ids instead, which is honest only while exactly one + /// application owns the family. + #[test] + #[cfg(target_os = "macos")] + fn a_helper_is_claimed_only_by_an_unambiguous_bundle_family() { + let owner = |name: &str| StartupOwner { + name: name.to_string(), + bundle_path: None, + vendor: false, + }; + let index = AppIndex { + by_id: [ + ("com.docker.docker".to_string(), owner("Docker")), + ( + "com.apphousekitchen.aldente-pro".to_string(), + owner("AlDente"), + ), + ("org.geogebra6.mac".to_string(), owner("GeoGebra")), + ] + .into_iter() + .collect(), + }; + assert_eq!( + index.owner_of("com.docker.socket").map(|o| o.name), + Some("Docker".into()) + ); + assert_eq!( + index + .owner_of("com.apphousekitchen.aldente-pro.helper") + .map(|o| o.name), + Some("AlDente".into()) + ); + // `org` on its own is a registry suffix, not a vendor. Without that bound + // `org.wireshark.ChmodBPF` was matched to the only `org.*` app installed. + assert_eq!(index.owner_of("org.wireshark.ChmodBPF"), None); + assert_eq!(index.owner_of("us.zoom.ZoomDaemon"), None); + + // Two applications in one family is a tie, and a tie is not an answer. + let tied = AppIndex { + by_id: [ + ("com.google.chrome".to_string(), owner("Chrome")), + ("com.google.keystone".to_string(), owner("Keystone")), + ] + .into_iter() + .collect(), + }; + // Where a prefix names one application exactly, that is the answer even + // though a shallower prefix would be a tie. + assert_eq!( + tied.owner_of("com.google.keystone.agent").map(|o| o.name), + Some("Keystone".into()) + ); + assert_eq!( + tied.owner_of("com.google.Chrome.helper").map(|o| o.name), + Some("Chrome".into()), + "the deeper prefix that does resolve is still used" + ); + assert_eq!( + tied.owner_of("com.google.SomeUpdater"), + None, + "the only prefix left is a tie between two applications, so nothing is claimed" + ); + } + + #[test] + #[cfg(windows)] + fn a_program_files_path_names_the_product_folder() { + assert_eq!( + install_folder_owning(Path::new( + r"C:\Program Files\Google\Chrome\Application\chrome.exe" + )), + Some("Google".into()) + ); + // ` (x86)` belongs to the root, so the product is the folder after it. + assert_eq!( + install_folder_owning(Path::new( + r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + )), + Some("Mozilla Firefox".into()) + ); + assert_eq!( + install_folder_owning(Path::new( + r"C:\program files (x86)\MOZILLA Firefox\firefox.exe" + )), + Some("MOZILLA Firefox".into()), + "found without regard to case, shown exactly as the folder is named" + ); + assert_eq!( + install_folder_owning(Path::new(r"D:\tools\bin\thing.exe")), + None + ); + } + + #[test] + fn an_entry_goes_to_the_list_its_source_declares() { + let mut login = StartupItem::new( + "login-item://Docker", + "Docker", + StartupSource::LoginItem, + StartupScope::User, + ); + let mut daemon = StartupItem::new( + "/Library/LaunchDaemons/com.docker.vmnetd.plist", + "com.docker.vmnetd", + StartupSource::LaunchDaemon, + StartupScope::System, + ); + categorise(&mut login); + categorise(&mut daemon); + assert_eq!(login.category, StartupCategory::OpenAtLogin); + assert_eq!(daemon.category, StartupCategory::Background); + } +} + /// True when the path lives in a dot-directory directly under home, which is /// where updaters and helpers that nobody installed tend to sit. fn in_hidden_home_dir(program: &Path) -> bool { @@ -309,6 +829,24 @@ fn in_hidden_home_dir(program: &Path) -> bool { .unwrap_or(false) } +/// What happens to every entry once both platforms have finished collecting them. +/// +/// Trust comes first because an entry whose path names no application is filed +/// under whoever signed it, and that is only known once the signature has been +/// asked about. On macOS that question costs one `codesign` process per entry, so +/// it is asked in parallel: ~870 sequential calls took 8 s on an M1 Pro, and the +/// same calls across the available cores take under 1 s. +fn finish(items: &mut [StartupItem]) { + use rayon::prelude::*; + + items.par_iter_mut().for_each(apply_trust); + attribute_owners(items); + for item in items.iter_mut() { + categorise(item); + } + sort_items(items); +} + /// Order user-owned entries first; inside a scope, alphabetically. fn sort_items(items: &mut [StartupItem]) { items.sort_by(|a, b| { @@ -369,10 +907,11 @@ mod macos { Ok(entries) => entries, Err(error) => { if error.kind() != std::io::ErrorKind::NotFound { - out.notes.push(format!( - "{} could not be listed: {error}", - root.dir.display() - )); + out.notes.push(StartupNote { + kind: StartupNoteKind::UnreadableRoot, + subject: root.dir.display().to_string(), + detail: error.to_string(), + }); } continue; } @@ -395,8 +934,8 @@ mod macos { } } } - out.items.extend(login_items()); - sort_items(&mut out.items); + out.items.extend(login_items(&mut out.notes)); + finish(&mut out.items); out } @@ -443,16 +982,16 @@ mod macos { /// entries Apple owns: a hundred unsigned system agents is not a signal. fn classify(item: &mut StartupItem, path: &Path, scope: StartupScope) { if item.system_vendor { - item.readonly_reason = Some("part of macOS".into()); + item.lock = Some(StartupLock::OperatingSystem); item.risks.clear(); } else if scope == StartupScope::System { - item.readonly_reason = Some("requires an administrator authorisation".into()); + item.lock = Some(StartupLock::NeedsAuthorisation); } else { let writable = crate::is_user_writable(path) && crate::is_user_writable(path.parent().unwrap_or(path)); item.modifiable = writable; if !writable { - item.readonly_reason = Some("this file is not owned by you".into()); + item.lock = Some(StartupLock::NotWritable); } } } @@ -491,71 +1030,125 @@ mod macos { .unwrap_or(expanded) } - /// The login-item database macOS still maintains beside the modern - /// per-app setting. Reading it costs one file scan; changing it belongs to - /// System Settings, so these entries are reported read-only. - fn login_items() -> Vec { - let path = home_dir().join( - "Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm", - ); + /// What System Settings shows under "Open at Login". + /// + /// Asking System Events rather than parsing a file is the point: the list is + /// maintained by backgroundtaskmanagement, its on-disk archive is a keychain + /// of security-scoped bookmarks that only root can resolve, and the one + /// readable copy in the home folder held 9 of the 30 groups the panel shows. + /// System Events *is* the panel's own view, so the two cannot disagree. + /// + /// Changing an entry still belongs to System Settings — the scriptable + /// `delete` is unreliable across macOS versions — so every row is reported + /// with its lock rather than with a toggle that might not hold. + fn login_items(notes: &mut Vec) -> Vec { + let script = "tell application \"System Events\"\n\ + set collected to {}\n\ + repeat with anItem in (every login item)\n\ + set theName to \"\"\n\ + try\n\ + set theName to name of anItem\n\ + end try\n\ + set thePath to \"\"\n\ + try\n\ + set thePath to (path of anItem) as text\n\ + end try\n\ + set hiddenFlag to false\n\ + try\n\ + set hiddenFlag to (hidden of anItem)\n\ + end try\n\ + set end of collected to theName & tab & thePath & tab & (hiddenFlag as text)\n\ + end repeat\n\ + set AppleScript's text item delimiters to linefeed\n\ + return collected as text\n\ + end tell"; + let output = match std::process::Command::new("osascript") + .args(["-e", script]) + .output() + { + Ok(output) if output.status.success() => { + String::from_utf8_lossy(&output.stdout).into_owned() + } + Ok(output) => { + let reason = String::from_utf8_lossy(&output.stderr).trim().to_string(); + notes.push(StartupNote { + kind: StartupNoteKind::LoginItemsUnavailable, + subject: String::new(), + detail: if reason.is_empty() { + "osascript failed".into() + } else { + reason + }, + }); + return Vec::new(); + } + Err(error) => { + notes.push(StartupNote { + kind: StartupNoteKind::LoginItemsUnavailable, + subject: String::new(), + detail: error.to_string(), + }); + return Vec::new(); + } + }; + + parse_login_items(&output) + } + + /// Turn the script's report into entries. One line per item, tab-separated: + /// name, path, and whether it launches hidden. + pub(super) fn parse_login_items(output: &str) -> Vec { let mut items = Vec::new(); - for found in printable_paths(&path, 8) { - if !found.contains("/Applications/") && !found.starts_with("/Library/") { + for line in output + .lines() + .map(str::trim) + .filter(|line| !line.is_empty()) + { + let mut fields = line.split('\t'); + let name = fields.next().unwrap_or_default().trim(); + if name.is_empty() { continue; } - let label = Path::new(&found) - .file_name() - .map(|name| name.to_string_lossy().trim_end_matches(".app").to_string()) - .unwrap_or_else(|| found.clone()); + // System Events reports `missing value` for an item whose file is + // gone, which is the interesting case rather than a reason to drop it. + let path = fields.next().unwrap_or_default().trim(); + let path = if path.is_empty() || path == "missing value" { + String::new() + } else { + path.to_string() + }; + let hidden = fields.next().unwrap_or_default().trim() == "true"; let mut item = StartupItem::builder( - found.clone(), - label, + format!("login-item://{name}"), + name.to_string(), StartupSource::LoginItem, StartupScope::User, ); - item.command = found.clone(); - judge_program(&mut item, Some(Path::new(&found))); - item.readonly_reason = Some("login items are managed in System Settings".into()); + // Left empty rather than filled with the name: repeating the name under + // itself says nothing, and the page can say what is actually true. + item.command = path.clone(); + item.hidden = hidden; + judge_program( + &mut item, + (!path.is_empty()).then(|| Path::new(path.as_str())), + ); + if hidden { + item.risks.push(StartupRisk::HiddenEntry); + } + item.modifiable = false; + item.lock = Some(StartupLock::ManagedBySystemSettings); items.push(item); } items } - /// Pull printable absolute paths out of a binary archive without a parser. - fn printable_paths(path: &Path, minimum: usize) -> Vec { - let Ok(bytes) = std::fs::read(path) else { - return Vec::new(); - }; - let mut found = Vec::new(); - let mut current = String::new(); - for byte in bytes { - if byte.is_ascii_graphic() || byte == b' ' { - current.push(byte as char); - } else { - if current.len() >= minimum && current.starts_with('/') { - found.push(current.clone()); - } - current.clear(); - } - } - if current.len() >= minimum && current.starts_with('/') { - found.push(current); - } - found.sort(); - found.dedup(); - found - } - pub fn set_enabled(id: &str, enabled: bool) -> Result { let current = inventory(); let item = current .find(id) .ok_or_else(|| "That startup item is no longer there.".to_string())?; if !item.modifiable { - return Err(item - .readonly_reason - .clone() - .unwrap_or_else(|| "Squid cannot change this item.".into())); + return Err(LOCK_REFUSAL.to_string()); } let path = PathBuf::from(id); let to = if enabled { @@ -680,6 +1273,54 @@ mod tests { path } + #[test] + fn a_login_item_report_becomes_entries_that_cannot_be_touched() { + // The shape System Events answers with: name, path, hidden. Nothing about a + // real machine is assumed, so the three rows are a bundle that is there, one + // that is gone, and the `missing value` an item whose file vanished is + // reported as. Dropping the last two would hide the entries worth seeing. + let f = fixture("loginitems"); + let present = f.home.join("Keeper.app"); + std::fs::create_dir_all(&present).expect("bundle"); + let gone = f.home.join("Uninstalled.app"); + let report = format!( + "Keeper\t{}\tfalse\nUninstalled\t{}\tfalse\nDoubao\tmissing value\ttrue\n", + present.display(), + gone.display() + ); + + let mut items = macos::parse_login_items(&report); + assert_eq!(items.len(), 3); + // Which list an entry belongs to is settled once, over the whole inventory, + // by the same step the real inventory runs. + for item in &mut items { + categorise(item); + } + + for item in &items { + assert_eq!(item.source, StartupSource::LoginItem); + assert_eq!(item.scope, StartupScope::User); + assert_eq!(item.category, StartupCategory::OpenAtLogin); + assert!(!item.modifiable, "macOS owns this list"); + assert_eq!(item.lock, Some(StartupLock::ManagedBySystemSettings)); + assert_eq!(item.id, format!("login-item://{}", item.name)); + } + + assert_eq!(items[0].program.as_deref(), Some(present.as_path())); + assert!( + items[1].risks.contains(&StartupRisk::MissingTarget), + "an entry pointing at nothing says so rather than disappearing" + ); + + let vanished = &items[2]; + assert!( + vanished.command.is_empty(), + "a name is not a path, and repeating one under the other says nothing" + ); + assert!(vanished.hidden); + assert!(vanished.risks.contains(&StartupRisk::HiddenEntry)); + } + #[test] fn a_user_agent_is_listed_with_the_program_it_runs() { let f = fixture("listed"); @@ -860,8 +1501,7 @@ mod windows { program_of_command(&command).as_deref().map(Path::new), ); if scope == StartupScope::System { - item.readonly_reason = - Some("requires an administrator authorisation".into()); + item.lock = Some(StartupLock::NeedsAuthorisation); } else { item.modifiable = true; } @@ -903,11 +1543,11 @@ mod windows { item.modified_ms = modified_ms(&path); judge_program(&mut item, Some(&path)); if scope == StartupScope::System { - item.readonly_reason = Some("requires an administrator authorisation".into()); + item.lock = Some(StartupLock::NeedsAuthorisation); } else { item.modifiable = crate::is_user_writable(&folder); if !item.modifiable { - item.readonly_reason = Some("this folder is not writable".into()); + item.lock = Some(StartupLock::NotWritable); } } out.items.push(item); @@ -917,7 +1557,7 @@ mod windows { out.items.extend(parked_entries()); out.items.extend(scheduled_tasks()); out.items.extend(services()); - sort_items(&mut out.items); + finish(&mut out.items); out } @@ -978,7 +1618,7 @@ mod windows { ); item.modifiable = hive_name == "HKCU"; if !item.modifiable { - item.readonly_reason = Some("requires an administrator authorisation".into()); + item.lock = Some(StartupLock::NeedsAuthorisation); } items.push(item); } @@ -1058,7 +1698,7 @@ mod windows { if item.system_vendor { item.risks.clear(); } - item.readonly_reason = Some("scheduled tasks are read-only in this release".into()); + item.lock = Some(StartupLock::NotManaged); items.push(item); } items @@ -1152,7 +1792,7 @@ mod windows { if item.system_vendor { item.risks.clear(); } - item.readonly_reason = Some("services are read-only in this release".into()); + item.lock = Some(StartupLock::NotManaged); items.push(item); } items @@ -1180,10 +1820,7 @@ mod windows { .cloned() .ok_or_else(|| "That startup item is no longer there.".to_string())?; if !item.modifiable { - return Err(item - .readonly_reason - .clone() - .unwrap_or_else(|| "Squid cannot change this item.".into())); + return Err(LOCK_REFUSAL.to_string()); } match item.source { StartupSource::RegistryRun => set_registry_enabled(&item, enabled), diff --git a/crates/squid-platform/src/trust.rs b/crates/squid-platform/src/trust.rs index 81e6530..b5ec165 100644 --- a/crates/squid-platform/src/trust.rs +++ b/crates/squid-platform/src/trust.rs @@ -18,6 +18,7 @@ use std::path::Path; /// What the signature says about one file. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct Trust { /// A signature exists and the operating system considers it intact. pub signed: bool, @@ -62,13 +63,20 @@ pub fn assess(path: &Path) -> Trust { // into an answer instead of a cached guess. return assess_uncached(path); }; + if let Some(found) = cache() + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .get(&key) + .cloned() + { + return found; + } + // Asked with no lock held: the question costs a subprocess, so holding the + // cache across it would make every bulk caller take these one at a time. + let trust = assess_uncached(path); let mut cache = cache() .lock() .unwrap_or_else(|poisoned| poisoned.into_inner()); - if let Some(found) = cache.get(&key) { - return found.clone(); - } - let trust = assess_uncached(path); // Bounded, because a utility that grows its own footprint to answer a // display question is its own kind of junk. Half is dropped rather than all, // so a table that is still on screen keeps the answers it is showing. @@ -318,41 +326,47 @@ fn pe_has_certificate_at(path: &Path) -> Option { /// Cheap gate for a table with hundreds of rows: only Mach-O and PE files can /// carry a signature, so everything else is answered without a subprocess. +/// +/// The header decides, not the name. A macOS privileged helper is called +/// `us.zoom.ZoomDaemon` and a Windows one `com.microsoft.autoupdate.helper`, where +/// the last dot is part of the name rather than an extension; judging by extension +/// never asked about a signed helper whose name happens to contain a dot. Reading +/// eight bytes is close to free next to the subprocess being avoided, and it is the +/// same question the signature actually answers. pub fn might_be_executable(path: &Path) -> bool { - if path.is_dir() { - return false; - } - if path.extension().is_some() { - const SIGNED_KINDS: [&str; 9] = [ - "app", - "framework", - "bundle", - "xpc", - "dylib", - "so", - "exe", - "dll", - "sys", - ]; - let ext = path - .extension() + /// Bundles are signed as a unit, so the directory itself is the question. + const BUNDLES: [&str; 4] = ["app", "framework", "bundle", "xpc"]; + + let extension = || { + path.extension() .map(|ext| ext.to_string_lossy().to_lowercase()) - .unwrap_or_default(); - return SIGNED_KINDS.contains(&ext.as_str()) || ext.is_empty(); + .unwrap_or_default() + }; + if path.is_dir() { + return BUNDLES.contains(&extension().as_str()); + } + match header(path) { + Some(head) => header_is_executable(&head), + // Nothing to read: an executable the current user may run but not open is + // common among root-owned helpers, and `codesign` may still answer for it. + None => { + BUNDLES.contains(&extension().as_str()) + || ["dylib", "so", "exe", "dll", "sys"].contains(&extension().as_str()) + || extension().is_empty() + } } - // Extension-less binaries are the norm on macOS, so the header decides. - header_is_executable(path) } -fn header_is_executable(path: &Path) -> bool { +/// The first eight bytes, or `None` when the file cannot be opened. +fn header(path: &Path) -> Option<[u8; 8]> { use std::io::Read; - let Ok(mut file) = std::fs::File::open(path) else { - return false; - }; + let mut file = std::fs::File::open(path).ok()?; let mut head = [0_u8; 8]; - let Ok(_) = file.read(&mut head) else { - return false; - }; + file.read_exact(&mut head).ok()?; + Some(head) +} + +fn header_is_executable(head: &[u8; 8]) -> bool { // Mach-O 32/64, fat binary, and their byte-swapped forms. const MACHOS: [[u8; 4]; 6] = [ [0xcf, 0xfa, 0xed, 0xfe], diff --git a/crates/squid-platform/src/windows.rs b/crates/squid-platform/src/windows.rs index 1fb7d69..c87899b 100644 --- a/crates/squid-platform/src/windows.rs +++ b/crates/squid-platform/src/windows.rs @@ -90,6 +90,26 @@ fn uninstall_program(uninstall_string: &str) -> Option { candidate.exists().then_some(candidate) } +/// `DisplayIcon` is a path with an optional icon index, usually quoted: +/// `"C:\Program Files\App\app.exe",0`. The file manager accepts the path +/// without the index and returns the application's default icon. +fn display_icon_path(value: Option) -> Option { + let raw = value?.trim().to_string(); + let unquoted = raw + .strip_prefix('"') + .and_then(|value| value.split('"').next()) + .unwrap_or(&raw) + .trim(); + let without_index = unquoted + .rsplit_once(',') + .filter(|(_, index)| index.trim().parse::().is_ok()) + .map(|(path, _)| path) + .unwrap_or(unquoted) + .trim(); + let path = PathBuf::from(without_index); + path.exists().then_some(path) +} + impl Platform for Windows { fn id(&self) -> PlatformId { PlatformId::Windows @@ -138,6 +158,27 @@ impl Platform for Windows { None => String::new(), } } + fn graphics_adapter(&self) -> String { + let Ok(class) = RegKey::predef(HKEY_LOCAL_MACHINE).open_subkey_with_flags( + r"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}", + KEY_READ, + ) else { + return String::new(); + }; + let mut adapters = Vec::new(); + for name in class.enum_keys().flatten() { + let Ok(adapter) = class.open_subkey_with_flags(&name, KEY_READ) else { + continue; + }; + let Some(description) = str_value(&adapter, "DriverDesc") else { + continue; + }; + if !adapters.contains(&description) { + adapters.push(description); + } + } + adapters.join(" · ") + } fn app_sources(&self) -> Vec { let env = |key: &str| std::env::var_os(key).map(PathBuf::from); let mut dirs: Vec = vec![ @@ -207,6 +248,7 @@ impl Platform for Windows { name: display_name, bundle_id: None, path, + icon_source: display_icon_path(str_value(&key, "DisplayIcon")), version: str_value(&key, "DisplayVersion"), size: Bytes::ZERO, source: source.into(), diff --git a/crates/squid-stats/src/battery.rs b/crates/squid-stats/src/battery.rs index cd00f43..7dc3edf 100644 --- a/crates/squid-stats/src/battery.rs +++ b/crates/squid-stats/src/battery.rs @@ -65,6 +65,9 @@ fn macos_battery() -> Option { battery.cycle_count = cycles; battery.temperature_c = temp; } + if let Some(health) = maximum_capacity() { + battery.health_percent = Some(health); + } Some(battery) } @@ -129,19 +132,77 @@ fn battery_details() -> Option<(Option, Option, Option)> { .ok() .filter(|output| output.status.success())?; let text = String::from_utf8_lossy(&output.stdout); - let design = find_number(&text, "DesignCapacity"); - let max = find_number(&text, "MaxCapacity"); - let health = match (design, max) { - (Some(design), Some(max)) if design > 0 => { - Some(((max as f64 / design as f64) * 100.0).round() as u8) - } - _ => None, - }; + let health = health_from_ioreg(&text); let cycles = find_number(&text, "CycleCount").map(|value| value as u32); let temp = find_number(&text, "Temperature").map(|tenths| tenths as f32 / 100.0); Some((health, cycles, temp)) } +/// macOS already publishes the same figure it shows in System Settings. Read it +/// once every ten minutes rather than deriving it from `MaxCapacity`, which on +/// Apple Silicon is a percentage rather than a mAh reading. +#[cfg(target_os = "macos")] +fn maximum_capacity() -> Option { + use std::sync::Mutex; + use std::time::{Duration, Instant}; + + static CACHE: Mutex)>> = Mutex::new(None); + let stale = CACHE + .lock() + .ok() + .and_then(|guard| *guard) + .map(|(at, _)| at.elapsed() > Duration::from_secs(600)) + .unwrap_or(true); + if !stale { + return CACHE + .lock() + .ok() + .and_then(|guard| guard.and_then(|(_, health)| health)); + } + let output = std::process::Command::new("/usr/sbin/system_profiler") + .arg("SPPowerDataType") + .output() + .ok() + .filter(|output| output.status.success()); + let health = output + .as_ref() + .and_then(|output| parse_maximum_capacity(&String::from_utf8_lossy(&output.stdout))); + if let Ok(mut guard) = CACHE.lock() { + *guard = Some((Instant::now(), health)); + } + health +} + +#[cfg(target_os = "macos")] +fn parse_maximum_capacity(text: &str) -> Option { + let line = text + .lines() + .find(|line| line.trim_start().starts_with("Maximum Capacity:"))?; + let value = line.split_once(':')?.1.trim().trim_end_matches('%').trim(); + value + .parse::() + .ok() + .filter(|value| (1..=100).contains(value)) +} + +#[cfg(target_os = "macos")] +fn health_from_ioreg(text: &str) -> Option { + let design = find_number(text, "DesignCapacity")?; + if design == 0 { + return None; + } + // `MaxCapacity` is a percentage on Apple Silicon. The raw/nominal fields are + // the actual mAh readings and are the only values that can form a ratio. + let maximum = find_number(text, "AppleRawMaxCapacity") + .filter(|value| *value > 0) + .or_else(|| find_number(text, "NominalChargeCapacity").filter(|value| *value > 0))?; + Some( + ((maximum as f64 / design as f64) * 100.0) + .round() + .min(100.0) as u8, + ) +} + #[cfg(target_os = "macos")] fn find_number(text: &str, key: &str) -> Option { let (_, after) = text.split_once(&format!("\"{key}\""))?; @@ -228,6 +289,21 @@ mod tests { assert!(parse_pmset(text).is_none()); } + #[test] + #[cfg(target_os = "macos")] + fn maximum_capacity_is_read_from_the_os_health_figure() { + let text = " Health Information:\n Cycle Count: 516\n Maximum Capacity: 86%\n"; + assert_eq!(parse_maximum_capacity(text), Some(86)); + } + + #[test] + #[cfg(target_os = "macos")] + fn apple_silicon_health_ignores_the_percentage_in_max_capacity() { + let text = + "\"DesignCapacity\" = 6075\n\"MaxCapacity\" = 100\n\"AppleRawMaxCapacity\" = 4911\n"; + assert_eq!(health_from_ioreg(text), Some(81)); + } + #[test] #[cfg(any(target_os = "macos", target_os = "linux"))] fn hhmm_parsing() { diff --git a/crates/squid-stats/src/lib.rs b/crates/squid-stats/src/lib.rs index 0eb8b31..a6b6091 100644 --- a/crates/squid-stats/src/lib.rs +++ b/crates/squid-stats/src/lib.rs @@ -107,6 +107,7 @@ pub struct HostInfo { pub os_name: String, pub os_version: String, pub hardware: String, + pub gpu: String, pub hostname: String, pub user: String, pub arch: String, @@ -119,6 +120,7 @@ impl HostInfo { os_name: platform.display_name(), os_version: platform.os_version(), hardware: platform.hardware_model(), + gpu: platform.graphics_adapter(), hostname: hostname(), user: std::env::var("USER") .or_else(|_| std::env::var("USERNAME")) @@ -428,35 +430,23 @@ pub struct AppUsage { } fn cpu_stats(system: &System) -> CpuStats { - // sysinfo puts the aggregate sample in `cpus()[0]`; the tail is one entry - // per logical core. let all = system.cpus(); - let (aggregate, cores) = all - .split_first() - .map(|(head, tail)| (Some(head), tail)) - .unwrap_or((None, &[])); - let per_core: Vec = cores + let per_core: Vec = all .iter() .map(|cpu| cpu.cpu_usage().clamp(0.0, 100.0)) .collect(); let load = System::load_average(); - let brand = aggregate - .or_else(|| cores.first()) + let first = all.first(); + let brand = first .map(|cpu| cpu.brand().trim().to_string()) .unwrap_or_else(|| std::env::consts::ARCH.to_string()); - let base_frequency_ghz = aggregate - .or_else(|| cores.first()) + let base_frequency_ghz = first .map(|cpu| cpu.frequency() as f64 / 1_000.0) .unwrap_or(0.0); - let total = aggregate - .map(|cpu| cpu.cpu_usage()) - .unwrap_or_else(|| system.global_cpu_usage()) - .clamp(0.0, 100.0); - let logical_cores = if per_core.is_empty() { - 1 - } else { - per_core.len() - }; + // sysinfo keeps the aggregate independently of the per-core list. Reading + // `cpus()[0]` as the total also dropped one core from every count. + let total = system.global_cpu_usage().clamp(0.0, 100.0); + let logical_cores = per_core.len().max(1); let physical = detect_physical_cores().unwrap_or_else(|| logical_cores.div_ceil(2)); CpuStats { total, @@ -553,30 +543,13 @@ fn vm_stat_details() -> Option<(Bytes, Bytes)> { let now = now_ms(); let previous = LAST.swap(now, Ordering::Relaxed); static CACHE: std::sync::Mutex> = std::sync::Mutex::new(None); - if now - previous > 5_000 || previous == 0 { - let page_size = 4096u64; + if now.saturating_sub(previous) > 5_000 || previous == 0 { let output = std::process::Command::new("/usr/bin/vm_stat") .output() .ok() .filter(|out| out.status.success())?; let text = String::from_utf8_lossy(&output.stdout); - let mut compressor_pages = 0u64; - let mut wired_pages = 0u64; - for line in text.lines() { - let mut parts = line.split(':'); - let key = parts.next()?.trim(); - let value = parts.next()?.trim().trim_end_matches('.').replace(' ', ""); - let pages: u64 = value.parse().unwrap_or(0); - match key { - "Occupied by compressor" => compressor_pages = pages, - "Wired Pages" => wired_pages = pages, - _ => {} - } - } - let value = ( - Bytes(compressor_pages * page_size), - Bytes(wired_pages * page_size), - ); + let value = parse_vm_stat(&text)?; if let Ok(mut guard) = CACHE.lock() { *guard = Some(value); } @@ -586,6 +559,42 @@ fn vm_stat_details() -> Option<(Bytes, Bytes)> { } } +/// Apple Silicon uses 16 KiB pages, Intel Macs use 4 KiB. The header states the +/// size, and the two fields squid reports use different labels than older +/// versions of `vm_stat`; both facts made the previous parser return zero. +fn parse_vm_stat(text: &str) -> Option<(Bytes, Bytes)> { + let header = text.lines().next()?; + let (_, after_size) = header.split_once("page size of ")?; + let page_size: u64 = after_size + .chars() + .take_while(|character| character.is_ascii_digit()) + .collect::() + .parse() + .ok()?; + let mut compressor_pages = 0u64; + let mut wired_pages = 0u64; + for line in text.lines().skip(1) { + let Some((key, value)) = line.split_once(':') else { + continue; + }; + let pages: u64 = value + .trim() + .trim_end_matches('.') + .replace(' ', "") + .parse() + .unwrap_or(0); + match key.trim().trim_matches('"') { + "Pages occupied by compressor" => compressor_pages = pages, + "Pages wired down" => wired_pages = pages, + _ => {} + } + } + Some(( + Bytes(compressor_pages.saturating_mul(page_size)), + Bytes(wired_pages.saturating_mul(page_size)), + )) +} + fn net_rates(networks: &Networks, seconds: f64) -> NetRate { let mut rx = 0u64; let mut tx = 0u64; @@ -858,6 +867,18 @@ mod tests { assert_eq!(stats.percent_used(), 100); } + #[test] + fn vm_stat_uses_the_reported_page_size_and_fields() { + let text = "\ +Mach Virtual Memory Statistics: (page size of 16384 bytes)\n\ +Pages free: 96476.\n\ +Pages wired down: 122963.\n\ +Pages occupied by compressor: 151882.\n"; + let (compressed, wired) = parse_vm_stat(text).expect("vm_stat"); + assert_eq!(wired, Bytes(122_963 * 16_384)); + assert_eq!(compressed, Bytes(151_882 * 16_384)); + } + /// The feature, end to end: a sample that still describes its pid stops it. #[test] fn a_process_stops_when_its_sample_asks_it_to() { diff --git a/crates/squid-tui/src/app.rs b/crates/squid-tui/src/app.rs index c2cbd1c..c6497b0 100644 --- a/crates/squid-tui/src/app.rs +++ b/crates/squid-tui/src/app.rs @@ -2593,6 +2593,7 @@ mod tests { name: "SquidTest".to_string(), bundle_id: Some("com.nexsquid.test".to_string()), path: bundle.clone(), + icon_source: None, version: Some("1.0".to_string()), size: Bytes(0), source: "test".to_string(), @@ -2686,6 +2687,7 @@ mod tests { name: "SquidTest".into(), bundle_id: Some("com.example.SquidTest".into()), path: path.clone(), + icon_source: None, version: None, size: Bytes(0), source: "test".into(), diff --git a/crates/squid-tui/src/views.rs b/crates/squid-tui/src/views.rs index 842689c..ba2e2bc 100644 --- a/crates/squid-tui/src/views.rs +++ b/crates/squid-tui/src/views.rs @@ -2044,6 +2044,7 @@ mod tests { name: "Demo".into(), bundle_id: Some("com.example.Demo".into()), path: "/Applications/Demo.app".into(), + icon_source: None, version: Some("1.0".into()), size: Bytes(1 << 20), source: "Applications".into(), @@ -2602,6 +2603,7 @@ mod tests { .map(|index| AppInfo { name: format!("Sq{index:02}"), path: format!("/Applications/Sq{index:02}.app").into(), + icon_source: None, source: "Applications".into(), size: Bytes(1 << 20), ..Default::default() diff --git a/docs/DESKTOP.md b/docs/DESKTOP.md index ee51e2a..d055db7 100644 --- a/docs/DESKTOP.md +++ b/docs/DESKTOP.md @@ -45,7 +45,7 @@ cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings | Screen | What it does | | --- | --- | -| Computer overview | Security status strip, cleanup scan entry, disk health, cleanup result categories and live CPU/memory/storage summaries | +| Overview | Security status strip, cleanup scan entry, disk health, cleanup result categories and live CPU/memory/storage summaries | | Daily cleanup | Runs the normal cleanup rule set, groups results by category, supports per-item and per-category selection, Trash or permanent deletion, then offers undo through History | | Uninstall apps | Reads installed apps, builds an app-specific removal plan, shows leftover paths and warnings, then uninstalls selected items | | Deep Clean | Searches chosen project roots for regenerable build artefacts with Git and file-age protections | diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 20f31ae..7951068 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -1,6 +1,6 @@ # Squid 安全与管理功能路线图 -状态:P0–P3 已实现(0.1.6);P4 未开始 +状态:P0–P3 已实现(0.1.7),并按第 13、14 节重做了列表、下拉组件、启动项页与界面文案;P4 未开始 更新时间:2026-11-07 适用平台:macOS 12+、Windows 10/11(x64;ARM64 通过兼容层运行) @@ -98,7 +98,7 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 ```text 维护 Maintenance - 电脑概览 Computer overview + 概览 Overview 日常清理 Daily cleanup 应用卸载 Uninstall apps 深度清理 Deep Clean @@ -127,7 +127,7 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 | 序号 | Page ID | 中文 | English | 快捷键 | | --- | --- | --- | --- | --- | -| 1 | `overview` | 电脑概览 | Computer overview | `Cmd/Ctrl+1` | +| 1 | `overview` | 概览 | Overview | `Cmd/Ctrl+1` | | 2 | `cleanup` | 日常清理 | Daily cleanup | `Cmd/Ctrl+2` | | 3 | `applications` | 应用卸载 | Uninstall apps | `Cmd/Ctrl+3` | | 4 | `purge` | 深度清理 | Deep Clean | `Cmd/Ctrl+4` | @@ -177,7 +177,7 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 | 页面 | 主要职责 | 主要动作 | 不承载 | | --- | --- | --- | --- | -| 电脑概览 | 汇总电脑状态、清理结果和安全状态 | 开始清理扫描、开始安全扫描、跳转 | 复杂发现处置、启动项编辑 | +| 概览 | 汇总电脑状态、清理结果和安全状态 | 开始清理扫描、开始安全扫描、跳转 | 复杂发现处置、启动项编辑 | | 日常清理 | 按规则扫描并删除可重建缓存和垃圾 | 选择、删除、撤销入口 | 安全发现和隔离 | | 应用卸载 | 读取应用、生成卸载计划 | 卸载 App 与残留 | 安全扫描、启动项管理 | | 深度清理 | 查找项目构建产物和旧安装包 | 选择、删除 | 安全扫描 | @@ -188,7 +188,7 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 | 历史记录 | 清理/卸载账本与恢复 | 查看会话、撤销 | 安全事件审计 | | 设置 | 全局偏好、权限、排除项、更新 | 修改设置、打开系统设置 | 扫描结果和处置 | -### 4.2 电脑概览 +### 4.2 概览 职责:给用户一个“现在该做什么”的入口,不在这里完成复杂处置。 @@ -262,30 +262,41 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 职责:展示并管理登录/启动时自动运行的持久化入口,解释每个条目的来源和风险。 -页面区块: +页面按操作系统自己的分法组织,而不是按实现文件的分法。macOS 把它拆成「登录时打开」 +和「允许在后台」两张列表,并把每个条目归到安装它的应用下面;0.1.6 的第一版把两者拍平成 +一条 873 行的 plist 标签列表,结果既看不到系统设置里那两三项「登录时打开」,也读不懂剩下 +八百项。现在: -1. 页头摘要: - - 用户级数量、系统级数量、已停用数量、需要管理员授权的数量。 - - 不显示“优化分数”。 -2. 过滤与搜索: - - 范围:全部 / 当前用户 / 系统。 - - 来源:LaunchAgent、LaunchDaemon、登录项、Run/RunOnce、启动文件夹、计划任务、服务。 - - 状态:已启用 / 已停用。 - - 风险:全部 / 需要注意 / 仅系统项。 - - 默认隐藏 Apple / Microsoft 系统项,可开启“显示系统项”。 -3. 列表: - - 名称、来源、范围、发布者/签名、目标路径、状态、风险标签。 - - 风险标签:目标不存在、路径在临时目录、未签名、命令包含脚本解释器、近期创建、隐藏任务。 - - 风险标签只表示“需要检查”,不等于恶意。 -4. 详情抽屉: - - 完整命令、参数、工作目录、父 App、签名状态、文件哈希、修改时间。 - - 关联进程:显示 PID、CPU、内存,跳转实时监控 → 进程。 - - 操作:停用/启用、在 Finder/资源管理器中显示、扫描该文件、打开系统设置。 -5. 修改确认: - - 展示将被移动/修改的具体 plist、注册表值或任务。 - - 说明影响和恢复方式。 - - 系统级项目要求一次系统授权。 - - 操作后刷新真实状态,不只更新前端缓存。 +1. 页头:一句话说明按应用分组、以及「风险标记只代表值得检查」,不显示“优化分数”。 +2. 两个页签,数字与点进去看到的条数一致: + - **登录项**:登录时会打开界面/应用的条目。macOS 的登录项,Windows 的启动文件夹与 + Run/RunOnce。平铺不分组,组头位置放一个「打开系统设置」入口——这一列表在两个平台 + 都不归 squid 写。 + - **后台程序**:不打开界面的 helper。macOS 的 LaunchAgents/LaunchDaemons、 + Windows 的计划任务与服务。按所属应用折叠,组头显示应用名、条目数、已停用数、 + 值得检查数与签名状态。 +3. 过滤:范围下拉(全部 / 当前用户 / 系统)、仅看值得检查、显示系统自带条目 + (默认关闭,chip 上带着被藏起来的条数)。搜索匹配名称、命令、路径与应用名, + 搜索时所有分组自动展开。 +4. 列表行:名称、目标路径、风险标签、来源(分组视图里才显示,因为组头已经说明来源相同)、 + 系统级标记;右侧是开关或只读原因。 + - 风险标签:目标不存在、路径在临时目录、无可用签名、**签名无法读取**、经由脚本解释器启动、 + 近期创建、隐藏条目、位于隐藏目录。 +5. 详情抽屉:完整命令、所属应用、工作目录、可执行文件、声明位置、修改时间、签名; + 关联进程跳转实时监控,文件可以单独送去扫描。 + 不可修改时,只读原因是本地化后的 `StartupLock` 枚举,不是后端拼好的英文句子。 +6. 修改确认:展示将被改名/移动的 plist、注册表值或启动文件夹条目,说明影响与恢复方式; + 操作后重新读取真实状态,不只更新前端缓存。 + +`StartupItem` 因此新增三个字段,全部由路径推导,不需要管理员权限: + +- `category`:条目属于上面两张列表中的哪一张,由 `source` 决定。 +- `owner`:安装它的应用。macOS 先取目标路径里的 `.app` 祖先并读它的 `CFBundleDisplayName`; + `/Library/PrivilegedHelperTools` 里的 helper 路径不携带答案,改用 launchd 标签去匹配 + **已安装应用**的 bundle id 前缀,且只有该前缀只被一个应用拥有时才认领 + (`org.wireshark.ChmodBPF` 曾经因为只比较首段而被归给 GeoGebra)。都失败时退回签名里的组织名。 + Windows 用 Authenticode 发布者,其次 Program Files 下的产品目录。 +- `lock`:不可修改的原因,枚举值,交给界面翻译。 首版操作范围: @@ -299,7 +310,7 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 - macOS 全局 LaunchAgents/Daemons:一次性管理员授权,备份后停用/恢复。 - Windows HKLM Run、系统计划任务:一次性 UAC 授权。 - Windows 服务:保持只读,不提供启停。 -- macOS 登录项:保持只读,跳转系统设置。 +- macOS 登录项:保持只读,页面直接打开系统设置对应 pane(13.4)。 ### 4.5 实时监控 @@ -312,11 +323,15 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 - 高占用进程标题右侧增加“查看全部进程”。 2. **进程 / Processes** - 全量进程表格,按需加载,不跟随 1Hz 刷新。 - - 列:进程、PID、父进程、用户、路径、CPU、内存、启动时间、签名、关联启动项。 + - 列:进程(路径并到名称下面一行)、PID、用户、CPU、内存、启动时间、签名, + 行尾是「由启动项启动」标记与结束进程按钮。父进程只在详情抽屉里给,不占一列。 - 搜索、排序、按应用聚合、只看当前用户、只看未签名、只看有启动项。 - 行详情抽屉:命令行、可执行文件、哈希、签名、工作目录、启动项、父进程。 - 操作:结束进程、停止并隔离(仅已确认恶意)、打开文件位置、复制路径、跳转启动项。 + 「只看有启动项」和那个标记读的是同一个字段。0.1.6 里那个字段从来没被赋过值, + 所以这一列和这个筛选都是 13.9 之后才真正可用的——上面这行是照实现改的,不是照愿望写的。 + 安全约束: - 保留现有 PID/名称复核和关键进程保护。 @@ -452,6 +467,12 @@ CleanMyMac 式的常驻实时防病毒产品,也不是 XProtect / Defender 的 - 系统级修改必须经过一次系统授权。 - 操作后重新读取真实状态,不信任前端缓存。 - 目标消失、权限变化、条目被 App 重建时,报告实际状态而不是假装成功。 +- 「无法读取签名」和「没有签名」是两件事:root 安装成 0711 的 helper 能执行、不能打开, + `codesign` 回答 Permission denied。把它报成未签名是在指控一个其实签过名的程序。 +- 归属只写有依据的名字:路径里的 `.app`、唯一匹配的 bundle id 前缀、签名里的组织名。 + 两个应用共享同一前缀时是平局,平局不写答案,条目留在未分组里。 +- 只读原因、读不到的目录、读不到的登录项都以枚举/结构体上传,由界面翻译; + 平台层不拼接句子,否则中文界面会漏出英文。 ### 6.5 规则包 @@ -512,10 +533,14 @@ security_exclusions security_update_rules startup_items startup_set_enabled +open_startup_settings process_inventory process_detail ``` +`open_startup_settings` 只打开系统设置对应的 pane:登录项、计划任务和服务在两个平台 +都不归 squid 写,能给的诚实动作是送到那一页,而不是给一个未必生效的开关。 + 扫描结果、启动项清单和隔离项都由后端保存并分配 ID;前端只提交 ID。 运行中的扫描复用 `Progress`、`CancelToken` 和现有 `ProgressReporter` 模式。 @@ -651,6 +676,11 @@ TUI 的 Guard 面板放到后续版本,不阻塞桌面端 MVP。 - Apple/Microsoft 系统项默认隐藏且只读。 - 关键进程结束被拒绝并说明原因。 - 进程详情能正确关联启动项。 +- 「登录项」页签显示的条目与系统设置「登录项与扩展 → 登录时打开」一致; + 读不到时页面说明原因,而不是显示一张空表假装「没有」。 +- 后台程序按应用分组,组名是可辨认的应用名,不是 plist 标签;归不了类的条目集中在一组, + 不被随便塞进某个应用。 +- 打开启动项页的等待时间与进程表同级,不出现「转圈几秒」。 ### 9.4 发布 @@ -802,6 +832,10 @@ TUI 的 Guard 面板放到后续版本,不阻塞桌面端 MVP。 **不新增的规范也要说清楚。** 隔离行、启动项行原来各自定义了边框/圆角/背景,现在都来自 `.item-row` 一处;改一处两个页面同时生效,这正是不开第二套规范的目的。 +> 13.1 把这一节里的三件事改掉了:`.item-row` 的定义换成扁平分隔线、`.settings-select` +> 变成组件 `Select`、`.stat` 删除。这一节保留原文,因为它记录的判断(复用而不是新造) +> 依然成立,被改掉的只是它当时选中的具体 class。 + ### 12.8 6.6 的体积预算超了,并且部分是我自己造成的 6.6 写「安装包增加目标不超过 10 MB」。0.1.6 实测: @@ -825,3 +859,256 @@ TUI 的 Guard 面板放到后续版本,不阻塞桌面端 MVP。 预算本身不改成 11 MB:超了就是超了,写在这里比改数字更有用。下一版如果要还这笔账, 方向是二进制本身(例如等 yara-x 提供关掉 wasm 后端的选项),不是砍功能。 + +## 13. 第二轮修订:列表样式、下拉组件与启动项重做 + +0.1.6 发出去以后收到的三条反馈都成立,而且第三条最严重:启动项页把 873 个 launchd +标签拍平成一列,用户在这页既找不到系统设置里那两三项「登录时打开」,也读不懂剩下的八百项。 + +### 13.1 列表统一成扁平分隔线,不要指示器 + +0.1.6 的两个新页面给每一行套了一张 1px 描边的圆角卡片,再用 3px 左边框当严重级别指示器。 +这一条不只是审美问题:它和旧模块根本不通约,而且同一版里自己就不统一—— +安全页/启动项页是描边圆角盒,新进程表是斑马纹,`.evidence-list li` 是实心色块, +旧模块则从来不是这个样子。现在: + +- `.item-row` 重新定义:`min-height: 44px`、`padding: 7px 10px`、 + `border-bottom: 1px solid var(--nex-line)`、无圆角、hover 用 `--nex-cream`,最后一行不画线。 + 旧页面本来只有两种行:一种带分隔线(`.process-row` + `.process-head`),一种是圆角但 + 不画边的悬浮高亮(`.cleanup-row`、`.app-row`、`.large-file-row`、`.whitelist-row`)。 + 0.1.6 造的是第三种——每行一个 1px 描边圆角盒子,再加 3px 左边框,哪一种是都不像。 + 新页面并入第一种:安全页和启动项页的条目是「几百行里扫一眼」的列表, + 和进程表同类;`.history-card` 那种整卡是「一次会话」的容器,不是同一件事。 +- 级别不再用边框表示。`.level-dot` 和 `.risk-chip` 删除;色调改为给 + `.item-copy strong` 着色(`is-danger` / `is-warning`),级别文字仍由 `.status-chip` 承担。 +- 同一版里剩下的两处也并入分隔线:`.evidence-list li`(原来是实心色块圆角)、 + `.ptable.pt-rows li` 与 `.process-group-head`(原来是斑马纹圆角)。 + 改完之后**安全页和启动项页**与旧模块里带分隔线的那种行完全一致。旧模块本身仍有两种行 + (带分隔线的 `.process-row`,和不画边、圆角高亮的 `.cleanup-row`/`.app-row`/`.large-file-row`/ + `.whitelist-row`),这一轮没有去统一它们:用户要的是新模块别再自己发明第三种, + 而不是把八个旧页面重排一遍。 +- 我这次新增的类只有 12 个(`group-*` 5 个、`select*` 3 个、`is-{start,end,current,nested}`), + 同时删掉 9 个(`level-dot`、`risk-chip`、`settings-select`、`startup-batch*` 3 个、 + `startup-meta`、`stat`、`stat-grid`)。启动项页原来的五块 `.stat` 摘要删除, + 数字回到页签和筛选 chip 上,和 12.7 的结论一致。 + +### 13.2 下拉组件不用原生控件 + +`` 全部换掉: +安全设置的扫描计划、设置页的历史保留条数、启动项页的范围筛选。`Select` 的触发框沿用原来 +的 86×31 与 8px 圆角,所以替换不会挪动任何布局。全应用现在没有原生下拉。 + +启动项页的「来源」下拉本来有七个选项,重做之后被两件事取代:页签表示 `category`, +分组标题表示所属应用。少一个控件比把控件做漂亮更有用。 + +### 13.3 启动项按操作系统的分法重排 + +`StartupItem` 增加三个字段,都由路径推导,不需要管理员权限: + +- `category`:`open-at-login`(macOS 登录项、Windows 启动文件夹与 Run/RunOnce) + 或 `background`(LaunchAgent/Daemon、计划任务、服务)。这就是页签的两栏, + 名字直接沿用系统设置「登录项与扩展」的分区。 +- `owner`:安装该条目的应用。macOS 先看目标路径的 `.app` 祖先并读 `CFBundleDisplayName`; + `/Library/PrivilegedHelperTools` 里的 helper 路径不带答案,改用 launchd 标签去匹配 + **已安装应用**的 bundle id 前缀,且只有该前缀只被一个应用拥有时才认领;都失败时退回 + 签名里的组织名。Windows 用 Authenticode 发布者,其次 Program Files 下的产品目录。 +- `lock`:不可修改的原因,是枚举而不是句子,由界面翻译。12.6 已经为 + `schedule_note` 犯过同样的错——后端拼好的英文会漏进中文界面。 + +页面结构:页签(登录项 / 后台程序,数字与点进去看到的条数一致)→ 搜索 + 范围 + +「值得检查」+「系统自带条目」四个筛选 → 登录项平铺、后台按应用折叠。 +系统自带条目仍然默认隐藏,chip 上直接写明被藏起来的是多少条(本机 845 条)—— +「默认帮你藏了 845 条」必须让人看见,否则「全部」这个词在这页是假的。 + +**本机实测**(M1 Pro,macOS 15.7.1):874 条,其中 Apple 845 条;非系统条目 +归成 19 组,例如 Google Chrome 4 条、Docker 2 条、Microsoft Corporation 2 条、Zoom 1 条; +另有 3 条确实归不出来,集中在一组,不硬塞。 +`login-item://豆包` 一条,与系统设置「登录时打开」一致。 + +### 13.4 登录项此前一条都没有,原因是两个真 bug + +用户说「mac 设置里登录打开的内容反而没有」,不是主观感受:那一栏当时恒为空。 + +1. `login_items()` 从 `backgrounditems.btm` 里刮 ASCII 路径,再要求命中 `"/Applications/"`。 + 这个归档里的路径全是小写(`/applications/wireguard.app`),大小写敏感的匹配一个都不中。 +2. 修好大小写也不够。BTM 是 NSKeyedArchiver,装的是 security-scoped bookmark; + 用户目录里那份只含 9 个容器,系统设置面板显示 30 多个应用组,`sfltool dumpbtm` + 需要 root 才能读全。刮字符串永远对不上系统设置。 + +现在改问 System Events(`every login item`),也就是系统设置那块面板自己的视图, +两者不会打架。登录项仍然只读——AppleScript 的 `delete` 在不同 macOS 版本上并不可靠—— +所以旁边给一个「打开系统设置」的动作,命令按 `sw_vers` 的主版本号选 URL: +13 及以上用 `com.apple.LoginItems-Settings.extension`,12 用 +`com.apple.preference.users?LoginItems`(这两个是不同的 pane,`open` 对不认识的 +pane 也返回 0,所以不能靠试错)。读不到时 `StartupNote.kind = login-items-unavailable` +在页面上说明原因,而不是显示空表假装「没有」。Info.plist 为此加了 +`NSAppleEventsUsageDescription`,首次读取会请求自动化权限。 + +### 13.5 打开这一页要 8 秒 + +`inventory()` 冷启动 8.65 s。原因不是 plist:868 个条目里 844 个的 `program` 指向 +Apple 自己的文件,而 macOS 的 `trust::assess` 每次 fork 一个 `codesign`, +等于给一屏永远没人检查的条目问 844 次签名。三处改动之后 0.34 s, +而且真正需要问签名的从 868 个降到 16 个: + +- 签名判断从 `judge_program` 里拆出来。`system_vendor` 的条目和「目标已不存在」的条目 + 都不再问:前者不是要检查的对象,后者「不在了」本身已经是答案。 +- 剩下那十几次用 `par_iter_mut` 并行;`trust::assess` 原来在整个 `codesign` 期间持有 + 缓存互斥锁,那样并行等于白做,现在只在查/写缓存时加锁。 +- 顺序有讲究:先签名后归属,因为路径认不出应用时要用「谁签的名」兜底。 + 两个平台的 `inventory()` 末尾收敛到同一个 `finish()`,不再各自写一遍。 + +扫描结果没有因此变化:同一台机器仍是 8 suspicious / 308 advisory / 0 confirmed。 + +### 13.6 顺手修掉的两个签名谎报 + +- `trust::might_be_executable` 用扩展名判断「值不值得问签名」。macOS 特权 helper 叫 + `us.zoom.ZoomDaemon`、`com.microsoft.autoupdate.helper`,最后一个点是名字的一部分, + 于是它们被判成「不是可执行文件」,进而报成**未签名**。本机 + `/Library/PrivilegedHelperTools` 的 7 个 helper 全部踩中这条:改之前一个都没被问过签名, + 其中 5 个其实签名完好,剩下 1 个是根本读不了的 `com.docker.socket`。改成读前 8 个字节判断 + Mach-O/PE;打不开文件时不再一律回答 false, + 因为 root 装成 0711 的 helper 能执行、不能打开。 +- 上面那种「打不开」现在单独成一级:`StartupRisk::SignatureUnreadable`。 + 把读不到说成没签名,是在指控一个签过名的程序,而 6.4 的整份信用就建立在这种区分上。 + +### 13.7 「太多太杂」的真正原因:字段名根本没对上 + +重查时发现比样式严重得多的事:`StartupItem` 没有 `rename_all`,而包住它的 `StartupView` 有。 +后端发的是 `system_vendor`,页面读的是 `item.systemVendor`,于是这个表达式**恒为 `undefined`**, +`if (!showVendor && item.systemVendor) return false` 一次都没有生效—— + +```text +0.1.6 的启动项页:默认显示 873 行(Apple 的 845 行全都列在外面) +现在(同一台机器,同一个 inventory):默认显示 29 行 +``` + +这正是用户说的「太多、太杂看不懂」的直接原因,也解释了为什么这一版光是分组还不够: +分组之前得先让那 845 行真的被藏起来。TypeScript 看不见这个 bug——interface 描述的是 +意图,不是线上真正发出来的字节。 + +同类问题一共四个,全都在 0.1.6 就发出去了: + +| 类型 | 页面读到的是 | 实际收到 | 后果 | +| --- | --- | --- | --- | +| `StartupItem` | `systemVendor`/`workingDirectory`/`modifiedMs` | snake_case | 「隐藏系统项」失效;详情抽屉的工作目录、修改时间恒为空 | +| `StartupOwner` | `bundlePath` | `bundle_path` | 组头的 bundle 路径不显示 | +| `ProcessRow` | `startedMs`/`startupItem`/`workingDirectory` | snake_case | 进程表「启动时间」列恒为 `—`,按它排序恒为平局(`startupItem` 另有原因,见 13.9) | +| `Trust` | `adHoc` | `ad_hoc` | 进程详情把 ad-hoc 签名说成「未签名」 | + +修法沿用本文既有约定:**跨 IPC 的结构体自己声明 camelCase**(`Finding`、`SecuritySettingsView` +等一直这么做),而不是在 `*View` 里再套一层复制。改的是发送端,Rust 内部字段名不变, +CLI/TUI 直接访问字段因此不受影响;`squid guard startup --json` 的输出键随之变成 camelCase, +和 `guard scan --json`、`guard status --json` 统一(那两个一直是 camelCase)。 +`SystemSnapshot`、`LargestFile` 两侧本来就是 snake_case,属于另一种一致,没有动。 + +回归测试在 `src-tauri/src/startup.rs` 的 `wire_tests`:它序列化真正的 `StartupView`, +断言页面读得到的每个名字都在线上,并且断言线上**没有**同一字段的第二种拼法。 +把 `StartupItem` 的 `rename_all` 删掉,测试立刻红。 + +### 13.8 屏幕锁着也能验:把真组件跑进无头 Chrome + +Computer Use 需要显示器点亮,而验收期间这台 Mac 一直锁着。替代办法是 +`probe/`:用真的 `StartupPage` + 真数据(`squid guard startup --json` 落地成 +`fixtures/startup.json`)+ 真 `src/styles.css`,在 headless Chrome 里量**计算后**的样式并截图。 +它当场抓到一个肉眼看不出的 bug:`.status-chip` 没有 `white-space: nowrap`, +中文标签在行内被挤成**一字一行**(截图里「无法读取签名」竖着排)。旧 `.risk-chip` 本来有 nowrap, +13.1 合并 chip 时把这个性质丢了。修在 `.status-chip` 本身(`flex: 0 0 auto` + `white-space: nowrap`), +因为它是 6 处共用的原语,不是一个页面的补丁。 + +量出来的行形状,新列表和旧模块对齐: + +| | 圆角 | 左边框 | 下边框 | 背景 | +| --- | --- | --- | --- | --- | +| `.item-row`(安全页/启动项页) | 0 | 0 | 1px solid | 透明 | +| `.group-head` | 0 | 0 | 1px solid | 透明 | +| `.process-row`(旧模块) | 0 | 0 | 1px solid | 透明 | +| `.select-menu`(下拉浮层) | 11px | — | 1px solid | 卡片底色 + 阴影 | + +全页 `document.querySelectorAll('select').length === 0`,`option` 同样是 0。生产包里 +`option` 元素计数也是 0(`select` 那个命中来自 react-dom 自带的 DOM intrinsic 表,不是应用代码), +所以「所有下拉都不是原生控件」在整个应用范围内成立,不只是这三处改过的地方。 + +nowrap 的代价是标签不能折行,所以同一份探针量了溢出:1180 / 1280 / 820 / 900 宽度下 +`scrollWidth - clientWidth` 全为 0,页面没有横向滚动;820px 截图里行仍是一行, +过长的是**名字**(`.item-copy` 本来就会打点省略),标签完整可读。 + +`probe/` 是临时脚手架,量完已删除,不进版本库;它不是产品的一部分。 +### 13.9 进程表里那个从来不会亮的标记 + +`ProcessRow::startup_item` 的注释写着「由桌面层填」,进程表从 0.1.6 起就照着它画 +「由启动项启动」的盾牌图标,筛选条也照它做「只看有启动项」——但**全仓库没有任何地方给它赋过值**, +三处构造点全是 `None`。所以那个图标从来没出现过,那个筛选永远返回 0 行。 +13.7 修好的只是字段名;名字对了,值仍然是空的。 + +现在 `process_inventory` 读一次启动项清单,按可执行文件路径把两者对上: + +- 一次 inventory 给整张表用。`entry_for` 每次调用都重新扫一遍全部根目录,按行调用等于 757 次。 +- 实测(M1 Pro,757 进程 / 874 条目;`join_tests::what_the_join_costs`,`--ignored` 才跑): + 签名检查开着(默认)时表本身 5 s,加 join 之后 6 s,757 行里 452 行被标注; + 签名检查关掉时表本身只要 26 ms,加 join 变成 390 ms。默认路径几乎没动,签名才是瓶颈; + 那条快路径多出的 0.36 s 是这次改动真实的代价,写在这里而不是糊过去。 + + 没有加缓存是有意的。这张表只在打开页签、切换签名、点「刷新」时读,没有定时器; + 而把 inventory 缓存下来正是 `useStartupWorkspace` 的注释里点名不要的做法—— + App 会自己把启动项装回来,记住旧值的列表会在条目已经重新启用之后还显示它是关着的。 +- 同一个程序被两个条目声明时(`com.google.keystone.agent` 在 `~/Library` 和 `/Library` 各一份), + 取清单里先出现的那个,也就是当前用户拥有的那份。 +- **已停用的条目照样标注**:停用不一定能让进程退出,而这恰好是人最需要看清 + 「它还开着是因为那条启动项」的时刻。详情抽屉的 `entry_for` 也从来没按 `disabled` 过滤,两边一致。 + +这条不在 5.3 的验收里(那节只要求进程**详情**能关联启动项),但 5.3 的措辞是「若进程关联启动项」, +列表既然已经为这个标记画了图标、做了筛选,就不该是个永远不会亮的摆设。 +测试:`join_tests` 两条,覆盖匹配、用户拥有的条目优先、无路径不匹配、停用仍标注。 + +## 14. 第三轮修订:菜单命名、页头小标题与重复说明 + +这一轮全是界面,没有改判定逻辑:扫描结果、启动项清单、进程表在本机与 13.9 结束时一致。 + +### 14.1 第一项改名「概览」 + +原来叫「电脑概览」,侧栏、顶栏、快捷键提示、README 与本文一起改成「概览」。 +菜单宽度有限,而这一项旁边已经有磁盘健康卡片说明它讲的是这台电脑,「电脑」是废字。 + +### 14.2 除概览之外不再有页头小标题 + +每个页面顶部原来都有一行橙色小字(`应用程序`、`安全`、`设置`……), +下面紧跟同样意思的 `

`。它把页面名说了两遍,还把标题从视觉上压小了。 +现在 `eyebrow` 只留在概览:那里写的是「下午好 · macOS」,是问候加系统名,不是第二遍页面名。 +其余 9 个页面一律不传 `eyebrow`;`.page-eyebrow` 规则保留,因为组件仍支持它。 + +### 14.3 界面上一半的说明是在重复离它最近的那个控件 + +12.7 定的规矩是「同一个事实只在离它最近的控件上出现一次」,当时只清理了两个新页面。 +这一轮把同一条规矩用到全部 10 个页面和 5 个卡片:整段删掉 22 处说明(中文约 530 字), +另外把 14 处两句话的说明压成一句。删之前先确认「删掉之后这句话还有没有人说」,所以保留的都各有理由: + +**删掉的是复述。** 设置页每个分组标题下面那句解释,说的都是标题或下面的控件已经说过的话: +「选择登录电脑后是否自动启动 Squid」在下一行的「登录时启动 Squid」开关上, +「超过此数量后较早的记录会被移除」在选择框里那五个数字上, +「默认选择当前系统语言」在任何平台的语言选择器上都是显然的。 +安全页更夸张:「尚未扫描」在同一屏里出现了四次——页头标题、发现区副标题、 +空状态标题、覆盖卡片——现在只剩页头和覆盖卡片两处,各自承担不同的事。 +空状态「还没有清理记录」「查看已安装的应用」下面那段「扫描之后你会看到什么」整段删除: +用户扫一次就知道了,而这句话挤掉了真正的入口按钮。 + +**保留的是删掉就没人说的话。** 隐私承诺留在它自己那两行里(「规则只下载到本机,不上传任何内容」 +「只读取,不改动」),页脚那句「一切都在本机完成」是它们的复述,删页脚不删这两行。 +确认对话框里的「永久删除无法撤销」「此进程中未保存的内容可能会丢失」全留, +那是不可逆操作唯一的提示位。覆盖受限时「未检查的范围见上方覆盖说明」也留: +6.4 要求不能把没读过说成安全,这句是它在界面上的落点。 +「停用会保留原始文件或注册表值,可随时恢复」留一次就够,同一个承诺在停用确认框里再说一遍是多余。 + +**改动方式。** 删掉说明会留下空容器,所以 `PageHeader.description` 与 +`EmptyState.description` 从必填改成可选(和本来就是可选的 `SectionTitle.subtitle` 一致), +两者都在缺省时不渲染那一段;设置页分组标题下的 `

`、设置行里的 `` +是各组独有的,直接删掉元素。随删掉的文案一起清除的 +CSS 规则有 4 条:`.page-footnote`、`.setup-note`、`.field-help`、`.settings-footer`, +都是这次改完之后全仓库再无引用的。没有新增任何 class,没有改任何尺寸, +所以删完之后每一页剩下的控件位置没动。 + +**验证:** `npx tsc --noEmit` 通过(顺带清掉因此失效的 `formatBytes` 导入; +`SecuritySettingsCard` 的 `api` 与 `ui.tsx` 的 `lang` 两处未使用变量在 HEAD 上就存在,没有动); +`pnpm build` 通过;`cargo test --workspace` 272 项通过;`cargo fmt --check` 干净。 diff --git a/package.json b/package.json index e845635..b74605c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "squid-desktop", "private": true, - "version": "0.1.6", + "version": "0.1.7", "type": "module", "scripts": { "dev": "vite --port 1420 --strictPort", diff --git a/release/0.1.7/README-Windows-x64.txt b/release/0.1.7/README-Windows-x64.txt new file mode 100644 index 0000000..88c344c --- /dev/null +++ b/release/0.1.7/README-Windows-x64.txt @@ -0,0 +1,27 @@ +Squid 0.1.7 - 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。 + +安装 +---- +1. 运行 Squid-Setup-0.1.7-win-x64.exe。 +2. 这是未签名构建。若 SmartScreen 显示警告,请选择“更多信息” > “仍要运行”。 +3. 卸载请在 Windows“设置 > 应用”中移除 Squid。 + +更新 +---- +Squid 使用与 nex_shift 一致的 releases 分支更新通道。更新包会先校验 +文件大小与 SHA256,再在退出后运行同一个安装程序。若构建时写入发布公钥, +还会验证清单的 Ed25519 签名。 + +校验 +---- +PowerShell: + Get-FileHash .\Squid-Setup-0.1.7-win-x64.exe -Algorithm SHA256 diff --git a/release/0.1.7/RELEASE_NOTES.md b/release/0.1.7/RELEASE_NOTES.md new file mode 100644 index 0000000..4f45d56 --- /dev/null +++ b/release/0.1.7/RELEASE_NOTES.md @@ -0,0 +1,16 @@ +Squid 0.1.7 + +- 概览页按新设计重做:智能维护、本机配置(系统、型号、处理器、内存、主硬盘、显卡)、处理器/内存/存储指标卡与日常维护入口;扫描结果仍在下方。 +- 应用卸载列表与卸载方案显示应用真实图标(macOS / Windows);图标按需加载并缓存,读取失败时回退首字母。 +- 实时监控修复电池健康度:改用系统报告的 Maximum Capacity,Apple Silicon 不再把百分比再除以设计容量;本机显示 86%,循环次数 516。 +- 修复 CPU 统计:使用全局占用和全部逻辑核心,不再把第一个核心当总量,也不再少算一个核心。 +- 修复内存统计:按 `vm_stat` 实际页大小(Apple Silicon 为 16 KiB)解析 compressor / wired;内存按 1024 进制显示,16 GB 不再显示为 17.2 GB。 +- 概览「本机配置」新增显卡信息(macOS `system_profiler`、Windows 注册表、Linux `lspci`)。 +- 启动项页按 macOS / Windows 自己的分法重做:「登录项 / 后台程序」页签,按安装它的应用分组;系统自带条目默认隐藏。 +- 启动项读取从 8.65 秒降到 0.34 秒:不再为系统自带和已不存在的条目逐个询问签名,其余项并行处理。 +- 修复启动项、进程表与信任状态共 4 处 IPC 字段名不一致:隐藏系统项恢复生效,启动时间、工作目录与 ad-hoc 签名状态不再显示为空或错误。 +- 修复进程表「由启动项启动」标记与筛选:按可执行文件路径关联启动项,现在能正确显示与筛选。 +- 修复带点名称的特权 helper 被误报未签名;新增「无法读取签名」状态,不再把读不到说成没签名。 +- 全部下拉菜单改为应用内自绘组件,不再弹出系统原生控件;列表统一为扁平分隔线。 +- 菜单第一项改名「概览」;除概览外移除重复的页面小标题,精简 22 处重复说明和 14 处冗长文案。 +- macOS 与 Windows 同步发布 0.1.7。两个安装包均为未签名构建,首次打开需要用户自行授权(macOS 右键打开,Windows SmartScreen「仍要运行」)。 diff --git a/release/0.1.7/SHA256SUMS.txt b/release/0.1.7/SHA256SUMS.txt new file mode 100644 index 0000000..cbaf480 --- /dev/null +++ b/release/0.1.7/SHA256SUMS.txt @@ -0,0 +1,3 @@ +f1841a084c76af824cbc5bc0feb2dd35a76743c03597c86bd64b0a478f6ad071 Squid-0.1.7-macOS-universal.dmg +34bc8444f6241b50e7ba7edb4a4875989f950481a4c7d2da21125cca5b5694df Squid-Setup-0.1.7-win-x64.exe +cb826847c7b598b0121d80f64cd954ec2dc2d23e6d559ad87fa767c051af8805 README-Windows-x64.txt diff --git a/release/0.1.7/Squid-0.1.7-macOS-universal.dmg b/release/0.1.7/Squid-0.1.7-macOS-universal.dmg new file mode 100644 index 0000000..83891cc Binary files /dev/null and b/release/0.1.7/Squid-0.1.7-macOS-universal.dmg differ diff --git a/release/0.1.7/Squid-Setup-0.1.7-win-x64.exe b/release/0.1.7/Squid-Setup-0.1.7-win-x64.exe new file mode 100644 index 0000000..9506999 Binary files /dev/null and b/release/0.1.7/Squid-Setup-0.1.7-win-x64.exe differ diff --git a/release/0.1.7/squid-update.json b/release/0.1.7/squid-update.json new file mode 100644 index 0000000..9578678 --- /dev/null +++ b/release/0.1.7/squid-update.json @@ -0,0 +1,18 @@ +{ + "schema": 1, + "version": "0.1.7", + "date": "2026-11-08", + "notes": "Squid 0.1.7\n\n- 概览页按新设计重做:智能维护、本机配置(系统、型号、处理器、内存、主硬盘、显卡)、处理器/内存/存储指标卡与日常维护入口;扫描结果仍在下方。\n- 应用卸载列表与卸载方案显示应用真实图标(macOS / Windows);图标按需加载并缓存,读取失败时回退首字母。\n- 实时监控修复电池健康度:改用系统报告的 Maximum Capacity,Apple Silicon 不再把百分比再除以设计容量;本机显示 86%,循环次数 516。\n- 修复 CPU 统计:使用全局占用和全部逻辑核心,不再把第一个核心当总量,也不再少算一个核心。\n- 修复内存统计:按 `vm_stat` 实际页大小(Apple Silicon 为 16 KiB)解析 compressor / wired;内存按 1024 进制显示,16 GB 不再显示为 17.2 GB。\n- 概览「本机配置」新增显卡信息(macOS `system_profiler`、Windows 注册表、Linux `lspci`)。\n- 启动项页按 macOS / Windows 自己的分法重做:「登录项 / 后台程序」页签,按安装它的应用分组;系统自带条目默认隐藏。\n- 启动项读取从 8.65 秒降到 0.34 秒:不再为系统自带和已不存在的条目逐个询问签名,其余项并行处理。\n- 修复启动项、进程表与信任状态共 4 处 IPC 字段名不一致:隐藏系统项恢复生效,启动时间、工作目录与 ad-hoc 签名状态不再显示为空或错误。\n- 修复进程表「由启动项启动」标记与筛选:按可执行文件路径关联启动项,现在能正确显示与筛选。\n- 修复带点名称的特权 helper 被误报未签名;新增「无法读取签名」状态,不再把读不到说成没签名。\n- 全部下拉菜单改为应用内自绘组件,不再弹出系统原生控件;列表统一为扁平分隔线。\n- 菜单第一项改名「概览」;除概览外移除重复的页面小标题,精简 22 处重复说明和 14 处冗长文案。\n- macOS 与 Windows 同步发布 0.1.7。两个安装包均为未签名构建,首次打开需要用户自行授权(macOS 右键打开,Windows SmartScreen「仍要运行」)。", + "artifacts": { + "macos": { + "file": "Squid-0.1.7-macOS-universal.dmg", + "sha256": "f1841a084c76af824cbc5bc0feb2dd35a76743c03597c86bd64b0a478f6ad071", + "size": 21933611 + }, + "windows": { + "file": "Squid-Setup-0.1.7-win-x64.exe", + "sha256": "34bc8444f6241b50e7ba7edb4a4875989f950481a4c7d2da21125cca5b5694df", + "size": 7875018 + } + } +} diff --git a/scripts/build-windows-release.sh b/scripts/build-windows-release.sh index 867d0ba..094b804 100755 --- a/scripts/build-windows-release.sh +++ b/scripts/build-windows-release.sh @@ -95,10 +95,10 @@ asset_text = "".join( for p in assets.iterdir() if p.suffix in {".js", ".css", ".html"} ) -# Markers are the Chinese copy that has to survive into the bundle: the two scan -# words are what the overview offers, and 0.1.6 split them apart, so a bundle built +# Markers are the Chinese copy that has to survive into the bundle: the overview, +# uninstall, monitor and update panels each contribute one phrase, so a bundle built # from an older or newer `dist` than the one on disk fails here rather than shipping. -for marker in ("清理扫描", "安全快速扫描", "扫描完成", "自动检查更新"): +for marker in ("本机配置", "智能扫描", "卸载,干净彻底", "掌握设备的每一次呼吸", "扫描完成", "自动检查更新"): if marker not in asset_text: missing.append(marker) if missing: diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5a0ffcc..93ed4cc 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -268,7 +268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" dependencies = [ "atk-sys", - "glib", + "glib 0.18.5", "libc", ] @@ -278,10 +278,10 @@ version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -515,7 +515,7 @@ checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" dependencies = [ "bitflags 2.13.2", "cairo-sys-rs", - "glib", + "glib 0.18.5", "libc", "once_cell", "thiserror 1.0.69", @@ -527,9 +527,9 @@ version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" dependencies = [ - "glib-sys", + "glib-sys 0.18.1", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -612,6 +612,16 @@ dependencies = [ "target-lexicon 0.12.16", ] +[[package]] +name = "cfg-expr" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba9e9ec16c447027685b1f897b720e18e9a8afd00bd7332c483537e38086c9f" +dependencies = [ + "smallvec", + "target-lexicon 0.13.5", +] + [[package]] name = "cfg-if" version = "1.0.5" @@ -1606,6 +1616,23 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "file_icon_provider" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff9f725b347b91d04340444fcbce0770886e4a6513e5f8e9e73a9e344efe73b" +dependencies = [ + "gio 0.22.10", + "gtk", + "log", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-uniform-type-identifiers", + "scopeguard", + "windows 0.62.2", +] + [[package]] name = "find-msvc-tools" version = "0.1.15" @@ -1786,8 +1813,8 @@ dependencies = [ "cairo-rs", "gdk-pixbuf", "gdk-sys", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "pango", ] @@ -1799,8 +1826,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" dependencies = [ "gdk-pixbuf-sys", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "once_cell", ] @@ -1811,11 +1838,11 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -1826,13 +1853,13 @@ checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", "pango-sys", "pkg-config", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -1842,11 +1869,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "140071d506d223f7572b9f09b5e155afbd77428cd5cc7af8f2694c41d98dfe69" dependencies = [ "gdk-sys", - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", "pkg-config", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -1857,8 +1884,8 @@ checksum = "3caa00e14351bebbc8183b3c36690327eb77c49abc2268dd4bd36b856db3fbfe" dependencies = [ "gdk", "gdkx11-sys", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "x11", ] @@ -1870,9 +1897,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e2e7445fe01ac26f11601db260dd8608fe172514eb63b3b5e261ea6b0f4428d" dependencies = [ "gdk-sys", - "glib-sys", + "glib-sys 0.18.1", "libc", - "system-deps", + "system-deps 6.2.2", "x11", ] @@ -1945,8 +1972,8 @@ dependencies = [ "futures-core", "futures-io", "futures-util", - "gio-sys", - "glib", + "gio-sys 0.18.1", + "glib 0.18.5", "libc", "once_cell", "pin-project-lite", @@ -1954,19 +1981,49 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "gio" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4620fbafdf19dba814473e19f18e75290cb3338662f6ae35f0402affd3b2b699" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys 0.22.9", + "glib 0.22.10", + "libc", + "pin-project-lite", + "smallvec", +] + [[package]] name = "gio-sys" version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", "winapi", ] +[[package]] +name = "gio-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28739f914c15b87a9856000bed9cbd5b3a8afbca5e982d9a299e1601422cb5" +dependencies = [ + "glib-sys 0.22.9", + "gobject-sys 0.22.9", + "libc", + "system-deps 9.0.1", + "windows-sys 0.61.2", +] + [[package]] name = "glib" version = "0.18.5" @@ -1979,10 +2036,10 @@ dependencies = [ "futures-executor", "futures-task", "futures-util", - "gio-sys", - "glib-macros", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-macros 0.18.5", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", "memchr", "once_cell", @@ -1990,6 +2047,26 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "glib" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4cf9e5bd8713f1990a92c422998826e0fb34824277b46bc59757373483c6694" +dependencies = [ + "bitflags 2.13.2", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "glib-macros 0.22.9", + "glib-sys 0.22.9", + "gobject-sys 0.22.9", + "libc", + "memchr", + "smallvec", +] + [[package]] name = "glib-macros" version = "0.18.5" @@ -2004,6 +2081,18 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "glib-macros" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9597c68fa7bdf4154a3079642cd21c4dccac0b0bdd2897d82861523bf91e7b9" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "glib-sys" version = "0.18.1" @@ -2011,7 +2100,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" dependencies = [ "libc", - "system-deps", + "system-deps 6.2.2", +] + +[[package]] +name = "glib-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b38907e67e40dec9b60f858bcada952598719cb512a13eb13d6cdcd16f8295" +dependencies = [ + "libc", + "system-deps 9.0.1", ] [[package]] @@ -2050,9 +2149,20 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" dependencies = [ - "glib-sys", + "glib-sys 0.18.1", "libc", - "system-deps", + "system-deps 6.2.2", +] + +[[package]] +name = "gobject-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07595c9ba696bd9819cb6a8df39f08078f3dd679508fe052dd558492c2053834" +dependencies = [ + "glib-sys 0.22.9", + "libc", + "system-deps 9.0.1", ] [[package]] @@ -2078,8 +2188,8 @@ dependencies = [ "futures-channel", "gdk", "gdk-pixbuf", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "gtk-sys", "gtk3-macros", "libc", @@ -2097,12 +2207,12 @@ dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", "pango-sys", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -2319,7 +2429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75e94d66081e4d8dcd098bd8dc5254800fea14a26389b298410158d834de167" dependencies = [ "byteorder", - "png", + "png 0.18.1", ] [[package]] @@ -2464,7 +2574,7 @@ dependencies = [ "byteorder-lite", "moxcms", "num-traits", - "png", + "png 0.18.1", ] [[package]] @@ -2570,7 +2680,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca5671e9ffce8ffba57afc24070e906da7fc4b1ba66f2cabebf61bf2ea257fcc" dependencies = [ "bitflags 1.3.2", - "glib", + "glib 0.18.5", "javascriptcore-rs-sys", ] @@ -2580,10 +2690,10 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1be78d14ffa4b75b66df31840478fef72b51f8c2465d4ca7c194da9f7a5124" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -2751,7 +2861,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03589b9607c868cc7ae54c0b2a22c8dc03dd41692d48f2d7df73615c6a95dc0a" dependencies = [ - "glib", + "glib 0.18.5", "gtk", "gtk-sys", "libappindicator-sys", @@ -3019,7 +3129,7 @@ dependencies = [ "objc2-core-foundation", "objc2-foundation", "once_cell", - "png", + "png 0.18.1", "serde", "thiserror 2.0.21", "windows-sys 0.61.2", @@ -3188,8 +3298,15 @@ checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.13.2", "block2", + "libc", "objc2", + "objc2-cloud-kit", + "objc2-core-data", "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-image", + "objc2-core-text", + "objc2-core-video", "objc2-foundation", "objc2-quartz-core", ] @@ -3211,6 +3328,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" dependencies = [ + "bitflags 2.13.2", "objc2", "objc2-foundation", ] @@ -3271,6 +3389,19 @@ dependencies = [ "objc2-core-graphics", ] +[[package]] +name = "objc2-core-video" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-io-surface", +] + [[package]] name = "objc2-encode" version = "4.1.0" @@ -3343,6 +3474,17 @@ dependencies = [ "objc2-user-notifications", ] +[[package]] +name = "objc2-uniform-type-identifiers" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7902ac02859fc1f7045f8b598c63f1ae0cc7efeaa06a9bc9f3d9a3c955974fa4" +dependencies = [ + "block2", + "objc2", + "objc2-foundation", +] + [[package]] name = "objc2-user-notifications" version = "0.3.2" @@ -3454,8 +3596,8 @@ version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" dependencies = [ - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "once_cell", "pango-sys", @@ -3467,10 +3609,10 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -3626,6 +3768,19 @@ dependencies = [ "time", ] +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.8.9", +] + [[package]] name = "png" version = "0.18.1" @@ -4053,8 +4208,8 @@ checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220" dependencies = [ "block2", "dispatch2", - "glib-sys", - "gobject-sys", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "gtk-sys", "js-sys", "libc", @@ -4574,8 +4729,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "471f924a40f31251afc77450e781cb26d55c0b650842efafc9c6cbd2f7cc4f9f" dependencies = [ "futures-channel", - "gio", - "glib", + "gio 0.18.4", + "glib 0.18.5", "libc", "soup3-sys", ] @@ -4586,11 +4741,11 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebe8950a680a12f24f15ebe1bf70db7af98ad242d9db43596ad3108aab86c27" dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "libc", - "system-deps", + "system-deps 6.2.2", ] [[package]] @@ -4605,7 +4760,7 @@ dependencies = [ [[package]] name = "squid-core" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -4624,7 +4779,7 @@ dependencies = [ [[package]] name = "squid-desktop" -version = "0.1.6" +version = "0.1.7" dependencies = [ "base64 0.22.1", "chrono", @@ -4651,7 +4806,7 @@ dependencies = [ [[package]] name = "squid-engine" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "chrono", @@ -4671,7 +4826,7 @@ dependencies = [ [[package]] name = "squid-guard" -version = "0.1.6" +version = "0.1.7" dependencies = [ "chrono", "hex", @@ -4687,11 +4842,13 @@ dependencies = [ [[package]] name = "squid-platform" -version = "0.1.6" +version = "0.1.7" dependencies = [ "dirs 6.0.0", + "file_icon_provider", "libc", "plist", + "png 0.17.16", "rayon", "serde", "serde_json", @@ -4705,7 +4862,7 @@ dependencies = [ [[package]] name = "squid-rules" -version = "0.1.6" +version = "0.1.7" dependencies = [ "globset", "serde", @@ -4717,7 +4874,7 @@ dependencies = [ [[package]] name = "squid-stats" -version = "0.1.6" +version = "0.1.7" dependencies = [ "chrono", "libc", @@ -4880,13 +5037,26 @@ version = "6.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" dependencies = [ - "cfg-expr", + "cfg-expr 0.15.8", "heck 0.5.0", "pkg-config", "toml 0.8.2", "version-compare", ] +[[package]] +name = "system-deps" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db551ad38aac61d5e0343e0eeeb0163be3115c4e23b6a025959570ee0c03c67d" +dependencies = [ + "cfg-expr 0.20.10", + "heck 0.5.0", + "pkg-config", + "toml 1.1.8+spec-1.1.0", + "version-compare", +] + [[package]] name = "tao" version = "0.37.2" @@ -5042,7 +5212,7 @@ dependencies = [ "ico", "json-patch", "plist", - "png", + "png 0.18.1", "proc-macro2", "quote", "semver", @@ -5636,7 +5806,7 @@ dependencies = [ "objc2-core-graphics", "objc2-foundation", "once_cell", - "png", + "png 0.18.1", "serde", "thiserror 2.0.21", "windows-sys 0.61.2", @@ -6183,11 +6353,11 @@ dependencies = [ "cairo-rs", "gdk", "gdk-sys", - "gio", - "gio-sys", - "glib", - "glib-sys", - "gobject-sys", + "gio 0.18.4", + "gio-sys 0.18.1", + "glib 0.18.5", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "gtk", "gtk-sys", "javascriptcore-rs", @@ -6206,15 +6376,15 @@ dependencies = [ "bitflags 1.3.2", "cairo-sys-rs", "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", + "gio-sys 0.18.1", + "glib-sys 0.18.1", + "gobject-sys 0.18.0", "gtk-sys", "javascriptcore-rs-sys", "libc", "pkg-config", "soup3-sys", - "system-deps", + "system-deps 6.2.2", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index db988dc..b1398ff 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "squid-desktop" -version = "0.1.6" +version = "0.1.7" description = "Squid — a CleanMyMac-inspired cleaner, uninstaller and system monitor." authors = ["squid contributors"] edition = "2021" diff --git a/src-tauri/Info.plist b/src-tauri/Info.plist index 91bef57..83bb199 100644 --- a/src-tauri/Info.plist +++ b/src-tauri/Info.plist @@ -14,5 +14,7 @@ Squid can analyze removable volumes you select. NSNetworkVolumesUsageDescription Squid can analyze network volumes you select. + NSAppleEventsUsageDescription + Squid reads the login items macOS lists in System Settings so the startup page can show the same ones. diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 36cca97..d61c589 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -5,6 +5,7 @@ //! The engine still re-validates every path against the same safety policy and //! whitelist used by the CLI and TUI. +use base64::{engine::general_purpose::STANDARD, Engine as _}; use squid_core::ledger::{self, Session}; use squid_core::paths; use squid_core::progress::{CancelToken, Event, Progress}; @@ -31,6 +32,7 @@ pub struct AppState { scans: Mutex>, plans: Mutex>, apps: Mutex>, + app_icons: Mutex>>, sampler: Mutex, } @@ -620,9 +622,38 @@ pub async fn apps_scan(app: AppHandle, job_id: String) -> Result().apps.lock() { *cache = apps.clone(); } + if let Ok(mut icons) = app.state::().app_icons.lock() { + icons.clear(); + } Ok(AppsView { apps, total }) } +/// Resolve one app's icon lazily so scanning does not pay for artwork the user +/// never opens. The result is cached; a missing icon is cached as `None` too. +#[tauri::command] +pub async fn app_icon(app: AppHandle, app_key: String) -> Result, String> { + if let Some(cached) = AppState::lock(&app.state::().app_icons)? + .get(&app_key) + .cloned() + { + return Ok(cached); + } + let chosen = AppState::lock(&app.state::().apps)? + .iter() + .find(|candidate| candidate.key() == app_key) + .cloned(); + let Some(chosen) = chosen else { + return Ok(None); + }; + let png = + tauri::async_runtime::spawn_blocking(move || squid_platform::apps::icon_png(&chosen, 64)) + .await + .map_err(|error| format!("Could not read the application icon: {error}"))?; + let icon = png.map(|bytes| format!("data:image/png;base64,{}", STANDARD.encode(bytes))); + AppState::lock(&app.state::().app_icons)?.insert(app_key, icon.clone()); + Ok(icon) +} + #[derive(Clone, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct PlanView { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 908077c..3e9168c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -226,6 +226,7 @@ pub fn run() { app::apps_scan, app::app_plan, app::app_uninstall, + app::app_icon, app::storage_explore, app::storage_largest_files, app::system_snapshot, @@ -262,6 +263,7 @@ pub fn run() { security::open_quarantine_folder, startup::startup_items, startup::startup_set_enabled, + startup::open_startup_settings, startup::process_inventory, startup::process_detail, startup::process_stop, diff --git a/src-tauri/src/startup.rs b/src-tauri/src/startup.rs index f139ee9..14dd8bf 100644 --- a/src-tauri/src/startup.rs +++ b/src-tauri/src/startup.rs @@ -13,36 +13,44 @@ use serde::Serialize; use squid_platform::process_table::ProcessRow; -use squid_platform::startup::{StartupInventory, StartupItem}; +use squid_platform::startup::{StartupCategory, StartupInventory, StartupItem, StartupNote}; use squid_platform::trust; -use std::path::PathBuf; +use std::collections::HashMap; +use std::path::{Path, PathBuf}; #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct StartupView { items: Vec, - notes: Vec, - user_count: usize, - system_count: usize, - disabled_count: usize, + notes: Vec, + /// The two lists the page shows, counted the way they are counted on screen. + login_count: usize, + background_count: usize, + /// Entries belonging to Apple or Microsoft, which are hidden by default. + vendor_count: usize, /// Entries the user owns that are not vendor-owned: what this page may act on. actionable_count: usize, risky_count: usize, - /// Which of the two platforms' surfaces were readable at all, so a page that - /// shows nothing can say whether that means "none" or "could not look". - sources: Vec, } impl StartupView { fn of(inventory: StartupInventory) -> StartupView { - let mut sources: Vec = inventory - .items - .iter() - .map(|item| item.source.as_str().to_string()) - .collect(); - sources.sort(); - sources.dedup(); StartupView { + login_count: inventory + .items + .iter() + .filter(|item| item.category == StartupCategory::OpenAtLogin) + .count(), + background_count: inventory + .items + .iter() + .filter(|item| item.category == StartupCategory::Background) + .count(), + vendor_count: inventory + .items + .iter() + .filter(|item| item.system_vendor) + .count(), actionable_count: inventory .items .iter() @@ -53,10 +61,6 @@ impl StartupView { .iter() .filter(|item| !item.risks.is_empty()) .count(), - user_count: inventory.user_count(), - system_count: inventory.system_count(), - disabled_count: inventory.disabled_count(), - sources, items: inventory.items, notes: inventory.notes, } @@ -117,6 +121,64 @@ pub async fn startup_set_enabled(id: String, enabled: bool) -> Result Result<(), String> { + #[cfg(target_os = "macos")] + let target = { + let version = crate::process::command("/usr/bin/sw_vers") + .arg("-productVersion") + .output() + .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned()) + .unwrap_or_default(); + let major: u32 = version + .split('.') + .next() + .and_then(|head| head.parse().ok()) + .unwrap_or(12); + if major >= 13 { + "x-apple.systempreferences:com.apple.LoginItems-Settings.extension" + } else { + "x-apple.systempreferences:com.apple.preference.users?LoginItems" + } + }; + // The pane Task Manager's Startup tab writes to. `ms-settings:startup` is not a + // URI and silently opens whatever was last shown. + #[cfg(windows)] + let target = "ms-settings:startupapps"; + + #[cfg(target_os = "macos")] + let opened = run("/usr/bin/open", &[target]); + #[cfg(windows)] + let opened = run("cmd", &["/C", "start", "", target]); + #[cfg(not(any(target_os = "macos", windows)))] + return Err("The system settings are not available here.".into()); + #[cfg(any(target_os = "macos", windows))] + opened +} + +/// The one shape the two platforms' settings openers differ in: a program, its +/// arguments, and whether the operating system accepted the request. +#[cfg(any(target_os = "macos", windows))] +fn run(program: &str, arguments: &[&str]) -> Result<(), String> { + let status = crate::process::command(program) + .args(arguments) + .status() + .map_err(|error| format!("Could not open the system settings: {error}"))?; + if status.success() { + Ok(()) + } else { + Err("Could not open the system settings.".into()) + } +} + #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct ProcessDetailView { @@ -133,12 +195,163 @@ pub struct ProcessDetailView { pub async fn process_inventory(with_trust: Option) -> Result, String> { let with_trust = with_trust.unwrap_or(true); tauri::async_runtime::spawn_blocking(move || -> Result, String> { - Ok(squid_platform::process_table::snapshot(with_trust).rows) + let mut rows = squid_platform::process_table::snapshot(with_trust).rows; + mark_startup_entries(&mut rows, &squid_platform::startup::inventory()); + Ok(rows) }) .await .map_err(|error| format!("Could not read the process table: {error}"))? } +/// Name the startup entry behind each process, which is what the table's "started by +/// a startup item" marker and its filter read. +/// +/// `ProcessRow::startup_item` says the desktop layer fills it in, and the marker has +/// been drawn from it since 0.1.6 — but nothing ever assigned it, so the icon never +/// appeared and "only started by an entry" returned nothing at all. +/// +/// Measured on an M1 Pro, ~760 processes and 874 entries: costs 0.45 s on top of the +/// 5.7 s the table already spends resolving signatures, and marks 452 of the rows. +/// The same read dominates the cheap path that skips signatures — 26 ms becomes 390 ms. +/// See ROADMAP 13.9 for why that trade was taken without caching. +fn mark_startup_entries(rows: &mut [ProcessRow], inventory: &StartupInventory) { + // Keyed once for the whole table. `entry_for` re-reads every root on every call, + // so using it per row would cost one inventory per process, several hundred of them, + // where the table already spends seconds reading signatures. + let mut declared: HashMap<&Path, &str> = HashMap::new(); + for item in &inventory.items { + // The inventory arrives user entries first, so keeping the first name seen + // prefers the entry this user owns when a vendor installs the same program + // twice (`com.google.keystone.agent` exists in both `~/Library` and `/Library`). + if let Some(program) = item.program.as_deref() { + declared.entry(program).or_insert(item.name.as_str()); + } + } + for row in rows { + row.startup_item = row + .program + .as_deref() + .and_then(|program| declared.get(program)) + .map(|name| (*name).to_string()); + } +} + +#[cfg(test)] +mod join_tests { + use super::mark_startup_entries; + use squid_platform::startup::{StartupInventory, StartupItem, StartupScope, StartupSource}; + use std::path::Path; + + /// The join costs one inventory read per refresh. Measured here rather than + /// asserted, because it is a latency decision, not a correctness one: the process + /// table has a deliberately cheap path that skips signature reads, and a join that + /// dwarfed it would be the wrong trade. + #[test] + #[ignore] + fn what_the_join_costs() { + use std::time::Instant; + for with_trust in [true, false] { + let start = Instant::now(); + let mut rows = squid_platform::process_table::snapshot(with_trust).rows; + let table = start.elapsed(); + let start = Instant::now(); + mark_startup_entries(&mut rows, &squid_platform::startup::inventory()); + let join = start.elapsed(); + let marked = rows.iter().filter(|row| row.startup_item.is_some()).count(); + println!( + "trust={with_trust}: table {table:.0?} + join {join:.0?} = {:.0?} · {marked}/{} marked", + table + join, + rows.len() + ); + } + } + + fn row(pid: u32, program: Option<&str>) -> super::ProcessRow { + super::ProcessRow { + pid, + parent: None, + name: "thing".into(), + command: String::new(), + program: program.map(Path::new).map(|p| p.to_path_buf()), + working_directory: None, + user: String::new(), + cpu: 0.0, + memory: 0, + started_ms: None, + startup_item: None, + signed: false, + publisher: None, + owned: true, + } + } + + fn entry(name: &str, program: &str) -> StartupItem { + let mut item = StartupItem::new( + format!("/Library/LaunchAgents/{name}.plist"), + name, + StartupSource::LaunchAgent, + StartupScope::User, + ); + item.program = Some(Path::new(program).to_path_buf()); + item + } + + /// The table has drawn a marker from this field since 0.1.6, and a filter has + /// keyed off it, but nothing ever wrote it: the icon never appeared and + /// "only started by an entry" returned nothing at all. + #[test] + fn a_process_is_matched_to_the_entry_that_declares_it() { + let inventory = StartupInventory { + items: vec![ + entry("com.user.keystone", "/opt/keystone/agent"), + entry("com.system.keystone", "/opt/keystone/agent"), + entry("com.other.thing", "/opt/other/thing"), + ], + notes: vec![], + }; + let mut rows = vec![ + row(1, Some("/opt/keystone/agent")), + row(2, Some("/opt/unrelated/app")), + row(3, None), + ]; + mark_startup_entries(&mut rows, &inventory); + + assert_eq!( + rows[0].startup_item.as_deref(), + Some("com.user.keystone"), + "an entry is named, and the user-owned one wins a duplicate program" + ); + assert_eq!( + rows[1].startup_item, None, + "a process nothing declared stays plain" + ); + assert_eq!( + rows[2].startup_item, None, + "a process with no path cannot be matched" + ); + } + + /// Disabling an entry does not necessarily stop the process it started, and that + /// is exactly when the link is worth seeing rather than losing. The detail drawer's + /// `entry_for` has never filtered on `disabled` either, so the two views agree. + #[test] + fn a_disabled_entry_still_names_the_process_it_left_running() { + let mut off = entry("com.user.updater", "/opt/updater/agent"); + off.disabled = true; + let inventory = StartupInventory { + items: vec![off], + notes: vec![], + }; + let mut rows = vec![row(9, Some("/opt/updater/agent"))]; + mark_startup_entries(&mut rows, &inventory); + assert_eq!( + rows[0].startup_item.as_deref(), + Some("com.user.updater"), + "the row that explains why this is still running must not disappear" + ); + } +} + #[tauri::command] pub async fn process_detail(pid: u32) -> Result { tauri::async_runtime::spawn_blocking(move || -> Result { @@ -226,3 +439,88 @@ pub async fn process_stop(pid: u32, name: String) -> Result>()) + ); + } +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1d8952b..6db9803 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Squid", - "version": "0.1.6", + "version": "0.1.7", "identifier": "app.nex.squid", "mainBinaryName": "squid-desktop", "build": { diff --git a/src/App.tsx b/src/App.tsx index ee44113..5108f57 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -61,8 +61,8 @@ const NAV_GROUPS: { items: [ { id: "overview", - labelEn: "Computer overview", - labelZh: "电脑概览", + labelEn: "Overview", + labelZh: "概览", icon: LayoutDashboard, }, { @@ -114,7 +114,7 @@ const NAV_GROUPS: { ]; const PAGE_TITLES: Record = { - overview: ["Computer overview", "电脑概览"], + overview: ["Overview", "概览"], cleanup: ["Daily cleanup", "日常清理"], applications: ["Uninstall apps", "应用卸载"], purge: ["Deep Clean", "深度清理"], @@ -367,7 +367,6 @@ export default function App() { bootstrap={bootstrap} snapshot={system.snapshot} cleanup={cleanup} - security={security} onNavigate={setPage} /> ) : null} diff --git a/src/components/CleanupView.tsx b/src/components/CleanupView.tsx index 5b1181b..4e0c498 100644 --- a/src/components/CleanupView.tsx +++ b/src/components/CleanupView.tsx @@ -292,10 +292,6 @@ export function CleanupInventory({ ? categoryLabel(focus, lang) : t("Everything found in this scan", "本次扫描的全部项目") } - subtitle={t( - "Only checked items are touched. Protected items stay locked.", - "只会处理已勾选的项目,受保护项目始终保持锁定。", - )} action={ focus ? ( ))} @@ -337,7 +337,7 @@ export function ProcessTable({ {row.user} {row.cpu.toFixed(1)}% - {formatBytes(row.memory)} + {formatMemoryBytes(row.memory)} {row.startedMs ? new Date(row.startedMs).toLocaleTimeString() : "—"} @@ -466,10 +466,7 @@ export function ProcessTable({ open={Boolean(victim)} title={t("Stop this process?", "结束此进程?")} message={victim ? `${victim.name} · PID ${victim.pid}` : ""} - note={t( - "Unsaved work here may be lost. Only your own processes can be stopped.", - "进程中未保存的内容可能丢失。只会结束当前用户的进程。", - )} + note={t("Unsaved work here may be lost.", "进程中未保存的内容可能丢失。")} confirmLabel={t("Stop process", "结束进程")} cancelLabel={t("Cancel", "取消")} busy={stopping} @@ -550,10 +547,7 @@ function ProcessDetailBody({

) : null}

- {t( - "Stopping a process never touches its file. Quarantine needs a confirmed finding.", - "结束进程不会处理其文件;只有已确认发现才会隔离。", - )} + {t("Stopping a process never touches its files.", "结束进程不会处理其文件。")}

); diff --git a/src/components/SecuritySettingsCard.tsx b/src/components/SecuritySettingsCard.tsx index 5c330c5..7ef23d5 100644 --- a/src/components/SecuritySettingsCard.tsx +++ b/src/components/SecuritySettingsCard.tsx @@ -13,7 +13,7 @@ import { api } from "../lib/api"; import { messageFrom, shortPath } from "../lib/format"; import type { ScanSchedule, SecurityStatus } from "../types"; import type { SecurityWorkspace } from "../hooks/useSecurityWorkspace"; -import { Button, ConfirmDialog, Toggle, useToast } from "./ui"; +import { Button, ConfirmDialog, Select, Toggle, useToast } from "./ui"; const SCHEDULES: [ScanSchedule, string, string][] = [ ["manual", "Only when I ask", "仅在我要求时"], @@ -99,12 +99,6 @@ export function SecuritySettingsCard({ {t("Security", "安全")}

-

- {t( - "When scans run, what may move without asking, and what a scan must not read.", - "扫描何时运行、什么可以不经确认就移动,以及扫描不能读取哪些位置。", - )} -

@@ -123,18 +117,13 @@ export function SecuritySettingsCard({ )} - + label={t("Scan schedule", "扫描计划")} + options={SCHEDULES.map(([value, en, zh]) => ({ value, label: t(en, zh) }))} + onChange={(next) => void save({ scanSchedule: next })} + />
@@ -208,8 +197,8 @@ export function SecuritySettingsCard({ {rulesNote ?? t( - "Rules are downloaded to this machine. No file name, hash or result is ever sent out.", - "规则只会下载到本机;文件名、哈希与扫描结果都不会上传。", + "Rules are downloaded to this machine; nothing is ever sent out.", + "规则只下载到本机,不上传任何内容。", )}
diff --git a/src/components/SetupPanel.tsx b/src/components/SetupPanel.tsx index bbe4b5d..6a95cbe 100644 --- a/src/components/SetupPanel.tsx +++ b/src/components/SetupPanel.tsx @@ -182,17 +182,14 @@ export function SetupPanel({ `${ protection.productName || (protection.provider === "xprotect" ? "XProtect" : protection.provider) - }${protection.definitions ? ` · ${protection.definitions}` : ""}. Squid reads this and never turns it on, off or updates it.`, + }${protection.definitions ? ` · ${protection.definitions}` : ""}. Read-only.`, `${ protection.productName || (protection.provider === "xprotect" ? "XProtect" : protection.provider) - }${protection.definitions ? ` · ${protection.definitions}` : ""}。Squid 只读取该状态,不会开启、关闭或更新它。`, + }${protection.definitions ? ` · ${protection.definitions}` : ""}。只读取,不改动。`, ) : protection?.notes[0] ?? - t( - "When this cannot be read Squid says so, rather than showing it as healthy.", - "读不到时 Squid 会直接说明,不会把它显示为正常。", - ) + t("Squid reports this instead of guessing.", "读不到时会直接说明,不会显示为正常。") } /> @@ -233,7 +230,7 @@ export function SetupPanel({ }} note={t( "Confirmed findings only. The banner and tray still report without it.", - "仅针对已确认发现。关闭后应用内提示与托盘仍会显示。", + "仅针对已确认发现,应用内提示与托盘不受影响。", )} action={ - - + } /> {startup.error ? : null} - {view ? ( -
-
- {view.userCount} - {t("for your user", "属于当前用户")} -
-
- {view.systemCount} - {t("system-wide", "系统级")} -
-
- {view.disabledCount} - {t("turned off", "已停用")} -
-
- {view.actionableCount} - {t("squid may change", "Squid 可修改")} -
-
- {view.riskyCount} - {t("worth a look", "值得检查")} -
-
- ) : null} - {view?.notes.length ? (
{view.notes.map((note) => ( - + - {note} + {note.kind === "login-items-unavailable" + ? t( + "macOS has not let Squid read the login items.", + "macOS 尚未允许 Squid 读取登录项。", + ) + : t("This folder could not be listed:", "以下目录无法读取:")}{" "} + {note.kind === "unreadable-root" ? note.subject : null} + {note.detail ? ` — ${note.detail}` : ""} ))}
) : null} +
+ {( + [ + ["open-at-login", t("Login items", "登录项")], + ["background", t("Background", "后台程序")], + ] as [Tab, string][] + ).map(([key, label]) => ( + + ))} +
+
- {( - [ - ["user", t("My user", "当前用户")], - ["system", t("System", "系统")], - ["all", t("All scopes", "全部范围")], - ] as [ScopeFilter, string][] - ).map(([key, label]) => ( - - ))} - - + ` does not move a layout; only the popup + is new, and it is drawn with the same shell as a panel. */ +.select { + position: relative; + flex: 0 0 auto; +} + +.select-trigger { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; min-width: 86px; height: 31px; padding: 0 9px; @@ -3700,6 +3859,88 @@ select:focus-visible, color: var(--nex-ink); background: var(--nex-paper); font-size: var(--nex-text-3xs); + transition: border-color 0.14s ease; +} + +.select-trigger:hover:not(:disabled) { + border-color: rgba(var(--nex-primary-rgb), 0.4); +} + +.select-trigger:disabled { + opacity: 0.55; + cursor: default; +} + +.select-trigger span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.select-trigger svg { + flex: 0 0 auto; + color: var(--nex-muted-soft); + transition: transform 0.14s ease; +} + +.select-trigger svg.is-open { + transform: rotate(180deg); +} + +.select-menu { + position: absolute; + top: calc(100% + 5px); + z-index: 30; + display: grid; + gap: 1px; + min-width: 100%; + max-height: 288px; + margin: 0; + padding: 5px; + overflow: auto; + list-style: none; + border: 1px solid var(--nex-line); + border-radius: 11px; + background: var(--nex-paper); + box-shadow: var(--shadow-float); +} + +.select-menu.is-start { + left: 0; +} + +.select-menu.is-end { + right: 0; +} + +.select-menu button { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + width: 100%; + padding: 6px 8px; + border: 0; + border-radius: 7px; + color: var(--nex-ink); + background: none; + font-size: var(--nex-text-3xs); + text-align: left; + white-space: nowrap; +} + +.select-menu button.is-active { + background: var(--nex-primary-tint); +} + +.select-menu button.is-current { + color: var(--nex-primary-strong); + font-weight: var(--nex-weight-semibold); +} + +.select-menu svg { + flex: 0 0 auto; + color: var(--nex-primary); } .whitelist-add { @@ -3822,16 +4063,6 @@ select:focus-visible, font-weight: var(--nex-weight-semibold); } -.settings-footer { - display: flex; - align-items: center; - justify-content: center; - gap: 6px; - padding: 13px; - color: var(--nex-muted-soft); - font-size: var(--nex-text-3xs); - text-align: center; -} /* Update panel */ @@ -4246,12 +4477,6 @@ select:focus-visible, line-height: var(--nex-leading-body); } -.setup-note { - margin: 14px 1px 0; - color: var(--nex-muted-soft); - font-size: var(--nex-text-3xs); - line-height: var(--nex-leading-body); -} .setup-foot { display: flex; @@ -4705,7 +4930,7 @@ select:focus-visible, } .overview-hero { - grid-template-columns: minmax(0, 1.2fr) 250px; + grid-template-columns: minmax(0, 1fr) 330px; padding: 27px; } @@ -4738,7 +4963,7 @@ select:focus-visible, } .overview-hero { - grid-template-columns: minmax(0, 1fr) 218px; + grid-template-columns: minmax(0, 1fr) 285px; padding: 24px; } @@ -4746,8 +4971,17 @@ select:focus-visible, font-size: var(--nex-text-hero); } - .overview-gauge-wrap .gauge { - transform: scale(0.86); + .overview-hero-copy { + padding-right: 12px; + } + + .overview-machine { + padding-left: 18px; + } + + .machine-row { + grid-template-columns: 22px 66px minmax(0, 1fr); + gap: 6px; } .quick-grid, @@ -5136,10 +5370,12 @@ select:focus-visible, } /* One row for everything that can be opened: a finding, a startup item, a - quarantined file. The tone class is the only difference between them. */ + quarantined file. Flat rows divided by one hairline, the way every older list + in the app is built — no card per entry, no rounded corners, no indicator bar. + A tone tints the text of a row, never its edge. */ .item-list { - display: grid; - gap: 6px; + display: flex; + flex-direction: column; margin: 0; padding: 0; list-style: none; @@ -5149,24 +5385,33 @@ select:focus-visible, display: flex; align-items: center; gap: 12px; - padding: 10px 12px; - border: 1px solid var(--nex-line); - border-radius: var(--radius-md); - background: rgba(255, 255, 255, 0.62); + min-height: 44px; + padding: 7px 10px; + border-bottom: 1px solid var(--nex-line); + background: transparent; + transition: background 0.14s ease; } -.item-row.is-danger { - border-left: 3px solid var(--nex-danger); +.item-row:last-child { + border-bottom: 0; } -.item-row.is-warning, -.item-row.is-risky { - border-left: 3px solid var(--nex-warning); +.item-row:hover { + background: var(--nex-cream); +} + +.item-row.is-danger .item-copy strong { + color: var(--nex-danger-strong); +} + +.item-row.is-warning .item-copy strong, +.item-row.is-risky .item-copy strong { + color: var(--nex-warning-strong); } .item-row.is-handled, .item-row.is-off { - opacity: 0.62; + opacity: 0.64; } /* The whole row is one button, which is why the reset is here rather than in a @@ -5226,22 +5471,6 @@ select:focus-visible, gap: 6px; } -.level-dot { - flex: 0 0 8px; - width: 8px; - height: 8px; - border-radius: 50%; - background: var(--nex-muted-soft); -} - -.level-dot.is-danger { - background: var(--nex-danger); -} - -.level-dot.is-warning { - background: var(--nex-warning); -} - /* Detail drawer body, shared by findings, startup items and processes. */ .item-detail { display: grid; @@ -5284,23 +5513,27 @@ select:focus-visible, .evidence-list { display: grid; - gap: 7px; margin: 0; padding: 0; list-style: none; } +/* One hairline per row, like every other list: the evidence is a table of facts, + not a stack of cards. */ .evidence-list li { display: grid; grid-template-columns: 108px 1fr; gap: 10px; - padding: 9px 11px; - border-radius: var(--radius-sm); - background: var(--nex-cream); + padding: 8px 0; + border-bottom: 1px solid var(--nex-line); font-size: var(--nex-text-2xs); line-height: var(--nex-leading-body); } +.evidence-list li:last-child { + border-bottom: 0; +} + .evidence-key { color: var(--nex-primary-strong); font-family: var(--nex-font-mono); @@ -5469,44 +5702,10 @@ select:focus-visible, text-align: center; } -.stat-grid { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); - gap: 12px; -} -.stat { - display: grid; - gap: 2px; - padding: 13px 15px; - border: 1px solid var(--nex-line); - border-radius: var(--radius-lg); - background: rgba(255, 255, 255, 0.73); - box-shadow: var(--shadow-card); -} -.stat strong { - font-size: var(--nex-text-xl); - font-weight: var(--nex-weight-bold); -} -.stat span { - color: var(--nex-muted); - font-size: var(--nex-text-3xs); -} -.stat.is-warning { - border-color: rgba(var(--nex-warning-rgb), 0.26); - background: var(--nex-warning-soft); -} - -.startup-meta { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 5px; - max-width: 46%; -} /* Where the entry is declared: LaunchAgent, Run, a login item. quieter than the name it qualifies, because most rows are the kind the user never touches. */ @@ -5517,18 +5716,6 @@ select:focus-visible, white-space: nowrap; } -.risk-chip { - display: inline-flex; - align-items: center; - gap: 3px; - padding: 2px 7px; - border-radius: 999px; - background: rgba(var(--nex-warning-rgb), 0.14); - color: var(--nex-warning-strong); - font-size: var(--nex-text-3xs); - font-weight: var(--nex-weight-medium); - white-space: nowrap; -} .muted-note { display: inline-flex; @@ -5539,28 +5726,72 @@ select:focus-visible, white-space: nowrap; } -.startup-batch { +/* Startup groups: one application and the entries it installed. The head is the + same flat, hairline-separated row as everything else it contains, and the rows + under it are ordinary `.item-row`s that have only been indented. */ +.group-list { display: flex; - align-items: center; - justify-content: space-between; - gap: 14px; - padding: 10px 14px; - border: 1px solid rgba(var(--nex-primary-rgb), 0.24); - border-radius: var(--radius-md); - background: var(--nex-primary-tint); + flex-direction: column; + margin: 0; + padding: 0; + list-style: none; } -.startup-batch-all { +.group-head { display: flex; align-items: center; - gap: 10px; + gap: 12px; + width: 100%; + min-height: 44px; + padding: 7px 10px; + border-bottom: 1px solid var(--nex-line); + background: transparent; + text-align: left; + transition: background 0.14s ease; +} + +.group-head:hover { + background: var(--nex-cream); +} + +.group-head > .item-copy strong { + font-size: var(--nex-text-xs); +} + +.group-meta { + display: flex; + flex: 0 0 auto; + align-items: center; + gap: 6px; +} + +.group-count { + min-width: 22px; color: var(--nex-muted); - font-size: var(--nex-text-2xs); + font-size: var(--nex-text-3xs); + font-variant-numeric: tabular-nums; + text-align: right; } -.startup-batch-actions { - display: flex; - gap: 8px; +.group-arrow { + flex: 0 0 auto; + color: var(--nex-muted-soft); + transition: transform 0.14s ease; +} + +.group-arrow.is-open { + transform: rotate(180deg); +} + +/* Nested rather than boxed: the rows belong to the group above them, which a card + around each one would deny. */ +.item-list.is-nested .item-row { + padding-left: 28px; + background: rgba(255, 255, 255, 0.4); +} + +.item-list.is-nested .item-row:last-child { + border-bottom: 1px solid var(--nex-line); } /* -------------------------------------------------------------- process table */ @@ -5604,7 +5835,6 @@ select:focus-visible, .ptable.pt-rows { display: grid; - gap: 2px; margin: 0; padding: 0; list-style: none; @@ -5615,11 +5845,14 @@ select:focus-visible, .ptable.pt-rows li { min-height: 38px; padding: 5px 11px; - border-radius: var(--radius-sm); } -.ptable.pt-rows li:nth-child(odd) { - background: rgba(255, 255, 255, 0.55); +.ptable.pt-rows li:not(:last-child) { + border-bottom: 1px solid var(--nex-line); +} + +.ptable.pt-rows li:hover { + background: var(--nex-cream); } .ptable.pt-rows li.is-flagged { @@ -5703,8 +5936,15 @@ select:focus-visible, /* Grouped by application: the group header is a row of the same shape, so the columns line up with the rows it opens. */ .process-grouped { - display: grid; - gap: 3px; + display: flex; + flex-direction: column; + margin: 0; + padding: 0; + list-style: none; +} + +.process-grouped > li:not(:last-child) > .process-group-head { + border-bottom: 1px solid var(--nex-line); } .process-group-head { @@ -5714,13 +5954,11 @@ select:focus-visible, align-items: center; width: 100%; padding: 9px 11px; - border-radius: var(--radius-sm); - background: rgba(255, 255, 255, 0.55); text-align: left; } .process-group-head:hover { - background: rgba(255, 255, 255, 0.9); + background: var(--nex-cream); } .process-group-head strong { @@ -5804,8 +6042,4 @@ select:focus-visible, .item-row { flex-wrap: wrap; } - - .startup-meta { - max-width: 100%; - } } diff --git a/src/types.ts b/src/types.ts index 5dacca6..11d8ead 100644 --- a/src/types.ts +++ b/src/types.ts @@ -116,6 +116,7 @@ export interface AppInfo { name: string; bundle_id: string | null; path: string; + icon_source: string | null; version: string | null; size: number; source: string; @@ -212,6 +213,7 @@ export interface SystemSnapshot { os_name: string; os_version: string; hardware: string; + gpu: string; hostname: string; user: string; arch: string; @@ -440,10 +442,31 @@ export type StartupRisk = | "missing-target" | "in-temp-dir" | "unsigned" + | "signature-unreadable" | "script-interpreter" | "recently-created" | "hidden-entry" | "hidden-home-directory"; +export type StartupCategory = "open-at-login" | "background"; +/** Something squid has to admit it could not read; the page says it in its own language. */ +export interface StartupNote { + kind: "unreadable-root" | "login-items-unavailable"; + subject: string; + detail: string; +} +export type StartupLock = + | "operating-system" + | "needs-authorisation" + | "not-writable" + | "managed-by-system-settings" + | "not-managed"; + +/** The application an entry belongs to, as both operating systems group them. */ +export interface StartupOwner { + name: string; + bundlePath: string | null; + vendor: boolean; +} export interface StartupItem { id: string; @@ -458,21 +481,22 @@ export interface StartupItem { systemVendor: boolean; disabled: boolean; modifiable: boolean; - readonlyReason: string | null; + lock: StartupLock | null; hidden: boolean; modifiedMs: number | null; risks: StartupRisk[]; + category: StartupCategory; + owner: StartupOwner | null; } export interface StartupView { items: StartupItem[]; - notes: string[]; - userCount: number; - systemCount: number; - disabledCount: number; + notes: StartupNote[]; + loginCount: number; + backgroundCount: number; + vendorCount: number; actionableCount: number; riskyCount: number; - sources: string[]; } export interface StartupChange {