From 5962c678a0e85a698d62d227f974b9d43aecc833 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 29 Dec 2023 01:27:16 +0800 Subject: [PATCH] .. [no ci] --- yazi-scheduler/src/lib.rs | 3 +- .../src/{workers => preload}/mod.rs | 4 +-- yazi-scheduler/src/preload/op.rs | 25 +++++++++++++++ .../src/{workers => preload}/preload.rs | 23 +------------- yazi-scheduler/src/process/mod.rs | 5 +++ yazi-scheduler/src/process/op.rs | 30 ++++++++++++++++++ .../src/{workers => process}/process.rs | 31 ++----------------- yazi-scheduler/src/scheduler.rs | 2 +- yazi-scheduler/src/task.rs | 4 +-- 9 files changed, 70 insertions(+), 57 deletions(-) rename yazi-scheduler/src/{workers => preload}/mod.rs (50%) create mode 100644 yazi-scheduler/src/preload/op.rs rename yazi-scheduler/src/{workers => preload}/preload.rs (83%) create mode 100644 yazi-scheduler/src/process/mod.rs create mode 100644 yazi-scheduler/src/process/op.rs rename yazi-scheduler/src/{workers => process}/process.rs (79%) diff --git a/yazi-scheduler/src/lib.rs b/yazi-scheduler/src/lib.rs index e401021d..fdc642ef 100644 --- a/yazi-scheduler/src/lib.rs +++ b/yazi-scheduler/src/lib.rs @@ -3,10 +3,11 @@ mod blocker; mod file; mod plugin; +mod preload; +mod process; mod running; mod scheduler; mod task; -pub mod workers; pub use blocker::*; pub use running::*; diff --git a/yazi-scheduler/src/workers/mod.rs b/yazi-scheduler/src/preload/mod.rs similarity index 50% rename from yazi-scheduler/src/workers/mod.rs rename to yazi-scheduler/src/preload/mod.rs index b7c9297e..d4399138 100644 --- a/yazi-scheduler/src/workers/mod.rs +++ b/yazi-scheduler/src/preload/mod.rs @@ -1,5 +1,5 @@ +mod op; mod preload; -mod process; +pub use op::*; pub use preload::*; -pub use process::*; diff --git a/yazi-scheduler/src/preload/op.rs b/yazi-scheduler/src/preload/op.rs new file mode 100644 index 00000000..4ef7492a --- /dev/null +++ b/yazi-scheduler/src/preload/op.rs @@ -0,0 +1,25 @@ +use std::sync::Arc; + +use yazi_shared::{fs::Url, Throttle}; + +#[derive(Debug)] +pub enum PreloadOp { + Rule(PreloadOpRule), + Size(PreloadOpSize), +} + +#[derive(Clone, Debug)] +pub struct PreloadOpRule { + pub id: usize, + pub rule_id: u8, + pub rule_multi: bool, + pub plugin: String, + pub targets: Vec, +} + +#[derive(Debug)] +pub struct PreloadOpSize { + pub id: usize, + pub target: Url, + pub throttle: Arc>, +} diff --git a/yazi-scheduler/src/workers/preload.rs b/yazi-scheduler/src/preload/preload.rs similarity index 83% rename from yazi-scheduler/src/workers/preload.rs rename to yazi-scheduler/src/preload/preload.rs index db801e9e..f19723b5 100644 --- a/yazi-scheduler/src/workers/preload.rs +++ b/yazi-scheduler/src/preload/preload.rs @@ -6,6 +6,7 @@ use tokio::sync::mpsc; use tracing::error; use yazi_shared::{fs::{calculate_size, FilesOp, Url}, Throttle}; +use super::{PreloadOpRule, PreloadOpSize}; use crate::TaskProg; pub struct Preload { @@ -15,28 +16,6 @@ pub struct Preload { pub size_loading: RwLock>, } -#[derive(Debug)] -pub enum PreloadOp { - Rule(PreloadOpRule), - Size(PreloadOpSize), -} - -#[derive(Clone, Debug)] -pub struct PreloadOpRule { - pub id: usize, - pub rule_id: u8, - pub rule_multi: bool, - pub plugin: String, - pub targets: Vec, -} - -#[derive(Debug)] -pub struct PreloadOpSize { - pub id: usize, - pub target: Url, - pub throttle: Arc>, -} - impl Preload { pub fn new(prog: mpsc::UnboundedSender) -> Self { Self { prog, rule_loaded: Default::default(), size_loading: Default::default() } diff --git a/yazi-scheduler/src/process/mod.rs b/yazi-scheduler/src/process/mod.rs new file mode 100644 index 00000000..e563de5d --- /dev/null +++ b/yazi-scheduler/src/process/mod.rs @@ -0,0 +1,5 @@ +mod op; +mod process; + +pub use op::*; +pub use process::*; diff --git a/yazi-scheduler/src/process/op.rs b/yazi-scheduler/src/process/op.rs new file mode 100644 index 00000000..ee0ea090 --- /dev/null +++ b/yazi-scheduler/src/process/op.rs @@ -0,0 +1,30 @@ +use std::{ffi::OsString, mem}; + +use tokio::sync::oneshot; +use yazi_plugin::external::ShellOpt; + +#[derive(Debug)] +pub enum ProcessOp { + Open(ProcessOpOpen), +} + +#[derive(Debug)] +pub struct ProcessOpOpen { + pub id: usize, + pub cmd: OsString, + pub args: Vec, + pub block: bool, + pub orphan: bool, + pub cancel: oneshot::Sender<()>, +} + +impl From<&mut ProcessOpOpen> for ShellOpt { + fn from(value: &mut ProcessOpOpen) -> Self { + Self { + cmd: mem::take(&mut value.cmd), + args: mem::take(&mut value.args), + piped: false, + orphan: value.orphan, + } + } +} diff --git a/yazi-scheduler/src/workers/process.rs b/yazi-scheduler/src/process/process.rs similarity index 79% rename from yazi-scheduler/src/workers/process.rs rename to yazi-scheduler/src/process/process.rs index 8665dcf3..2431db80 100644 --- a/yazi-scheduler/src/workers/process.rs +++ b/yazi-scheduler/src/process/process.rs @@ -1,41 +1,14 @@ -use std::{ffi::OsString, mem}; - use anyhow::Result; -use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::{mpsc, oneshot}}; +use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::mpsc}; use yazi_plugin::external::{self, ShellOpt}; +use super::ProcessOpOpen; use crate::{Scheduler, TaskProg, BLOCKER}; pub struct Process { prog: mpsc::UnboundedSender, } -#[derive(Debug)] -pub enum ProcessOp { - Open(ProcessOpOpen), -} - -#[derive(Debug)] -pub struct ProcessOpOpen { - pub id: usize, - pub cmd: OsString, - pub args: Vec, - pub block: bool, - pub orphan: bool, - pub cancel: oneshot::Sender<()>, -} - -impl From<&mut ProcessOpOpen> for ShellOpt { - fn from(value: &mut ProcessOpOpen) -> Self { - Self { - cmd: mem::take(&mut value.cmd), - args: mem::take(&mut value.args), - piped: false, - orphan: value.orphan, - } - } -} - impl Process { pub fn new(prog: mpsc::UnboundedSender) -> Self { Self { prog } } diff --git a/yazi-scheduler/src/scheduler.rs b/yazi-scheduler/src/scheduler.rs index b5c434d8..8f21c688 100644 --- a/yazi-scheduler/src/scheduler.rs +++ b/yazi-scheduler/src/scheduler.rs @@ -7,7 +7,7 @@ use yazi_config::{open::Opener, plugin::PluginRule, TASKS}; use yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle}; use super::{Running, TaskProg, TaskStage}; -use crate::{file::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash}, plugin::{Plugin, PluginOpEntry}, workers::{Preload, PreloadOpRule, PreloadOpSize, Process, ProcessOpOpen}, TaskKind, TaskOp}; +use crate::{file::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash}, plugin::{Plugin, PluginOpEntry}, preload::{Preload, PreloadOpRule, PreloadOpSize}, process::{Process, ProcessOpOpen}, TaskKind, TaskOp}; pub struct Scheduler { pub file: Arc, diff --git a/yazi-scheduler/src/task.rs b/yazi-scheduler/src/task.rs index edfc8709..8138c699 100644 --- a/yazi-scheduler/src/task.rs +++ b/yazi-scheduler/src/task.rs @@ -62,8 +62,8 @@ impl From<&Task> for TaskSummary { pub enum TaskOp { File(Box), Plugin(Box), - Preload(Box), - Process(Box), + Preload(Box), + Process(Box), } impl TaskOp {