feat: make trash optional

This commit is contained in:
sxyazi 2023-09-18 07:46:42 +08:00
parent c540542da4
commit 2447917ac7
No known key found for this signature in database
2 changed files with 17 additions and 10 deletions

View file

@ -26,9 +26,13 @@ syntect = "^5"
tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "time", "fs", "process", "io-std", "io-util" ] } tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "time", "fs", "process", "io-std", "io-util" ] }
tokio-stream = "^0" tokio-stream = "^0"
tracing = "^0" tracing = "^0"
trash = "^3" trash = { version = "^3", optional = true }
unicode-width = "^0" unicode-width = "^0"
yazi-prebuild = "^0" yazi-prebuild = "^0"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
clipboard-win = "^4" clipboard-win = "^4"
[features]
trash_bin = [ "trash" ]
default = [ "trash_bin" ]

View file

@ -152,16 +152,19 @@ impl File {
self.sch.send(TaskOp::Adv(task.id, 1, task.length))? self.sch.send(TaskOp::Adv(task.id, 1, task.length))?
} }
FileOp::Trash(task) => { FileOp::Trash(task) => {
#[cfg(target_os = "macos")] #[cfg(feature = "trash_bin")]
{ {
use trash::{macos::{DeleteMethod, TrashContextExtMacos}, TrashContext}; #[cfg(target_os = "macos")]
let mut ctx = TrashContext::default(); {
ctx.set_delete_method(DeleteMethod::NsFileManager); use trash::{macos::{DeleteMethod, TrashContextExtMacos}, TrashContext};
ctx.delete(&task.target)?; let mut ctx = TrashContext::default();
} ctx.set_delete_method(DeleteMethod::NsFileManager);
#[cfg(not(target_os = "macos"))] ctx.delete(&task.target)?;
{ }
trash::delete(&task.target)?; #[cfg(not(target_os = "macos"))]
{
trash::delete(&task.target)?;
}
} }
self.sch.send(TaskOp::Adv(task.id, 1, task.length))?; self.sch.send(TaskOp::Adv(task.id, 1, task.length))?;
} }