Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions native/src/addons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,17 @@ pub fn what(k: &Tokens, name: &str, lines: Vec<V>) -> V {
what_of(all)
}

/// `.what` with a leading brand mark to the left of the bold name and its lines (matching `ours`).
pub fn what_with_icon(k: &Tokens, icon: V, name: &str, lines: Vec<V>) -> V {
row()
.w(0.0)
.grow(1.0)
.gap(SPACE_3)
.align(Align::Start)
.child(icon)
.child(what(k, name, lines))
}

/// `.what` of lines that are all given.
pub fn what_of(lines: Vec<V>) -> V {
col().w(0.0).grow(1.0).children(lines)
Expand Down
26 changes: 17 additions & 9 deletions native/src/bot_settings_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::bot_settings_rows::{
Ctx, Hint, Place, code_span, key, row_of, run, sheet, sheet_danger, sheet_heading, sheet_list,
sheet_title,
};
use crate::brand_icons::{BrandNamespace, brand_glyph};
use crate::controls::{self, words};
use crate::forms::{self, Kind};
use crate::state::Bot;
Expand Down Expand Up @@ -258,10 +259,12 @@ fn adapter_rows(cx: Ctx<'_>, label: &str, adapter: &Adapter) -> Vec<V> {
)
.on_press(move |app: &mut App| ask(app, &name, &label, mode))
};
let mark = || brand_glyph(BrandNamespace::Agent, &adapter.name, ICON, k.fg_muted);
let mut out = Vec::new();
match &adapter.version {
None => out.push(
row_of(cx, &format!("{label} adapter"))
.icon(mark())
.hint("Bate can fetch the program that connects it, into its own folder.")
.error(preview_failure.clone())
.control(button("install", "Install…", Mode::Install)),
Expand All @@ -280,6 +283,7 @@ fn adapter_rows(cx: Ctx<'_>, label: &str, adapter: &Adapter) -> Vec<V> {
}
out.push(
row_of(cx, &format!("{label} adapter, installed by Bate"))
.icon(mark())
.hint(Hint::Rich(hint))
.error(preview_failure.clone())
.control(
Expand Down Expand Up @@ -460,7 +464,11 @@ pub fn engine(cx: Ctx<'_>) -> Option<V> {
);
});
let hint = chosen.map(|a| Hint::Rich(vec![code_span(k, &a.path)]));
let mut row = row_of(cx, "Engine").saved_if("agent", choice != OTHER);
let chosen_mark =
chosen.and_then(|a| brand_glyph(BrandNamespace::Agent, &a.label, ICON, k.fg_muted));
let mut row = row_of(cx, "Engine")
.icon(chosen_mark)
.saved_if("agent", choice != OTHER);
if choice != OTHER {
row = row.failing("agent");
}
Expand Down Expand Up @@ -505,15 +513,15 @@ pub fn engine(cx: Ctx<'_>) -> Option<V> {
}
for (n, missing) in found.missing.iter().enumerate() {
let title = format!("{} (not installed)", missing.label);
let mark = brand_glyph(BrandNamespace::Agent, &missing.label, ICON, k.fg_muted);
match &missing.install {
Some(install) => {
rows.push(row_of(cx, &title).place(Place::Under).control(forms::code(
k,
&cx.key(&format!("install-{n}")),
install,
)))
}
None => rows.push(row_of(cx, &title).control(col())),
Some(install) => rows.push(
row_of(cx, &title)
.icon(mark)
.place(Place::Under)
.control(forms::code(k, &cx.key(&format!("install-{n}")), install)),
),
None => rows.push(row_of(cx, &title).icon(mark).control(col())),
}
if let Some(adapter) = &missing.adapter {
rows.extend(adapter_rows(cx, &missing.label, adapter));
Expand Down
18 changes: 17 additions & 1 deletion native/src/bot_settings_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub enum Place {
pub struct Row<'a> {
cx: Ctx<'a>,
what: String,
icon: Option<V>,
hint: Hint,
place: Place,
saved: Option<bool>,
Expand All @@ -140,6 +141,7 @@ pub fn row_of<'a>(cx: Ctx<'a>, what: &str) -> Row<'a> {
Row {
cx,
what: what.to_owned(),
icon: None,
hint: Hint::None,
place: Place::End,
saved: None,
Expand All @@ -148,6 +150,12 @@ pub fn row_of<'a>(cx: Ctx<'a>, what: &str) -> Row<'a> {
}

impl Row<'_> {
/// An optional leading icon rendered beside the row's title.
pub fn icon(mut self, icon: Option<V>) -> Self {
self.icon = icon;
self
}

pub fn hint(mut self, hint: impl Into<Hint>) -> Self {
self.hint = hint.into();
self
Expand Down Expand Up @@ -185,7 +193,15 @@ impl Row<'_> {
/// The row, with `control`.
pub fn control(self, control: V) -> V {
let k = self.cx.k;
let mut name = col().child(words(&self.what, SIZE_UI, LEADING, k.fg));
let title = match self.icon {
Some(mark) => row()
.gap(SPACE_2)
.align(Align::Center)
.child(mark)
.child(words(&self.what, SIZE_UI, LEADING, k.fg)),
None => words(&self.what, SIZE_UI, LEADING, k.fg),
};
let mut name = col().child(title);
match self.hint {
Hint::None => {}
Hint::Plain(s) => name = name.child(words(&s, SIZE_SMALL, LEADING_SMALL, k.fg_muted)),
Expand Down
234 changes: 234 additions & 0 deletions native/src/brand_icons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
//! Bundled monochrome brand marks for connectors, channels, and installed agents
//! (matching `window/ui/src/brandIcons.ts` and `BrandIcon.tsx`, generated from
//! the same `simple-icons` pipeline). Zero runtime network calls.

use std::sync::LazyLock;
use weft::{Align, Color, El, Icon, Justify, icon, row, text};

use crate::brand_icons_data::{
AGENT_ICON_SLUGS, BRAND_ICONS, BrandEntry, CHANNEL_ICON_SLUGS, CONNECTOR_ICON_SLUGS,
};
use crate::tokens::*;

/// Legal attribution shown once per catalog that renders third-party brand marks.
pub const TRADEMARK_NOTE: &str = "Product names and logos are trademarks of their respective owners, shown for identification only.";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BrandNamespace {
Connector,
Channel,
Agent,
}

fn table(namespace: BrandNamespace) -> &'static [(&'static str, &'static str)] {
match namespace {
BrandNamespace::Connector => CONNECTOR_ICON_SLUGS,
BrandNamespace::Channel => CHANNEL_ICON_SLUGS,
BrandNamespace::Agent => AGENT_ICON_SLUGS,
}
}

fn candidate_keys(id: &str) -> Vec<String> {
let raw = id.trim();
if raw.is_empty() {
return Vec::new();
}
let lowered = raw.to_lowercase();
let mut dashed = String::with_capacity(lowered.len());
let mut prev_dash = false;
for ch in lowered.chars() {
if ch.is_whitespace() || matches!(ch, '_' | '.') {
if !prev_dash {
dashed.push('-');
prev_dash = true;
}
} else {
dashed.push(ch);
prev_dash = false;
}
}
let stripped = dashed
.strip_prefix("mcp-")
.unwrap_or(&dashed)
.strip_suffix("-mcp")
.or_else(|| {
dashed
.strip_prefix("mcp-")
.unwrap_or(&dashed)
.strip_suffix("-acp")
})
.unwrap_or(dashed.strip_prefix("mcp-").unwrap_or(&dashed))
.to_owned();

let mut out = Vec::with_capacity(4);
for key in [raw.to_owned(), lowered, dashed, stripped] {
if !key.is_empty() && !out.contains(&key) {
out.push(key);
}
}
out
}

fn index_of(namespace: BrandNamespace, id: &str) -> Option<usize> {
let entries = table(namespace);
for key in candidate_keys(id) {
if let Some((_, slug)) = entries.iter().find(|(k, _)| *k == key) {
return BRAND_ICONS.iter().position(|e| e.slug == *slug);
}
}
None
}

/// Looks up the bundled brand entry for `(namespace, id)`, or `None` when unmapped.
pub fn brand_entry(namespace: BrandNamespace, id: &str) -> Option<&'static BrandEntry> {
index_of(namespace, id).map(|at| &BRAND_ICONS[at])
}

/// Up to two uppercase initials for the monogram fallback (`"Google Maps"` -> `"GM"`).
pub fn brand_initials(name: &str) -> String {
let cleaned = name.trim();
if cleaned.is_empty() {
return "?".to_owned();
}
let words: Vec<&str> = cleaned
.split(|c: char| c.is_whitespace() || matches!(c, '-' | '_' | '.' | '/'))
.filter(|w| !w.is_empty())
.collect();
if words.len() >= 2 {
let mut s = String::new();
if let Some(a) = words[0].chars().next() {
s.extend(a.to_uppercase());
}
if let Some(b) = words[1].chars().next() {
s.extend(b.to_uppercase());
}
return s;
}
cleaned
.chars()
.take(2)
.flat_map(char::to_uppercase)
.collect()
}

fn svg(path: &str) -> String {
format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"#000\">\
<path d=\"{path}\"/></svg>"
)
}

fn parsed() -> &'static [Icon] {
static SET: LazyLock<Vec<Icon>> = LazyLock::new(|| {
BRAND_ICONS
.iter()
.map(|e| {
Icon::from_svg(&format!("brand-{}", e.slug), &svg(e.path)).expect("valid brand SVG")
})
.collect()
});
&SET
}

/// Bare monochrome brand mark of `size` px tinted `color`, or `None` when unmapped.
pub fn brand_glyph<S>(
namespace: BrandNamespace,
id: &str,
size: f32,
color: Color,
) -> Option<El<S>> {
let at = index_of(namespace, id)?;
Some(
icon(parsed()[at].clone())
.size(size)
.color(color)
.el()
.shrink(0.0),
)
}

/// Square tile with the bundled monochrome brand mark, or a two-letter monogram when unmapped.
/// Uses `k.tile_fill()` so the mark steps cleanly off a connector or catalog tile (`--bg-soft`).
pub fn brand_mark<S>(k: &Tokens, namespace: BrandNamespace, id: &str, name: &str) -> El<S> {
let box_el = row()
.size(AVATAR_CHAT, AVATAR_CHAT)
.shrink(0.0)
.radius(RADIUS_M)
.fill(k.tile_fill())
.align(Align::Center)
.justify(Justify::Center);
if let Some(glyph) = brand_glyph(namespace, id, ICON - SPACE_0, k.fg_muted) {
box_el.child(glyph)
} else {
box_el.child(
text(brand_initials(name))
.font_size(SIZE_SMALL)
.line_height(LEADING_SMALL)
.weight(WEIGHT_STRONG)
.color(k.fg_muted),
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn bundled_marks_parse_and_resolve() {
assert_eq!(parsed().len(), BRAND_ICONS.len());
for name in [
"git",
"linear",
"notion",
"sentry",
"stripe",
"fetch",
"filesystem",
"time",
"sequential-thinking",
] {
assert!(
brand_entry(BrandNamespace::Connector, name).is_some(),
"missing connector brand mark for {name}"
);
}
assert_eq!(
brand_entry(BrandNamespace::Connector, "mcp-linear").map(|e| e.title),
Some("Linear")
);
assert_eq!(
brand_entry(BrandNamespace::Channel, "telegram").map(|e| e.title),
Some("Telegram")
);
assert_eq!(
brand_entry(BrandNamespace::Channel, "discord").map(|e| e.title),
Some("Discord")
);
assert_eq!(
brand_entry(BrandNamespace::Agent, "Claude Code").map(|e| e.title),
Some("Claude")
);
assert_eq!(
brand_entry(BrandNamespace::Agent, "codex-acp").map(|e| e.title),
Some("Codex")
);
assert_eq!(
brand_entry(BrandNamespace::Agent, "opencode").map(|e| e.title),
Some("opencode")
);
assert_eq!(
brand_entry(BrandNamespace::Agent, "Gemini CLI").map(|e| e.title),
Some("Google Gemini")
);
assert!(brand_entry(BrandNamespace::Connector, "my-custom-server").is_none());
}

#[test]
fn initials_fallback_handles_words_and_empty() {
assert_eq!(brand_initials("Google Maps"), "GM");
assert_eq!(brand_initials("my-custom-server"), "MC");
assert_eq!(brand_initials("fetch"), "FE");
assert_eq!(brand_initials(""), "?");
}
}
Loading
Loading