mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: wrong state pointed to and ignore plugin/flavor directory creation errors
This commit is contained in:
parent
bfcf401b40
commit
7a99ea4409
4 changed files with 20 additions and 23 deletions
|
|
@ -157,8 +157,8 @@ impl Default for Boot {
|
||||||
state_dir: Xdg::state_dir(),
|
state_dir: Xdg::state_dir(),
|
||||||
};
|
};
|
||||||
|
|
||||||
std::fs::create_dir_all(&boot.flavor_dir).expect("Failed to create flavor directory");
|
std::fs::create_dir_all(&boot.flavor_dir).ok();
|
||||||
std::fs::create_dir_all(&boot.plugin_dir).expect("Failed to create plugin directory");
|
std::fs::create_dir_all(&boot.plugin_dir).ok();
|
||||||
boot
|
boot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{fs, path::PathBuf, time::{self, SystemTime}};
|
use std::{path::PathBuf, time::{self, SystemTime}};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
@ -53,7 +53,7 @@ impl Default for Preview {
|
||||||
preview.cache_dir.filter(|p| !p.is_empty()).map_or_else(Xdg::cache_dir, expand_path);
|
preview.cache_dir.filter(|p| !p.is_empty()).map_or_else(Xdg::cache_dir, expand_path);
|
||||||
|
|
||||||
if !cache_dir.is_dir() {
|
if !cache_dir.is_dir() {
|
||||||
fs::create_dir(&cache_dir).unwrap();
|
std::fs::create_dir(&cache_dir).expect("Failed to create cache directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
Preview {
|
Preview {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use parking_lot::RwLock;
|
||||||
use yazi_boot::BOOT;
|
use yazi_boot::BOOT;
|
||||||
use yazi_shared::{fs::Url, RoCell};
|
use yazi_shared::{fs::Url, RoCell};
|
||||||
|
|
||||||
use crate::{body::{Body, BodyCd, BodyHi, BodyHover, BodyRename, BodyTabs, BodyYank}, Client, Payload, ID, PEERS};
|
use crate::{body::{Body, BodyCd, BodyHi, BodyHover, BodyRename, BodyTabs, BodyYank}, Client, ID, PEERS};
|
||||||
|
|
||||||
pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> =
|
pub static LOCAL: RoCell<RwLock<HashMap<String, HashMap<String, Function<'static>>>>> =
|
||||||
RoCell::new();
|
RoCell::new();
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ impl Require {
|
||||||
"require",
|
"require",
|
||||||
lua.create_function(move |lua, name: mlua::String| {
|
lua.create_function(move |lua, name: mlua::String| {
|
||||||
lua.named_registry_value::<RtRef>("rt")?.swap(name.to_str()?);
|
lua.named_registry_value::<RtRef>("rt")?.swap(name.to_str()?);
|
||||||
let module: Table = require.call(&name)?;
|
let mod_: Table = require.call(&name)?;
|
||||||
lua.named_registry_value::<RtRef>("rt")?.reset();
|
lua.named_registry_value::<RtRef>("rt")?.reset();
|
||||||
|
|
||||||
module.raw_set("_name", &name)?;
|
mod_.raw_set("_name", &name)?;
|
||||||
Self::create_mt(lua, name, module)
|
Self::create_mt(lua, name, mod_)
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
@ -27,38 +27,35 @@ impl Require {
|
||||||
fn create_mt(
|
fn create_mt(
|
||||||
lua: &'static Lua,
|
lua: &'static Lua,
|
||||||
name: mlua::String<'static>,
|
name: mlua::String<'static>,
|
||||||
module: Table<'static>,
|
mod_: Table<'static>,
|
||||||
) -> mlua::Result<Table<'static>> {
|
) -> mlua::Result<Table<'static>> {
|
||||||
let ts =
|
let ts =
|
||||||
lua.create_table_from([("name", name.into_lua(lua)?), ("module", module.into_lua(lua)?)])?;
|
lua.create_table_from([("name", name.into_lua(lua)?), ("mod", mod_.into_lua(lua)?)])?;
|
||||||
|
|
||||||
let mt = lua.create_table()?;
|
let mt = lua.create_table_from([(
|
||||||
mt.raw_set(
|
|
||||||
"__index",
|
"__index",
|
||||||
lua.create_function(|_, (ts, key): (Table, mlua::String)| {
|
lua.create_function(|_, (_, key): (Table, mlua::String)| {
|
||||||
if key.to_str()? == "setup" {
|
if key.to_str()? == "setup" {
|
||||||
Ok(RequireSetup { name: ts.raw_get("name")?, module: ts.raw_get("module")? })
|
Ok(RequireSetup)
|
||||||
} else {
|
} else {
|
||||||
Err("Only `require():setup()` and `require().setup()` are supported").into_lua_err()
|
Err("Only `require():setup()` is supported").into_lua_err()
|
||||||
}
|
}
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)])?;
|
||||||
|
|
||||||
ts.set_metatable(Some(mt));
|
ts.set_metatable(Some(mt));
|
||||||
Ok(ts)
|
Ok(ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct RequireSetup {
|
pub(super) struct RequireSetup;
|
||||||
name: mlua::String<'static>,
|
|
||||||
module: Table<'static>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserData for RequireSetup {
|
impl UserData for RequireSetup {
|
||||||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
methods.add_meta_method(MetaMethod::Call, |lua, me, args: Variadic<Value>| {
|
methods.add_meta_method(MetaMethod::Call, |lua, _, (ts, args): (Table, Variadic<Value>)| {
|
||||||
lua.named_registry_value::<RtRef>("rt")?.swap(me.name.to_str()?);
|
let (name, mod_): (mlua::String, Table) = (ts.raw_get("name")?, ts.raw_get("mod")?);
|
||||||
let result = me.module.call_function::<_, Variadic<Value>>("setup", args);
|
lua.named_registry_value::<RtRef>("rt")?.swap(name.to_str()?);
|
||||||
|
let result = mod_.call_method::<_, Variadic<Value>>("setup", args);
|
||||||
lua.named_registry_value::<RtRef>("rt")?.reset();
|
lua.named_registry_value::<RtRef>("rt")?.reset();
|
||||||
result
|
result
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue