chore: Assets interpolate folder path via rust embed (#1318)
Use `rust-embed` feature `interpolate-folder-path` to always (`debug`/`release`) load assets from the correct `assets` directory
This commit is contained in:
parent
4ee64cc661
commit
908c022efe
3 changed files with 19 additions and 26 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -5864,6 +5864,7 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rust-embed-utils",
|
"rust-embed-utils",
|
||||||
|
"shellexpand",
|
||||||
"syn 2.0.105",
|
"syn 2.0.105",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
@ -6485,6 +6486,15 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shellexpand"
|
||||||
|
version = "3.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
|
||||||
|
dependencies = [
|
||||||
|
"dirs 4.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ raw-window-handle = { version = "0.6", features = ["std"] }
|
||||||
regex = "1"
|
regex = "1"
|
||||||
reqwest_client.workspace = true
|
reqwest_client.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
rust-embed = "8.5.0"
|
rust-embed = { version = "8.7.2", features = ["interpolate-folder-path"] }
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
unindent = "0.2.3"
|
unindent = "0.2.3"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
use std::{borrow::Cow, path::PathBuf};
|
use anyhow::anyhow;
|
||||||
|
use gpui::{AssetSource, Result, SharedString};
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
|
|
||||||
use gpui::AssetSource;
|
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "../../assets"]
|
#[folder = "$CARGO_MANIFEST_DIR/../../assets"]
|
||||||
#[include = "icons/**/*"]
|
#[include = "icons/**/*.svg"]
|
||||||
#[exclude = "*.DS_Store"]
|
|
||||||
pub struct Assets;
|
pub struct Assets;
|
||||||
|
|
||||||
impl AssetSource for Assets {
|
impl AssetSource for Assets {
|
||||||
|
|
@ -19,26 +16,12 @@ impl AssetSource for Assets {
|
||||||
|
|
||||||
Self::get(path)
|
Self::get(path)
|
||||||
.map(|f| Some(f.data))
|
.map(|f| Some(f.data))
|
||||||
.or_else(|| {
|
.ok_or_else(|| anyhow!("could not find asset at path \"{path}\""))
|
||||||
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
||||||
let path = manifest_dir.join(path);
|
|
||||||
|
|
||||||
std::fs::read(path)
|
|
||||||
.map(|data| Some(std::borrow::Cow::Owned(data)))
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(&self, path: &str) -> gpui::Result<Vec<gpui::SharedString>> {
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
Ok(Self::iter()
|
Ok(Self::iter()
|
||||||
.filter_map(|p| {
|
.filter_map(|p| p.starts_with(path).then(|| p.into()))
|
||||||
if p.starts_with(path) {
|
|
||||||
Some(p.into())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue