diff --git a/crates/squid-platform/src/lib.rs b/crates/squid-platform/src/lib.rs index 52e2d86..9036a06 100644 --- a/crates/squid-platform/src/lib.rs +++ b/crates/squid-platform/src/lib.rs @@ -150,6 +150,79 @@ pub trait Platform: Send + Sync { /// Open the system Trash (Finder / explorer / xdg-open). fn reveal_trash(&self) {} + + /// What would happen to a file sent to the Trash *right now*. Cheap: one + /// metadata check at most, since the status line calls it per render. + fn trash_target(&self) -> TrashTarget { + TrashTarget::Unreachable + } + + /// What to call the machine when squid talks to a person about it. This is + /// a property of the platform, not of the locale: the Chinese UI on a + /// Windows box must not inherit "这台 Mac" from the macOS build either. + fn device(&self) -> Device { + Device::Machine + } + + /// What the operating system calls the place deleted files wait in. + /// + /// Explorer says 回收站 / "Recycle Bin", and that is the only name a Windows + /// user can act on: there is no Trash folder to open, so copy that promises + /// "empty the Trash" points at something the user cannot find. + fn bin_noun(&self) -> BinNoun { + BinNoun::Trash + } +} + +/// What the operating system calls the place deleted files wait in. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum BinNoun { + /// macOS and the freedesktop trash: 「废纸篓」. + Trash, + /// Windows: 回收站. + RecycleBin, +} + +impl BinNoun { + /// The name as an English speaker of the interface would see it. + pub fn en(self) -> &'static str { + match self { + BinNoun::Trash => "Trash", + BinNoun::RecycleBin => "Recycle Bin", + } + } + + /// The name as a Chinese speaker of the interface would see it. + pub fn zh(self) -> &'static str { + match self { + BinNoun::Trash => "废纸篓", + BinNoun::RecycleBin => "回收站", + } + } +} + +/// What the machine squid runs on is called when squid addresses a person. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Device { + Mac, + Pc, + Machine, +} + +/// Where a file sent to the Trash actually lands, as far as the user can tell. +/// +/// `doctor` used to probe `~/.Trash` unconditionally and conclude on Windows +/// that "deletions fall back to permanent", which was wrong: the shell Recycle +/// Bin is there, it is just not a folder squid can name or list. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum TrashTarget { + /// The shell Recycle Bin. Reachable and restorable, but the shell owns the + /// bookkeeping, so there is no folder path to show. + RecycleBin, + /// A real trash folder that exists right now. + Folder(PathBuf), + /// Nothing reachable — sending to the Trash would end up permanent. + Unreachable, } /// Concrete adapter for the host we are running on. diff --git a/crates/squid-platform/src/linux.rs b/crates/squid-platform/src/linux.rs index 55dcbf5..93ea2a0 100644 --- a/crates/squid-platform/src/linux.rs +++ b/crates/squid-platform/src/linux.rs @@ -1,6 +1,6 @@ //! Linux adapter: `.desktop` entries, Flatpak/Snap awareness, XDG leftovers. -use crate::{AppSource, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId}; +use crate::{AppSource, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId, TrashTarget}; use squid_core::progress::CancelToken; use squid_core::{AppInfo, Bytes, Category, Result, Volume}; use std::collections::BTreeMap; @@ -307,4 +307,18 @@ impl Platform for Linux { .spawn(); let _ = trash; } + + fn trash_target(&self) -> TrashTarget { + // The XDG spec puts it under $XDG_DATA_HOME; in practice ~/.local/share. + let root = std::env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .filter(|p| p.is_absolute()) + .unwrap_or_else(|| home().join(".local").join("share")); + let trash = root.join("Trash"); + if trash.is_dir() { + TrashTarget::Folder(trash) + } else { + TrashTarget::Unreachable + } + } } diff --git a/crates/squid-platform/src/macos.rs b/crates/squid-platform/src/macos.rs index a332fb2..e33f505 100644 --- a/crates/squid-platform/src/macos.rs +++ b/crates/squid-platform/src/macos.rs @@ -1,7 +1,9 @@ //! macOS adapter: `.app` bundles, sandbox containers, launch services. use crate::apps::{app_from_bundle, discover_bundles}; -use crate::{AppSource, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId}; +use crate::{ + AppSource, Device, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId, TrashTarget, +}; use rayon::prelude::*; use squid_core::progress::CancelToken; use squid_core::{AppInfo, Category, Result, SquidError, Volume}; @@ -320,6 +322,19 @@ impl Platform for MacOs { quiet("open", &[&home().join(".Trash").to_string_lossy()]); } + fn device(&self) -> Device { + Device::Mac + } + + fn trash_target(&self) -> TrashTarget { + let trash = home().join(".Trash"); + if trash.is_dir() { + TrashTarget::Folder(trash) + } else { + TrashTarget::Unreachable + } + } + fn inspect_path(&self, path: &Path) -> Option { // Sandboxed containers are owned by containermanagerd; deleting the // folder without the metadata file upsets the sandbox service. diff --git a/crates/squid-platform/src/windows.rs b/crates/squid-platform/src/windows.rs index 4e1599d..1fb7d69 100644 --- a/crates/squid-platform/src/windows.rs +++ b/crates/squid-platform/src/windows.rs @@ -2,7 +2,10 @@ //! (HKLM 64-bit + 32-bit views, HKCU), leftovers from the well-known //! AppData/ProgramData folders, volumes and processes from `sysinfo`. -use crate::{AppSource, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId}; +use crate::{ + AppSource, BinNoun, Device, LeftoverRoot, LifecycleReport, Naming, Platform, PlatformId, + TrashTarget, +}; use squid_core::progress::CancelToken; use squid_core::{AppInfo, Bytes, Category, Result, Volume}; use std::path::{Path, PathBuf}; @@ -297,4 +300,20 @@ impl Platform for Windows { .arg("shell:RecycleBinFolder") .spawn(); } + + fn device(&self) -> Device { + Device::Pc + } + + fn bin_noun(&self) -> BinNoun { + BinNoun::RecycleBin + } + + fn trash_target(&self) -> TrashTarget { + // Every interactive Windows desktop has a Recycle Bin for its drive; + // squid writes it through `IFileOperation` rather than a folder, so + // there is no path to report. `SHEmptyRecycleBinW` failing is the only + // signal that the shell refused, and that is a per-deletion error. + TrashTarget::RecycleBin + } }