mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
perf: do not listen for file changes in inactive tabs (#2958)
This commit is contained in:
parent
52ecb31f5a
commit
917e1f54a1
15 changed files with 35 additions and 102 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::HashSet;
|
use std::iter;
|
||||||
|
|
||||||
use yazi_parser::mgr::WatchOpt;
|
use yazi_parser::mgr::WatchOpt;
|
||||||
|
|
||||||
|
|
@ -7,16 +7,10 @@ use crate::mgr::Mgr;
|
||||||
impl Mgr {
|
impl Mgr {
|
||||||
#[yazi_codegen::command]
|
#[yazi_codegen::command]
|
||||||
pub fn watch(&mut self, _: WatchOpt) {
|
pub fn watch(&mut self, _: WatchOpt) {
|
||||||
let mut to_watch = HashSet::with_capacity(3 * self.tabs.len());
|
let it = iter::once(self.tabs.active().cwd())
|
||||||
for tab in self.tabs.iter() {
|
.chain(self.tabs.parent().map(|p| &p.url))
|
||||||
to_watch.insert(tab.cwd());
|
.chain(self.tabs.hovered().filter(|h| h.is_dir()).map(|h| &h.url));
|
||||||
if let Some(ref p) = tab.parent {
|
|
||||||
to_watch.insert(&p.url);
|
self.watcher.watch(it);
|
||||||
}
|
|
||||||
if let Some(h) = tab.hovered().filter(|&h| h.is_dir()) {
|
|
||||||
to_watch.insert(&h.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.watcher.watch(to_watch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ impl Tabs {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn active_mut(&mut self) -> &mut Tab { &mut self.items[self.cursor] }
|
pub(super) fn active_mut(&mut self) -> &mut Tab { &mut self.items[self.cursor] }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn parent(&self) -> Option<&Folder> { self.active().parent.as_ref() }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn current(&self) -> &Folder { &self.active().current }
|
pub fn current(&self) -> &Folder { &self.active().current }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,8 @@ impl Watcher {
|
||||||
Self { in_tx, out_tx }
|
Self { in_tx, out_tx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn watch(&mut self, mut new: HashSet<&Url>) {
|
pub(super) fn watch<'a>(&mut self, it: impl Iterator<Item = &'a Url>) {
|
||||||
new.retain(|&u| u.is_regular());
|
self.in_tx.send(it.filter(|u| u.is_regular()).cloned().collect()).ok();
|
||||||
self.in_tx.send(new.into_iter().cloned().collect()).ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn push_files(&self, urls: Vec<Url>) {
|
pub(super) fn push_files(&self, urls: Vec<Url>) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type EscapeOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct EscapeOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for EscapeOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for EscapeOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
yazi_macro::mod_pub!(cmp confirm help input mgr notify pick spot tab tasks which);
|
yazi_macro::mod_pub!(cmp confirm help input mgr notify pick spot tab tasks which);
|
||||||
|
|
||||||
|
yazi_macro::mod_flat!(void);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type UnyankOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct UnyankOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for UnyankOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for UnyankOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type WatchOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct WatchOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for WatchOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for WatchOpt {
|
|
||||||
fn from((): ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type CloseOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct CloseOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for CloseOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for CloseOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type FollowOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct FollowOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for FollowOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type LeaveOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct LeaveOpt;
|
|
||||||
|
|
||||||
impl From<()> for LeaveOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CmdCow> for LeaveOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type CloseOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct CloseOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for CloseOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for CloseOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1 @@
|
||||||
use yazi_shared::event::CmdCow;
|
pub type ShowOpt = crate::VoidOpt;
|
||||||
|
|
||||||
pub struct ShowOpt;
|
|
||||||
|
|
||||||
impl From<CmdCow> for ShowOpt {
|
|
||||||
fn from(_: CmdCow) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for ShowOpt {
|
|
||||||
fn from(_: ()) -> Self { Self }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
11
yazi-parser/src/void.rs
Normal file
11
yazi-parser/src/void.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
use yazi_shared::event::CmdCow;
|
||||||
|
|
||||||
|
pub struct VoidOpt;
|
||||||
|
|
||||||
|
impl From<CmdCow> for VoidOpt {
|
||||||
|
fn from(_: CmdCow) -> Self { Self }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<()> for VoidOpt {
|
||||||
|
fn from(_: ()) -> Self { Self }
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ function M:peek(job)
|
||||||
return require("empty").msg(
|
return require("empty").msg(
|
||||||
job,
|
job,
|
||||||
code == 2 and "File list in this archive is encrypted"
|
code == 2 and "File list in this archive is encrypted"
|
||||||
or "Failed to start both `7zz` and `7z`. Do you have 7-zip installed?"
|
or "Failed to start either `7zz` or `7z`. Do you have 7-zip installed?"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ function M.spawn_7z(args)
|
||||||
|
|
||||||
local child = try("7zz") or try("7z")
|
local child = try("7zz") or try("7z")
|
||||||
if not child then
|
if not child then
|
||||||
return ya.err("Failed to start both `7zz` and `7z`, error: " .. last_err)
|
return ya.err("Failed to start either `7zz` or `7z`, error: " .. last_err)
|
||||||
end
|
end
|
||||||
return child, last_err
|
return child, last_err
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ function M:try_with(from, pwd, to)
|
||||||
local archive = require("archive")
|
local archive = require("archive")
|
||||||
local child, err = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) }
|
local child, err = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) }
|
||||||
if not child then
|
if not child then
|
||||||
fail("Failed to start both `7zz` and `7z`, error: " .. err)
|
fail("Failed to start either `7zz` or `7z`, error: " .. err)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output, err = child:wait_with_output()
|
local output, err = child:wait_with_output()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue