.. [no ci]

This commit is contained in:
sxyazi 2023-12-29 01:27:16 +08:00
parent 53e6e1bc0a
commit 5962c678a0
No known key found for this signature in database
9 changed files with 70 additions and 57 deletions

View file

@ -3,10 +3,11 @@
mod blocker; mod blocker;
mod file; mod file;
mod plugin; mod plugin;
mod preload;
mod process;
mod running; mod running;
mod scheduler; mod scheduler;
mod task; mod task;
pub mod workers;
pub use blocker::*; pub use blocker::*;
pub use running::*; pub use running::*;

View file

@ -1,5 +1,5 @@
mod op;
mod preload; mod preload;
mod process;
pub use op::*;
pub use preload::*; pub use preload::*;
pub use process::*;

View file

@ -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<yazi_shared::fs::File>,
}
#[derive(Debug)]
pub struct PreloadOpSize {
pub id: usize,
pub target: Url,
pub throttle: Arc<Throttle<(Url, u64)>>,
}

View file

@ -6,6 +6,7 @@ use tokio::sync::mpsc;
use tracing::error; use tracing::error;
use yazi_shared::{fs::{calculate_size, FilesOp, Url}, Throttle}; use yazi_shared::{fs::{calculate_size, FilesOp, Url}, Throttle};
use super::{PreloadOpRule, PreloadOpSize};
use crate::TaskProg; use crate::TaskProg;
pub struct Preload { pub struct Preload {
@ -15,28 +16,6 @@ pub struct Preload {
pub size_loading: RwLock<BTreeSet<Url>>, pub size_loading: RwLock<BTreeSet<Url>>,
} }
#[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<yazi_shared::fs::File>,
}
#[derive(Debug)]
pub struct PreloadOpSize {
pub id: usize,
pub target: Url,
pub throttle: Arc<Throttle<(Url, u64)>>,
}
impl Preload { impl Preload {
pub fn new(prog: mpsc::UnboundedSender<TaskProg>) -> Self { pub fn new(prog: mpsc::UnboundedSender<TaskProg>) -> Self {
Self { prog, rule_loaded: Default::default(), size_loading: Default::default() } Self { prog, rule_loaded: Default::default(), size_loading: Default::default() }

View file

@ -0,0 +1,5 @@
mod op;
mod process;
pub use op::*;
pub use process::*;

View file

@ -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<OsString>,
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,
}
}
}

View file

@ -1,41 +1,14 @@
use std::{ffi::OsString, mem};
use anyhow::Result; 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 yazi_plugin::external::{self, ShellOpt};
use super::ProcessOpOpen;
use crate::{Scheduler, TaskProg, BLOCKER}; use crate::{Scheduler, TaskProg, BLOCKER};
pub struct Process { pub struct Process {
prog: mpsc::UnboundedSender<TaskProg>, prog: mpsc::UnboundedSender<TaskProg>,
} }
#[derive(Debug)]
pub enum ProcessOp {
Open(ProcessOpOpen),
}
#[derive(Debug)]
pub struct ProcessOpOpen {
pub id: usize,
pub cmd: OsString,
pub args: Vec<OsString>,
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 { impl Process {
pub fn new(prog: mpsc::UnboundedSender<TaskProg>) -> Self { Self { prog } } pub fn new(prog: mpsc::UnboundedSender<TaskProg>) -> Self { Self { prog } }

View file

@ -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 yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle};
use super::{Running, TaskProg, TaskStage}; 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 struct Scheduler {
pub file: Arc<File>, pub file: Arc<File>,

View file

@ -62,8 +62,8 @@ impl From<&Task> for TaskSummary {
pub enum TaskOp { pub enum TaskOp {
File(Box<crate::file::FileOp>), File(Box<crate::file::FileOp>),
Plugin(Box<crate::plugin::PluginOp>), Plugin(Box<crate::plugin::PluginOp>),
Preload(Box<crate::workers::PreloadOp>), Preload(Box<crate::preload::PreloadOp>),
Process(Box<crate::workers::ProcessOp>), Process(Box<crate::process::ProcessOp>),
} }
impl TaskOp { impl TaskOp {