Skip to content

Your lightweight open-source personal agent.

fix(webui): align channel logo presentation

Xubin Ren73bc6d083ef4
diff --git a/nanobot/channels/email/webui/index.ts b/nanobot/channels/email/webui/index.ts
index 6cb45059a..2952ee7d1 100644
--- a/nanobot/channels/email/webui/index.ts
+++ b/nanobot/channels/email/webui/index.ts
@@ -1,3 +1,5 @@
+import { Mail } from "lucide-react";
+
import type { ChannelUiContribution } from "@/channel-plugins/types";
import {
type ChannelProviderPresetDefinition,
@@ -36,7 +38,7 @@ const EMAIL_PROVIDER_PRESETS: ChannelProviderPresetDefinition[] = [
export default {
presentation: {
- logoUrl: "https://gmail.com/favicon.ico",
+ icon: Mail,
displayName: "Email",
initials: "EM",
color: "#64748B",
diff --git a/nanobot/channels/feishu/webui/index.tsx b/nanobot/channels/feishu/webui/index.tsx
index 13ec8153d..eb6902d17 100644
--- a/nanobot/channels/feishu/webui/index.tsx
+++ b/nanobot/channels/feishu/webui/index.tsx
@@ -19,6 +19,7 @@ export default {
},
presentation: {
logoUrl: "https://www.larksuite.com/favicon.ico",
+ logoLayout: "tile",
displayName: "Feishu",
initials: "FS",
color: "#3370FF",
diff --git a/nanobot/channels/linear/webui/index.tsx b/nanobot/channels/linear/webui/index.tsx
index 40dc533b6..4600a29aa 100644
--- a/nanobot/channels/linear/webui/index.tsx
+++ b/nanobot/channels/linear/webui/index.tsx
@@ -16,6 +16,7 @@ export default {
initials: "LI",
color: "#5E6AD2",
logoUrl: "https://linear.app/favicon.ico",
+ logoLayout: "tile",
setup: {
mode: "connect",
docsUrl: chatAppGuideUrl("linear"),
diff --git a/nanobot/channels/qq/webui/index.ts b/nanobot/channels/qq/webui/index.ts
index 0ddf9a6c7..877a82aa7 100644
--- a/nanobot/channels/qq/webui/index.ts
+++ b/nanobot/channels/qq/webui/index.ts
@@ -3,7 +3,8 @@ import { chatAppGuideUrl } from "@/components/settings/channels/catalog";
export default {
presentation: {
- logoUrl: "https://im.qq.com/favicon.ico",
+ logoUrl: "https://static-res.qq.com/static-res/imqq/qq-logo.png",
+ logoFallbackUrl: "https://im.qq.com/favicon.ico",
displayName: "QQ",
initials: "QQ",
color: "#12B7F5",
diff --git a/webui/src/components/settings/channels/ChannelIdentity.tsx b/webui/src/components/settings/channels/ChannelIdentity.tsx
index dfb7c8bd3..6a1f84393 100644
--- a/webui/src/components/settings/channels/ChannelIdentity.tsx
+++ b/webui/src/components/settings/channels/ChannelIdentity.tsx
@@ -20,6 +20,7 @@ import { useLogoFallback } from "@/hooks/useLogoFallback";
import { normalizeLocale } from "@/i18n/config";
import { logoFallbackUrls } from "@/lib/provider-brand";
import type { ChannelRuntimeStatus, NanobotFeatureInfo } from "@/lib/types";
+import { cn } from "@/lib/utils";
export const CHANNEL_SETUP_PANEL_CLASS_NAME =
"min-h-full rounded-panel bg-settings-surface p-6";
@@ -145,48 +146,48 @@ export function ChannelLogo({
const presentation = channelUiPresentation(feature.name, feature.webui)
?? channelUiPresentation(feature.name);
const initials = presentation?.initials ?? feature.display_name.slice(0, 2).toUpperCase();
- const color = presentation?.color ?? "#6B7280";
const Icon = presentation?.icon;
- const logoUrls = useMemo(() => logoFallbackUrls(presentation?.logoUrl), [presentation?.logoUrl]);
- const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
-
- if (showBrandLogos && logoUrl) {
- return (
- <span
- className="grid h-10 w-10 shrink-0 place-items-center rounded-control bg-background"
- >
- <img
- src={logoUrl}
- alt=""
- decoding="async"
- loading="lazy"
- className="h-5.5 w-5.5 max-h-6 max-w-6 object-contain"
- onLoad={onLogoLoad}
- onError={onLogoError}
- />
- </span>
- );
- }
-
- if (Icon) {
- return (
- <span
- className="flex h-10 w-10 shrink-0 items-center justify-center rounded-control bg-background"
- style={{ color }}
- aria-hidden
- >
- <Icon className="h-5 w-5" strokeWidth={2.25} />
- </span>
- );
- }
+ const logoUrls = useMemo(() => {
+ const fallbackUrls = logoFallbackUrls(presentation?.logoFallbackUrl ?? presentation?.logoUrl);
+ return presentation?.logoUrl && presentation.logoFallbackUrl
+ ? [...new Set([presentation.logoUrl, ...fallbackUrls])]
+ : fallbackUrls;
+ }, [presentation?.logoUrl, presentation?.logoFallbackUrl]);
+ const { logoUrl, logoLoaded, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
+ const showRemoteLogo = showBrandLogos && Boolean(logoUrl);
+ const showLoadedLogo = showRemoteLogo && logoLoaded;
+ const isLogoTile = presentation?.logoLayout === "tile" && logoUrl === presentation.logoUrl;
return (
<span
- className="flex h-10 w-10 shrink-0 items-center justify-center rounded-control bg-background text-[11px] font-bold"
- style={{ color }}
+ data-testid={`channel-logo-${feature.name}`}
+ className={cn(
+ "relative grid h-8 w-8 shrink-0 place-items-center overflow-hidden rounded-[9px] text-[11px] font-semibold text-muted-foreground",
+ showLoadedLogo ? (isLogoTile ? "bg-transparent" : "bg-white") : "bg-muted",
+ )}
aria-hidden
>
- {initials}
+ <span className={cn(
+ "transition-opacity duration-150 motion-reduce:transition-none",
+ showLoadedLogo ? "opacity-0" : "opacity-100",
+ )}>
+ {Icon ? <Icon className="h-6 w-6" strokeWidth={2} /> : initials}
+ </span>
+ {showRemoteLogo ? <img
+ src={logoUrl}
+ alt=""
+ decoding="async"
+ loading="lazy"
+ referrerPolicy="no-referrer"
+ draggable={false}
+ className={cn(
+ "absolute object-contain transition-opacity duration-150 motion-reduce:transition-none",
+ isLogoTile ? "h-8 w-8" : "h-6 w-6",
+ logoLoaded ? "opacity-100" : "opacity-0",
+ )}
+ onLoad={onLogoLoad}
+ onError={onLogoError}
+ /> : null}
</span>
);
}
diff --git a/webui/src/components/settings/channels/catalog.ts b/webui/src/components/settings/channels/catalog.ts
index 2b8a12e86..5cda41bb9 100644
--- a/webui/src/components/settings/channels/catalog.ts
+++ b/webui/src/components/settings/channels/catalog.ts
@@ -6,6 +6,10 @@ export type ChannelPresentation = {
color: string;
icon?: ComponentType<{ className?: string; strokeWidth?: string | number }>;
logoUrl?: string;
+ /** Official site favicon to use when the primary asset is hosted on a CDN. */
+ logoFallbackUrl?: string;
+ /** The primary asset already includes its own background and safe area. */
+ logoLayout?: "tile";
setup?: ChannelCatalogSetupPresentation;
};
diff --git a/webui/src/tests/channel-logo.test.tsx b/webui/src/tests/channel-logo.test.tsx
new file mode 100644
index 000000000..eddca0efb
--- /dev/null
+++ b/webui/src/tests/channel-logo.test.tsx
@@ -0,0 +1,139 @@
+import { cleanup, fireEvent, render } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import { channelUiPresentation, registeredChannelUiContributions } from "@/channel-plugins/registry";
+import { ChannelLogo } from "@/components/settings/channels/ChannelIdentity";
+import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
+import { logoFallbackUrls } from "@/lib/provider-brand";
+import type { NanobotFeatureInfo } from "@/lib/types";
+
+function feature(name: string): NanobotFeatureInfo {
+ return {
+ name,
+ display_name: channelUiPresentation(name)?.displayName ?? name,
+ type: "channel",
+ enabled: false,
+ installed: true,
+ ready: true,
+ status: "not_enabled",
+ install_supported: false,
+ requires_restart: false,
+ };
+}
+
+function expectFootprint(icon: Element) {
+ expect(icon).toHaveClass("h-8", "w-8", "shrink-0", "overflow-hidden", "rounded-[9px]");
+ expect(icon).toHaveAttribute("aria-hidden", "true");
+ expect(icon.className.split(/\s+/).some((value) => value.startsWith("border"))).toBe(false);
+}
+
+describe("channel logos", () => {
+ beforeEach(__clearLogoFallbackCacheForTests);
+ afterEach(cleanup);
+
+ const remoteChannels = registeredChannelUiContributions()
+ .filter(({ contribution }) => contribution.presentation.logoUrl)
+ .map(({ channel }) => channel);
+
+ it.each(remoteChannels)("keeps %s in one stable tile while loading", (channel) => {
+ const { container } = render(<ChannelLogo feature={feature(channel)} showBrandLogos />);
+ const icon = container.firstElementChild!;
+ const image = icon.querySelector("img")!;
+ const fallback = icon.querySelector("span")!;
+ const presentation = channelUiPresentation(channel)!;
+
+ expectFootprint(icon);
+ expect(icon).toHaveClass("bg-muted");
+ expect(fallback).toHaveClass("opacity-100");
+ expect(image).toHaveAttribute("src", presentation.logoUrl);
+ expect(image).toHaveAttribute("alt", "");
+ expect(image).toHaveAttribute("referrerpolicy", "no-referrer");
+ expect(image).toHaveClass("object-contain", "opacity-0");
+
+ fireEvent.load(image);
+
+ expectFootprint(icon);
+ expect(fallback).toHaveClass("opacity-0");
+ expect(image).toHaveClass("opacity-100");
+ expect(image).not.toHaveClass("invert", "grayscale", "object-cover");
+ expect(icon).toHaveClass(presentation.logoLayout === "tile" ? "bg-transparent" : "bg-white");
+ expect(image).toHaveClass(...(presentation.logoLayout === "tile" ? ["h-8", "w-8"] : ["h-6", "w-6"]));
+ });
+
+ it.each(["linear", "feishu", "lark"])("insets unknown %s fallback assets instead of stretching them", (channel) => {
+ const { container } = render(<ChannelLogo feature={feature(channel)} showBrandLogos />);
+ const icon = container.firstElementChild!;
+ const image = icon.querySelector("img")!;
+ fireEvent.load(image);
+ expect(icon).toHaveClass("bg-transparent");
+ expect(image).toHaveClass("h-8", "w-8");
+
+ fireEvent.error(image);
+ expect(icon).toHaveClass("bg-muted");
+ expect(image).toHaveClass("h-6", "w-6", "opacity-0");
+ fireEvent.load(image);
+ expect(icon).toHaveClass("bg-white");
+ expectFootprint(icon);
+ });
+
+ it("falls back to initials after all remote sources fail without changing size", () => {
+ const { container } = render(<ChannelLogo feature={feature("slack")} showBrandLogos />);
+ const icon = container.firstElementChild!;
+ for (const url of logoFallbackUrls(channelUiPresentation("slack")!.logoUrl)) {
+ const image = icon.querySelector("img")!;
+ expect(image).toHaveAttribute("src", url);
+ fireEvent.error(image);
+ expect(container.firstElementChild).toBe(icon);
+ expectFootprint(icon);
+ expect(icon).toHaveClass("bg-muted");
+ expect(icon.querySelector("span")).toHaveClass("opacity-100");
+ }
+ expect(icon.querySelector("img")).toBeNull();
+ expect(icon).toHaveTextContent(channelUiPresentation("slack")!.initials!);
+ });
+
+ it("respects the brand logo preference even for cached images", () => {
+ const { container, rerender } = render(<ChannelLogo feature={feature("slack")} showBrandLogos />);
+ const icon = container.firstElementChild!;
+ fireEvent.load(icon.querySelector("img")!);
+
+ rerender(<ChannelLogo feature={feature("slack")} showBrandLogos={false} />);
+ expectFootprint(icon);
+ expect(icon.querySelector("img")).toBeNull();
+ expect(icon).toHaveClass("bg-muted");
+ expect(icon.querySelector("span")).toHaveClass("opacity-100");
+
+ rerender(<ChannelLogo feature={feature("slack")} showBrandLogos />);
+ expect(icon.querySelector("img")).toHaveClass("opacity-100");
+ expect(icon).toHaveClass("bg-white");
+ });
+
+ it("uses a generic envelope for Email without requesting a vendor logo", () => {
+ const { container } = render(<ChannelLogo feature={feature("email")} showBrandLogos />);
+ expectFootprint(container.firstElementChild!);
+ expect(container.querySelector("svg.lucide-mail")).not.toBeNull();
+ expect(container.querySelector("img")).toBeNull();
+ expect(channelUiPresentation("email")?.logoUrl).toBeUndefined();
+ });
+
+ it("falls back to QQ's official favicon rather than its CDN's identity", () => {
+ const { container } = render(<ChannelLogo feature={feature("qq")} showBrandLogos />);
+ const image = container.querySelector("img")!;
+ expect(image).toHaveAttribute("src", channelUiPresentation("qq")!.logoUrl);
+ fireEvent.error(image);
+ expect(image).toHaveAttribute("src", "https://im.qq.com/favicon.ico");
+ fireEvent.load(image);
+ expect(container.firstElementChild).toHaveClass("bg-white");
+ });
+
+ it("keeps the local nanobot mark and unknown channel initials readable", () => {
+ const { container, rerender } = render(<ChannelLogo feature={feature("websocket")} showBrandLogos />);
+ expectFootprint(container.firstElementChild!);
+ expect(container.querySelector("img")).toHaveAttribute("src", "/brand/nanobot_mark.svg");
+
+ rerender(<ChannelLogo feature={feature("custom-channel")} showBrandLogos />);
+ expectFootprint(container.firstElementChild!);
+ expect(container.firstElementChild).toHaveTextContent("CU");
+ expect(container.querySelector("img")).toBeNull();
+ });
+});