mirror of https://github.com/wayvr-org/wayvr.git
parent
a17334bc80
commit
382735956a
|
|
@ -7035,8 +7035,10 @@ dependencies = [
|
||||||
"glam",
|
"glam",
|
||||||
"idmap",
|
"idmap",
|
||||||
"idmap-derive",
|
"idmap-derive",
|
||||||
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"wayvr-ipc",
|
"wayvr-ipc",
|
||||||
|
"xdg 3.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,5 @@ idmap = { workspace = true, features = ["serde"] }
|
||||||
idmap-derive = { workspace = true }
|
idmap-derive = { workspace = true }
|
||||||
wayvr-ipc = { path = "../wayvr-ipc", default-features = false }
|
wayvr-ipc = { path = "../wayvr-ipc", default-features = false }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
xdg = "3.0"
|
||||||
|
log = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
use std::{path::PathBuf, sync::LazyLock};
|
||||||
|
|
||||||
|
const FALLBACK_CACHE_PATH: &str = "/tmp/wayvr_cache";
|
||||||
|
|
||||||
|
static CACHE_ROOT_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||||
|
if let Some(mut dir) = xdg::BaseDirectories::new().get_cache_home() {
|
||||||
|
dir.push("wayvr");
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return fallback cache path
|
||||||
|
log::error!("Err: Failed to find cache path, using {FALLBACK_CACHE_PATH}");
|
||||||
|
PathBuf::from(FALLBACK_CACHE_PATH)
|
||||||
|
});
|
||||||
|
|
||||||
|
fn get_cache_root() -> PathBuf {
|
||||||
|
CACHE_ROOT_PATH.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensure_dir(cache_root_path: &PathBuf) {
|
||||||
|
let _ = std::fs::create_dir(cache_root_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_data(data_path: &str) -> Option<Vec<u8>> {
|
||||||
|
let mut path = get_cache_root();
|
||||||
|
ensure_dir(&path);
|
||||||
|
path.push(data_path);
|
||||||
|
std::fs::read(path).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_data(data_path: &str, data: &[u8]) -> std::io::Result<()> {
|
||||||
|
let mut path = get_cache_root();
|
||||||
|
path.push(data_path);
|
||||||
|
std::fs::write(path, data)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod astr_containers;
|
pub mod astr_containers;
|
||||||
|
pub mod cache_dir;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod dash_interface;
|
pub mod dash_interface;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue