This commit is contained in:
2026-10-21 19:51:01 +07:00
parent d7160e196e
commit 6117c8184c
149 changed files with 591 additions and 18 deletions
+7 -8
View File
@@ -1,7 +1,8 @@
use anyhow::Context;
use gpui::{AssetSource, Result, SharedString};
use rust_embed::RustEmbed;
/// The Lucide icons the app and the kit components draw, vendored so they ship
/// with the binary and resolve like any other coop asset.
#[derive(RustEmbed)]
#[folder = "../../assets"]
#[include = "fonts/**/*"]
@@ -10,20 +11,20 @@ use rust_embed::RustEmbed;
#[exclude = "*.DS_Store"]
pub struct Assets;
/// Coop's bundled assets, with the GPUI Kit component icon bundle (Lucide) as
/// the fallback so `IconName` SVGs resolve alongside coop's own files.
/// Coop's bundled assets, with the GPUI Kit component icon bundle as the
/// fallback for any icon not vendored here.
pub struct CombinedAssets;
impl AssetSource for CombinedAssets {
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
if let Some(data) = Assets.load(path)? {
if let Ok(Some(data)) = Assets.load(path) {
return Ok(Some(data));
}
gpui_kit::assets::Assets.load(path)
}
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
let mut paths = Assets.list(path)?;
let mut paths = Assets.list(path).unwrap_or_default();
paths.extend(gpui_kit::assets::Assets.list(path)?);
Ok(paths)
}
@@ -31,9 +32,7 @@ impl AssetSource for CombinedAssets {
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
Self::get(path)
.map(|f| Some(f.data))
.with_context(|| format!("loading asset at path {path:?}"))
Ok(Self::get(path).map(|f| f.data))
}
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
+39
View File
@@ -0,0 +1,39 @@
use gpui::AssetSource;
#[test]
fn icons_resolve_from_the_vendored_folder() {
// Icons coop's code and the kit components draw, served by the vendored
// folder (signed's set, filled with the kit bundle where coop needs more).
let vendored = [
"icons/search.svg",
"icons/close.svg",
"icons/panel-left.svg",
"icons/window-minimize.svg",
"icons/settings-2.svg",
"icons/x.svg",
"icons/compass.svg",
"icons/radio-tower.svg",
];
for path in vendored {
let own = assets::Assets
.load(path)
.unwrap_or_else(|e| panic!("{path} errored in own embed: {e}"));
assert!(own.is_some(), "own embed is missing {path}");
let combined = assets::CombinedAssets.load(path).unwrap();
assert!(combined.is_some(), "CombinedAssets fails to serve {path}");
}
// Coop's own files still load through the combined source.
let own = [
"brand/coop.svg",
"brand/bg1.jpg",
"fonts/Inter/Inter-Medium.ttf",
];
for path in own {
assert!(
matches!(assets::CombinedAssets.load(path), Ok(Some(_))),
"CombinedAssets fails to serve coop asset {path}"
);
}
}
+3 -8
View File
@@ -1152,15 +1152,10 @@ impl ChatPanel {
.show_author(show_author)
.hide_avatar(hide_avatar)
.avatar(
Button::new("message-avatar")
.ghost()
.relative()
Avatar::new(author.avatar())
.seed(author.avatar_seed())
.flex_shrink_0()
.child(
Avatar::new(author.avatar())
.seed(author.avatar_seed())
.into_any_element(),
)
.relative()
.dropdown_menu(move |this, _window, _cx| {
this.menu("Public Key", Box::new(Command::Copy(pk)))
.menu("View Relays", Box::new(Command::Relays(pk)))
+5 -2
View File
@@ -4,6 +4,7 @@ use gpui::{
SharedString, StyleRefinement, Styled, StyledImage, Window, canvas, div, img, point, px,
};
use gpui_kit::base::StyledExt as _;
use gpui_kit::component::menu::DropdownMenu;
use gpui_kit::component::{ActiveTheme as _, Selectable, Sizable, Size};
/// Number of rows and columns in the generated pixel grid.
@@ -41,7 +42,7 @@ struct PixelAvatar {
}
impl PixelAvatar {
/// Creates a pixel avatar from `seed.
/// Creates a pixel avatar from the given seed.
fn new(seed: impl AsRef<str>) -> Self {
Self {
seed: fnv1a(seed.as_ref().as_bytes()),
@@ -124,7 +125,7 @@ impl RenderOnce for PixelAvatar {
}
}
/// Builds the mirrored fill pattern for `seed.
/// Builds the mirrored fill pattern for the given seed.
fn pixel_pattern(seed: u64) -> [u8; PIXEL_GRID * PIXEL_GRID] {
let mut rng = PixelRng::new(seed);
let mut pattern = [0u8; PIXEL_GRID * PIXEL_GRID];
@@ -417,6 +418,8 @@ impl InteractiveElement for Avatar {
}
}
impl DropdownMenu for Avatar {}
impl RenderOnce for Avatar {
fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement {
let image_size = avatar_size(self.size).to_pixels(window.rem_size());