refactor: promote Id to the task scheduler (#2873)

This commit is contained in:
三咲雅 misaki masa 2025-06-14 12:07:22 +08:00 committed by GitHub
parent 0eec8fc80e
commit aae3f9ea4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 179 additions and 107 deletions

146
Cargo.lock generated
View file

@ -213,7 +213,7 @@ dependencies = [
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -349,9 +349,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.26"
version = "1.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac"
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
dependencies = [
"jobserver",
"libc",
@ -735,7 +735,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
]
[[package]]
@ -1442,9 +1442,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.7.4"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "minimal-lexical"
@ -1810,7 +1810,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -1845,9 +1845,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "plist"
version = "1.7.1"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eac26e981c03a6e53e0aee43c113e3202f5581d5360dae7bd2c70e800dd0451d"
checksum = "3d77244ce2d584cd84f6a15f86195b8c9b2a0dfbfd817c09e0464244091a58ed"
dependencies = [
"base64",
"indexmap",
@ -1964,9 +1964,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.32.0"
version = "0.37.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2"
checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb"
dependencies = [
"memchr",
]
@ -2133,9 +2133,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.12"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [
"bitflags 2.9.1",
]
@ -2486,9 +2486,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.102"
version = "2.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462"
checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8"
dependencies = [
"proc-macro2",
"quote",
@ -2594,12 +2594,11 @@ dependencies = [
[[package]]
name = "thread_local"
version = "1.1.8"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
@ -3129,7 +3128,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
dependencies = [
"windows-core 0.56.0",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -3141,7 +3140,7 @@ dependencies = [
"windows-implement 0.56.0",
"windows-interface 0.56.0",
"windows-result 0.1.2",
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -3203,9 +3202,9 @@ dependencies = [
[[package]]
name = "windows-link"
version = "0.1.1"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-result"
@ -3213,7 +3212,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
dependencies = [
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -3240,7 +3239,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
@ -3249,7 +3248,16 @@ version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets 0.53.2",
]
[[package]]
@ -3258,14 +3266,30 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm 0.52.6",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.53.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef"
dependencies = [
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
"windows_i686_gnullvm 0.53.0",
"windows_i686_msvc 0.53.0",
"windows_x86_64_gnu 0.53.0",
"windows_x86_64_gnullvm 0.53.0",
"windows_x86_64_msvc 0.53.0",
]
[[package]]
@ -3274,48 +3298,96 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "winnow"
version = "0.7.11"
@ -3583,7 +3655,7 @@ dependencies = [
"tokio",
"tracing",
"uzers",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
"yazi-ffi",
"yazi-macro",
"yazi-shared",
@ -3618,7 +3690,7 @@ dependencies = [
"twox-hash",
"unicode-width 0.2.0",
"uzers",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
"yazi-adapter",
"yazi-binding",
"yazi-boot",
@ -3690,7 +3762,7 @@ dependencies = [
"tokio",
"tracing",
"uzers",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
"yazi-macro",
]
@ -3702,7 +3774,7 @@ dependencies = [
"libc",
"parking_lot",
"tracing",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
"yazi-macro",
"yazi-shared",
]

View file

@ -13,5 +13,5 @@ proc-macro = true
[dependencies]
# External dependencies
syn = { version = "2.0.102", features = [ "full" ] }
syn = { version = "2.0.103", features = [ "full" ] }
quote = "1.0.40"

View file

@ -55,7 +55,7 @@ impl App {
drain_events!();
}
}
} else if rx.recv_many(&mut events, 50).await > 0 {
} else if rx.recv_many(&mut events, 50).await != 0 {
drain_events!();
} else {
break;

View file

@ -32,7 +32,7 @@ libc = { workspace = true }
uzers = { workspace = true }
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = [ "Win32_Storage_FileSystem" ] }
windows-sys = { version = "0.60.2", features = [ "Win32_Storage_FileSystem" ] }
[target.'cfg(target_os = "macos")'.dependencies]
core-foundation-sys = { workspace = true }

View file

@ -12,10 +12,7 @@ use yazi_shared::natsort;
use super::{Locked, Partition, Partitions};
impl Partitions {
pub fn monitor<F>(me: Locked, cb: F)
where
F: Fn() + Copy + Send + 'static,
{
pub fn monitor(me: Locked, cb: fn()) {
tokio::task::spawn_blocking(move || {
let session = unsafe { DASessionCreate(kCFAllocatorDefault) };
if session.is_null() {

View file

@ -51,7 +51,7 @@ uzers = { workspace = true }
[target."cfg(windows)".dependencies]
clipboard-win = "5.4.0"
windows-sys = { version = "0.59.0", features = [ "Win32_System_JobObjects" ] }
windows-sys = { version = "0.60.2", features = [ "Win32_System_JobObjects" ] }
[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }

View file

@ -5,7 +5,7 @@ use tokio::{fs::{self, DirEntry}, io::{self, ErrorKind::{AlreadyExists, NotFound
use tracing::warn;
use yazi_config::YAZI;
use yazi_fs::{SizeCalculator, cha::Cha, copy_with_progress, maybe_exists, ok_or_not_found, path_relative_to, skip_path};
use yazi_shared::url::Url;
use yazi_shared::{Id, url::Url};
use super::{FileIn, FileInDelete, FileInHardlink, FileInLink, FileInPaste, FileInTrash};
use crate::{LOW, NORMAL, TaskOp, TaskProg};
@ -343,17 +343,15 @@ impl File {
impl File {
#[inline]
fn succ(&self, id: usize) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
fn succ(&self, id: Id) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
#[inline]
fn fail(&self, id: usize, reason: String) -> Result<()> {
fn fail(&self, id: Id, reason: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Fail(id, reason))?)
}
#[inline]
fn log(&self, id: usize, line: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Log(id, line))?)
}
fn log(&self, id: Id, line: String) -> Result<()> { Ok(self.prog.send(TaskProg::Log(id, line))?) }
#[inline]
async fn queue(&self, r#in: impl Into<TaskOp>, priority: u8) -> Result<()> {

View file

@ -1,5 +1,5 @@
use yazi_fs::cha::Cha;
use yazi_shared::url::Url;
use yazi_shared::{Id, url::Url};
#[derive(Debug)]
pub enum FileIn {
@ -11,7 +11,7 @@ pub enum FileIn {
}
impl FileIn {
pub fn id(&self) -> usize {
pub fn id(&self) -> Id {
match self {
Self::Paste(r#in) => r#in.id,
Self::Link(r#in) => r#in.id,
@ -25,7 +25,7 @@ impl FileIn {
// --- Paste
#[derive(Clone, Debug)]
pub struct FileInPaste {
pub id: usize,
pub id: Id,
pub from: Url,
pub to: Url,
pub cha: Option<Cha>,
@ -51,7 +51,7 @@ impl FileInPaste {
// --- Link
#[derive(Clone, Debug)]
pub struct FileInLink {
pub id: usize,
pub id: Id,
pub from: Url,
pub to: Url,
pub cha: Option<Cha>,
@ -77,7 +77,7 @@ impl From<FileInPaste> for FileInLink {
// --- Hardlink
#[derive(Clone, Debug)]
pub struct FileInHardlink {
pub id: usize,
pub id: Id,
pub from: Url,
pub to: Url,
pub cha: Option<Cha>,
@ -93,7 +93,7 @@ impl FileInHardlink {
// --- Delete
#[derive(Clone, Debug)]
pub struct FileInDelete {
pub id: usize,
pub id: Id,
pub target: Url,
pub length: u64,
}
@ -101,7 +101,7 @@ pub struct FileInDelete {
// --- Trash
#[derive(Clone, Debug)]
pub struct FileInTrash {
pub id: usize,
pub id: Id,
pub target: Url,
pub length: u64,
}

View file

@ -1,3 +1,5 @@
use yazi_shared::Id;
use crate::{file::FileIn, plugin::PluginIn, prework::PreworkIn};
#[derive(Debug)]
@ -8,7 +10,7 @@ pub enum TaskOp {
}
impl TaskOp {
pub fn id(&self) -> usize {
pub fn id(&self) -> Id {
match self {
TaskOp::File(r#in) => r#in.id(),
TaskOp::Plugin(r#in) => r#in.id(),

View file

@ -2,33 +2,34 @@ use std::collections::HashMap;
use futures::future::BoxFuture;
use yazi_config::YAZI;
use yazi_shared::{Id, Ids};
use super::{Task, TaskStage};
use crate::TaskKind;
#[derive(Default)]
pub struct Ongoing {
incr: usize,
pub(super) hooks: HashMap<usize, Box<dyn (FnOnce(bool) -> BoxFuture<'static, ()>) + Send + Sync>>,
pub(super) all: HashMap<usize, Task>,
pub(super) hooks: HashMap<Id, Box<dyn (FnOnce(bool) -> BoxFuture<'static, ()>) + Send + Sync>>,
pub(super) all: HashMap<Id, Task>,
}
impl Ongoing {
pub fn add(&mut self, kind: TaskKind, name: String) -> usize {
self.incr += 1;
self.all.insert(self.incr, Task::new(self.incr, kind, name));
self.incr
pub fn add(&mut self, kind: TaskKind, name: String) -> Id {
static IDS: Ids = Ids::new();
let id = IDS.next();
self.all.insert(id, Task::new(id, kind, name));
id
}
#[inline]
pub fn get(&self, id: usize) -> Option<&Task> { self.all.get(&id) }
pub fn get(&self, id: Id) -> Option<&Task> { self.all.get(&id) }
#[inline]
pub fn get_mut(&mut self, id: usize) -> Option<&mut Task> { self.all.get_mut(&id) }
pub fn get_mut(&mut self, id: Id) -> Option<&mut Task> { self.all.get_mut(&id) }
#[inline]
pub fn get_id(&self, idx: usize) -> Option<usize> { self.values().nth(idx).map(|t| t.id) }
pub fn get_id(&self, idx: usize) -> Option<Id> { self.values().nth(idx).map(|t| t.id) }
#[inline]
pub fn len(&self) -> usize {
@ -40,7 +41,7 @@ impl Ongoing {
}
#[inline]
pub fn exists(&self, id: usize) -> bool { self.all.contains_key(&id) }
pub fn exists(&self, id: Id) -> bool { self.all.contains_key(&id) }
#[inline]
pub fn values(&self) -> Box<dyn Iterator<Item = &Task> + '_> {
@ -54,7 +55,7 @@ impl Ongoing {
#[inline]
pub fn is_empty(&self) -> bool { self.len() == 0 }
pub fn try_remove(&mut self, id: usize, stage: TaskStage) -> Option<BoxFuture<'static, ()>> {
pub fn try_remove(&mut self, id: Id, stage: TaskStage) -> Option<BoxFuture<'static, ()>> {
if let Some(task) = self.get_mut(id) {
if stage > task.stage {
task.stage = stage;

View file

@ -1,4 +1,5 @@
use yazi_proxy::options::PluginOpt;
use yazi_shared::Id;
#[derive(Debug)]
pub enum PluginIn {
@ -6,7 +7,7 @@ pub enum PluginIn {
}
impl PluginIn {
pub fn id(&self) -> usize {
pub fn id(&self) -> Id {
match self {
Self::Entry(r#in) => r#in.id,
}
@ -15,6 +16,6 @@ impl PluginIn {
#[derive(Debug)]
pub struct PluginInEntry {
pub id: usize,
pub id: Id,
pub opt: PluginOpt,
}

View file

@ -1,6 +1,7 @@
use anyhow::{Result, anyhow};
use tokio::sync::mpsc;
use yazi_plugin::isolate;
use yazi_shared::Id;
use super::{PluginIn, PluginInEntry};
use crate::{HIGH, TaskOp, TaskProg};
@ -50,10 +51,10 @@ impl Plugin {
impl Plugin {
#[inline]
fn succ(&self, id: usize) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
fn succ(&self, id: Id) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
#[inline]
fn fail(&self, id: usize, reason: String) -> Result<()> {
fn fail(&self, id: Id, reason: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Fail(id, reason))?)
}

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use yazi_config::plugin::{Fetcher, Preloader};
use yazi_shared::{Throttle, url::Url};
use yazi_shared::{Id, Throttle, url::Url};
#[derive(Debug)]
pub enum PreworkIn {
@ -11,7 +11,7 @@ pub enum PreworkIn {
}
impl PreworkIn {
pub fn id(&self) -> usize {
pub fn id(&self) -> Id {
match self {
Self::Fetch(r#in) => r#in.id,
Self::Load(r#in) => r#in.id,
@ -22,21 +22,21 @@ impl PreworkIn {
#[derive(Debug)]
pub struct PreworkInFetch {
pub id: usize,
pub id: Id,
pub plugin: &'static Fetcher,
pub targets: Vec<yazi_fs::File>,
}
#[derive(Clone, Debug)]
pub struct PreworkInLoad {
pub id: usize,
pub id: Id,
pub plugin: &'static Preloader,
pub target: yazi_fs::File,
}
#[derive(Debug)]
pub struct PreworkInSize {
pub id: usize,
pub id: Id,
pub target: Url,
pub throttle: Arc<Throttle<(Url, u64)>>,
}

View file

@ -8,7 +8,7 @@ use tracing::error;
use yazi_config::Priority;
use yazi_fs::{FilesOp, SizeCalculator};
use yazi_plugin::isolate;
use yazi_shared::{event::CmdCow, url::Url};
use yazi_shared::{Id, event::CmdCow, url::Url};
use super::{PreworkIn, PreworkInFetch, PreworkInLoad, PreworkInSize};
use crate::{HIGH, NORMAL, TaskOp, TaskProg};
@ -130,10 +130,10 @@ impl Prework {
impl Prework {
#[inline]
fn succ(&self, id: usize) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
fn succ(&self, id: Id) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
#[inline]
fn fail(&self, id: usize, reason: String) -> Result<()> {
fn fail(&self, id: Id, reason: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Fail(id, reason))?)
}

View file

@ -1,14 +1,14 @@
use std::ffi::OsString;
use tokio::sync::mpsc;
use yazi_shared::url::Url;
use yazi_shared::{Id, url::Url};
use super::ShellOpt;
// --- Block
#[derive(Debug)]
pub struct ProcessInBlock {
pub id: usize,
pub id: Id,
pub cwd: Url,
pub cmd: OsString,
pub args: Vec<OsString>,
@ -23,7 +23,7 @@ impl From<ProcessInBlock> for ShellOpt {
// --- Orphan
#[derive(Debug)]
pub struct ProcessInOrphan {
pub id: usize,
pub id: Id,
pub cwd: Url,
pub cmd: OsString,
pub args: Vec<OsString>,
@ -38,7 +38,7 @@ impl From<ProcessInOrphan> for ShellOpt {
// --- Bg
#[derive(Debug)]
pub struct ProcessInBg {
pub id: usize,
pub id: Id,
pub cwd: Url,
pub cmd: OsString,
pub args: Vec<OsString>,

View file

@ -2,6 +2,7 @@ use anyhow::Result;
use scopeguard::defer;
use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::mpsc};
use yazi_proxy::{AppProxy, HIDER};
use yazi_shared::Id;
use super::{ProcessInBg, ProcessInBlock, ProcessInOrphan, ShellOpt};
use crate::TaskProg;
@ -97,15 +98,13 @@ impl Process {
impl Process {
#[inline]
fn succ(&self, id: usize) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
fn succ(&self, id: Id) -> Result<()> { Ok(self.prog.send(TaskProg::Succ(id))?) }
#[inline]
fn fail(&self, id: usize, reason: String) -> Result<()> {
fn fail(&self, id: Id, reason: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Fail(id, reason))?)
}
#[inline]
fn log(&self, id: usize, line: String) -> Result<()> {
Ok(self.prog.send(TaskProg::Log(id, line))?)
}
fn log(&self, id: Id, line: String) -> Result<()> { Ok(self.prog.send(TaskProg::Log(id, line))?) }
}

View file

@ -8,7 +8,7 @@ use yazi_config::{YAZI, plugin::{Fetcher, Preloader}};
use yazi_dds::Pump;
use yazi_fs::{must_be_dir, remove_dir_clean, unique_name};
use yazi_proxy::{MgrProxy, options::{PluginOpt, ProcessExecOpt}};
use yazi_shared::{Throttle, url::Url};
use yazi_shared::{Id, Throttle, url::Url};
use super::{Ongoing, TaskProg, TaskStage};
use crate::{HIGH, LOW, NORMAL, TaskKind, TaskOp, file::{File, FileInDelete, FileInHardlink, FileInLink, FileInPaste, FileInTrash}, plugin::{Plugin, PluginInEntry}, prework::{Prework, PreworkInFetch, PreworkInLoad, PreworkInSize}, process::{Process, ProcessInBg, ProcessInBlock, ProcessInOrphan}};
@ -55,7 +55,7 @@ impl Scheduler {
scheduler
}
pub fn cancel(&self, id: usize) -> bool {
pub fn cancel(&self, id: Id) -> bool {
let mut ongoing = self.ongoing.lock();
if let Some(hook) = ongoing.hooks.remove(&id) {
@ -413,7 +413,7 @@ impl Scheduler {
})
}
fn send_micro<F>(&self, id: usize, priority: u8, f: F)
fn send_micro<F>(&self, id: Id, priority: u8, f: F)
where
F: Future<Output = Result<()>> + Send + 'static,
{
@ -430,7 +430,7 @@ impl Scheduler {
);
}
fn new_and_fail(&self, id: usize, reason: &str) -> Result<()> {
fn new_and_fail(&self, id: Id, reason: &str) -> Result<()> {
self.prog.send(TaskProg::New(id, 0))?;
self.prog.send(TaskProg::Fail(id, reason.to_owned()))?;
Ok(())

View file

@ -1,8 +1,9 @@
use tokio::sync::mpsc;
use yazi_shared::Id;
#[derive(Debug, Default)]
pub struct Task {
pub id: usize,
pub id: Id,
pub kind: TaskKind,
pub name: String,
pub stage: TaskStage,
@ -19,7 +20,7 @@ pub struct Task {
}
impl Task {
pub fn new(id: usize, kind: TaskKind, name: String) -> Self {
pub fn new(id: Id, kind: TaskKind, name: String) -> Self {
Self { id, kind, name, ..Default::default() }
}
}
@ -61,15 +62,15 @@ impl From<&Task> for TaskSummary {
#[derive(Debug)]
pub enum TaskProg {
// id, size
New(usize, u64),
New(Id, u64),
// id, processed, size
Adv(usize, u32, u64),
Adv(Id, u32, u64),
// id
Succ(usize),
Succ(Id),
// id
Fail(usize, String),
Fail(Id, String),
// id, line
Log(usize, String),
Log(Id, String),
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]

View file

@ -16,7 +16,7 @@ yazi-macro = { path = "../yazi-macro", version = "25.6.11" }
anyhow = { workspace = true }
crossterm = { workspace = true }
futures = { workspace = true }
memchr = "2.7.4"
memchr = "2.7.5"
parking_lot = { workspace = true }
percent-encoding = "2.3.1"
ratatui = { workspace = true }
@ -29,7 +29,7 @@ libc = { workspace = true }
uzers = { workspace = true }
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = [ "Win32_UI_Shell" ] }
windows-sys = { version = "0.60.2", features = [ "Win32_UI_Shell" ] }
[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }

View file

@ -26,4 +26,4 @@ libc = { workspace = true }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = [ "Win32_Globalization", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Console", "Win32_System_Threading", "Win32_Security" ] }
windows-sys = { version = "0.60.2", features = [ "Win32_Globalization", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Console", "Win32_System_Threading", "Win32_Security" ] }