Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(desktop): keep bot avatars sharp on non-Retina screens
leepokaia05143a10c90
diff --git a/apps/desktop/src/main/tray.ts b/apps/desktop/src/main/tray.tsindex 2a3935a5..c8792ecb 100644--- a/apps/desktop/src/main/tray.ts+++ b/apps/desktop/src/main/tray.ts@@ -1,6 +1,6 @@import { join } from 'node:path'import { app, clipboard, Menu, nativeImage, shell, Tray as ElectronTray } from 'electron'-import type { TraySummary, WindowCommand } from '../shared/ipc'+import type { TrayImage, TraySummary, WindowCommand } from '../shared/ipc'import type { HostController } from './host-controller'import type { Updates } from './updates'import { updateAction } from '../shared/update-action'@@ -55,11 +55,12 @@ export class Tray {this.rebuild()}- /** The renderer draws menu images at 2× (`tray-summary.ts`): shown at half their pixel size. */- private image(dataURL: string | null) {- if (!dataURL) return undefined+ /** The renderer draws menu images at 1× and 2× (`tray-summary.ts`): each screen gets its own pixels. */+ private image(drawn: TrayImage | null) {+ if (!drawn) return undefinedconst image = nativeImage.createEmpty()- image.addRepresentation({ scaleFactor: 2, dataURL })+ image.addRepresentation({ scaleFactor: 1, dataURL: drawn.x1 })+ image.addRepresentation({ scaleFactor: 2, dataURL: drawn.x2 })return image.isEmpty() ? undefined : image}diff --git a/apps/desktop/src/renderer/components/Avatar.tsx b/apps/desktop/src/renderer/components/Avatar.tsxindex a8515546..992d7813 100644--- a/apps/desktop/src/renderer/components/Avatar.tsx+++ b/apps/desktop/src/renderer/components/Avatar.tsx@@ -1,5 +1,6 @@import { memo, useEffect, useRef, type CSSProperties } from 'react'import { isGroup, isWorking, needsInput, type Bot } from '@shared/models'+import { DOT_RADIUS, dotGrid } from '../lib/dot-grid'import { avatarColor, palette, useDark, usePixelRatio, useReduceMotion } from '../lib/theme'import { Icon } from './Icon'import './avatar.css'@@ -120,12 +121,15 @@ export const CharacterAvatar = memo(function CharacterAvatar({ shape, color, tinconst reduce = useReduceMotion()const ratio = usePixelRatio()const fill = tint ?? avatarColor(color)+ // A whole number of device pixels, so the bitmap shows 1:1 and drawCharacter's pixels are the screen's.+ const pixels = Math.max(1, Math.round(size * ratio))useEffect(() => {const el = canvas.currentif (!el) return- el.width = Math.round(size * ratio)- el.height = Math.round(size * ratio)+ el.width = pixels+ el.height = pixels+ const scale = pixels / sizeconst ctx = el.getContext('2d')!const still = mood === 'idle' || reduce// A moving character draws at 30 fps (its light turns slowly), and only while on screen.@@ -136,7 +140,7 @@ export const CharacterAvatar = memo(function CharacterAvatar({ shape, color, tinframe = 0if (time - drawn >= 33) {drawn = time- ctx.setTransform(ratio, 0, 0, ratio, 0, 0)+ ctx.setTransform(scale, 0, 0, scale, 0, 0)ctx.clearRect(0, 0, size, size)drawCharacter(ctx, { shape, fill, size, mood, dark, t: still ? 0 : (time / 1000) % 3600, still })}@@ -153,9 +157,9 @@ export const CharacterAvatar = memo(function CharacterAvatar({ shape, color, tinonScreen.disconnect()cancelAnimationFrame(frame)}- }, [shape, fill, size, mood, dark, reduce, ratio])+ }, [shape, fill, size, mood, dark, reduce, pixels])- return <canvas ref={canvas} aria-hidden style={{ width: size, height: size, display: 'block', flex: 'none' }} />+ return <canvas ref={canvas} aria-hidden style={{ width: pixels / ratio, height: pixels / ratio, display: 'block', flex: 'none' }} />})/** Draws one frame of a character at the context's origin (views and menu bar icons). */@@ -163,10 +167,10 @@ export function drawCharacter(ctx: CanvasRenderingContext2D,{ shape, fill, size, mood, dark, t, still }: { shape: string; fill: string; size: number; mood: Mood; dark: boolean; t: number; still: boolean },) {- const cells = size < 18 ? 7 : size < 28 ? 9 : 13+ // The grid fits the context's device pixels (its scale).+ const { cells, pitch, first } = dotGrid(size, ctx.getTransform().a || 1)const eyeColumns = cells === 7 ? [2, 4] : cells === 9 ? [3, 6] : [4, 8]const eyeRowsAll = cells === 13 ? [4, 5, 6] : cells === 9 ? [3, 4] : [2, 3]- const step = size / cellsconst dots = grid(shape, size, cells)const [tr, tg, tb] = palette(dark).textconst n = parseInt(fill.slice(1), 16)@@ -193,10 +197,10 @@ export function drawCharacter(const ripple = 0.5 + 0.5 * Math.sin(Math.hypot(u, v) * 9 - t * 5)shade *= 0.6 + 0.4 * ripple}- const r = step * 0.42 * (0.55 + 0.45 * shade)+ const r = pitch * DOT_RADIUS * (0.55 + 0.45 * shade)const ink = cells < 13 ? 0.4 + 0.4 * shade : 0.2 + 0.4 * Math.min(1, shade / 0.7)ctx.beginPath()- ctx.arc(d.x, d.y, r, 0, Math.PI * 2)+ ctx.arc(first + d.col * pitch, first + d.row * pitch, r, 0, Math.PI * 2)ctx.fillStyle = `rgba(${tr},${tg},${tb},${ink})`ctx.fill()if (shade > 0.6) {diff --git a/apps/desktop/src/renderer/lib/dot-grid.test.ts b/apps/desktop/src/renderer/lib/dot-grid.test.tsnew file mode 100644index 00000000..2be9e8f3--- /dev/null+++ b/apps/desktop/src/renderer/lib/dot-grid.test.ts@@ -0,0 +1,36 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { DOT_RADIUS, dotGrid } from './dot-grid.ts'++test('below 2x dots sit on pixel centers (even pitch) or corners (odd) and the grid stays in its box', () => {+ for (const scale of [1, 1.25, 1.5]) {+ for (let px = 10; px <= 100; px++) {+ const size = px / scale+ const { cells, pitch, first } = dotGrid(size, scale)+ const devicePitch = Math.round(pitch * scale)+ assert.ok(Math.abs(pitch * scale - devicePitch) < 1e-6, `${px} px at ${scale}x: pitch ${pitch * scale}`)+ const offset = devicePitch % 2 ? 0 : 0.5+ for (let i = 0; i < cells; i++) {+ const center = (first + i * pitch) * scale+ assert.ok(Math.abs(center - Math.floor(center + 1e-6) - offset) < 1e-6, `${px} px at ${scale}x: dot ${i} at ${center}`)+ }+ const reach = DOT_RADIUS * pitch * scale+ assert.ok(first * scale - reach >= -0.5, `${px} px at ${scale}x overflows left`)+ assert.ok((first + (cells - 1) * pitch) * scale + reach <= px + 1, `${px} px at ${scale}x overflows right`)+ }+ }+})++test('a 1x screen gets a sparser grid that still fills a menu bar icon', () => {+ assert.equal(dotGrid(30, 1).cells, 9)+ assert.equal(dotGrid(20, 1).cells, 7)+ assert.equal(dotGrid(20, 1).pitch, 3)+})++test('Retina keeps the exact design grid', () => {+ for (let size = 10; size <= 60; size += 0.5) {+ const cells = size < 18 ? 7 : size < 28 ? 9 : 13+ const step = size / cells+ assert.deepEqual(dotGrid(size, 2), { cells, pitch: step, first: step / 2 })+ }+})diff --git a/apps/desktop/src/renderer/lib/dot-grid.ts b/apps/desktop/src/renderer/lib/dot-grid.tsnew file mode 100644index 00000000..3d4c9959--- /dev/null+++ b/apps/desktop/src/renderer/lib/dot-grid.ts@@ -0,0 +1,24 @@+/** A full-shade dot's radius, as a share of the pitch. */+export const DOT_RADIUS = 0.42++/**+ * Where a character's dots go in a `size` box drawn at `scale` device pixels per unit: `cells` per+ * side, `pitch` apart, the first centered at `first`. Dots need whole device pixels: 13 cells over+ * 30 px of a 1x screen alias into a blur, so 13 cells need 4 px each and 9 need 3. Below 2x the pitch+ * is whole pixels too (rounded, or rounded down when that overflows the box by more than a pixel),+ * so every gap is equal. A dot is about a pixel narrower than the pitch: an even width (odd pitch)+ * stays crisp centered on a pixel corner, an odd width on a pixel center. Retina keeps the exact grid.+ */+export function dotGrid(size: number, scale: number) {+ // The canvas is whole device pixels: rounding drops the float error of size × scale.+ const px = Math.round(size * scale)+ const cells = Math.min(size < 18 ? 7 : size < 28 ? 9 : 13, px < 27 ? 7 : px < 52 ? 9 : 13)+ const step = size / cells+ if (scale >= 2) return { cells, pitch: step, first: step / 2 }+ const exact = step * scale+ const rounded = Math.round(exact)+ const devicePitch = Math.max(1, rounded * (cells - 1 + 2 * DOT_RADIUS) <= px + 1 ? rounded : Math.floor(exact))+ const centered = (px - devicePitch * (cells - 1)) / 2+ const first = devicePitch % 2 ? Math.round(centered) : Math.floor(centered) + 0.5+ return { cells, pitch: devicePitch / scale, first: first / scale }+}diff --git a/apps/desktop/src/renderer/views/island/IslandUsage.tsx b/apps/desktop/src/renderer/views/island/IslandUsage.tsxindex 0a6baeab..bc3cb500 100644--- a/apps/desktop/src/renderer/views/island/IslandUsage.tsx+++ b/apps/desktop/src/renderer/views/island/IslandUsage.tsx@@ -1,5 +1,6 @@import type { UsageProvider, UsageWindow } from '@shared/models'import { prefs, usePref } from '../../lib/prefs'+import { usePixelRatio } from '../../lib/theme'import { UsageBar } from '../usage/UsageBar'import { mascotDataURL } from '../usage/ProviderMascot'import { providerTintCSS, resetDescription, tightest, windowTitle } from '../usage/usage-model'@@ -11,7 +12,8 @@ import type { IslandModel } from './island-model'/** A provider's character for the black island, whatever the system appearance. */function Mascot({ provider, size }: { provider: UsageProvider; size: number }) {const [style] = usePref(prefs.usageIconStyle)- const src = mascotDataURL(provider, size, style, true)+ const ratio = usePixelRatio()+ const src = mascotDataURL(provider, size, style, true, ratio)return src ? <img src={src} alt="" width={size} height={size} className="island-mascot" /> : null}diff --git a/apps/desktop/src/renderer/views/tray-summary.ts b/apps/desktop/src/renderer/views/tray-summary.tsindex a20b1ff0..b3d9541e 100644--- a/apps/desktop/src/renderer/views/tray-summary.ts+++ b/apps/desktop/src/renderer/views/tray-summary.ts@@ -1,5 +1,5 @@import { useEffect } from 'react'-import type { TraySummary } from '@shared/ipc'+import type { TrayImage, TraySummary } from '@shared/ipc'import { isGroup, isWorking, needsInput, folderName, type Bot, type UsageWindow } from '@shared/models'import { drawCharacter, moodOf } from '../components/Avatar'import { useModels } from '../lib/observable'@@ -7,32 +7,40 @@ import { prefs, usePref } from '../lib/prefs'import { avatarColor, isDark, palette } from '../lib/theme'import type { AppModel } from '../store/app-model'import { providerTint, resetDate, untilText, windowTitle } from './usage/usage-model'-import { mascotDataURL } from './usage/ProviderMascot'+import { drawMascot, nearlyUsedUp } from './usage/ProviderMascot'const isMac = window.codync.platform === 'darwin'/** Rendered icons by what they show and the appearance: nothing is redrawn while nothing changed. */-const cache = new Map<string, string>()+const cache = new Map<string, TrayImage>()-function canvasURL(key: string, width: number, height: number, draw: (ctx: CanvasRenderingContext2D) => void) {+/**+ * A menu image drawn for 1x and 2x screens (a 1x screen shrinking a 2x image blurs it), or null+ * while `draw` can't draw yet (it returns false).+ */+function canvasImage(key: string, width: number, height: number, draw: (ctx: CanvasRenderingContext2D) => boolean | void): TrayImage | null {const full = `${key}|${isDark()}`const hit = cache.get(full)if (hit) return hit- const ratio = 2- const canvas = document.createElement('canvas')- canvas.width = width * ratio- canvas.height = height * ratio- const ctx = canvas.getContext('2d')!- ctx.scale(ratio, ratio)- draw(ctx)- const url = canvas.toDataURL('image/png')- cache.set(full, url)- return url+ const at = (ratio: number) => {+ const canvas = document.createElement('canvas')+ canvas.width = width * ratio+ canvas.height = height * ratio+ const ctx = canvas.getContext('2d')!+ ctx.scale(ratio, ratio)+ return draw(ctx) === false ? null : canvas.toDataURL('image/png')+ }+ const x1 = at(1)+ const x2 = x1 && at(2)+ if (!x1 || !x2) return null+ const image = { x1, x2 }+ cache.set(full, image)+ return image}function avatarIcon(bot: Bot) {const key = `bot|${bot.id}|${bot.avatarShape}|${bot.avatarColor}|${bot.status}|${bot.unread > 0}`- return canvasURL(key, 20, 20, (ctx) => {+ return canvasImage(key, 20, 20, (ctx) => {const dark = isDark()drawCharacter(ctx, { shape: bot.avatarShape, fill: avatarColor(bot.avatarColor), size: 20, mood: moodOf(bot, false), dark, t: 0, still: true })const badge = needsInput(bot) ? palette(dark).warning : bot.unread > 0 ? (dark ? '#FFFFFF' : '#000000') : null@@ -58,7 +66,7 @@ export function botDetail(bot: Bot) {/** One usage limit's bar in the provider's color: amber from 70%, red from 90%. */function barIcon(providerId: string, window: UsageWindow) {const percent = Math.round(window.percent)- return canvasURL(`bar|${providerId}|${percent}`, 60, 16, (ctx) => {+ return canvasImage(`bar|${providerId}|${percent}`, 60, 16, (ctx) => {const dark = isDark()const color = window.percent >= 90 ? palette(dark).danger : window.percent >= 70 ? palette(dark).warning : providerTint(providerId)ctx.fillStyle = dark ? 'rgba(255,255,255,0.12)' : 'rgba(0,0,0,0.12)'@@ -110,7 +118,7 @@ export function useTraySummary(app: AppModel) {})),usage: (local?.usage.providers ?? []).map((p) => ({name: p.name,- icon: mascotDataURL(p, 16, iconStyle, isDark()),+ icon: canvasImage(`mascot|${p.id}|${iconStyle}|${nearlyUsedUp(p)}`, 16, 16, (ctx) => drawMascot(ctx, p, 16, iconStyle, isDark())),lines: p.windows.map((w) => ({ title: usageLine(w), bar: barIcon(p.id, w) })),})),screen: screendiff --git a/apps/desktop/src/renderer/views/usage/ProviderMascot.tsx b/apps/desktop/src/renderer/views/usage/ProviderMascot.tsxindex 92d3679b..f5391675 100644--- a/apps/desktop/src/renderer/views/usage/ProviderMascot.tsx+++ b/apps/desktop/src/renderer/views/usage/ProviderMascot.tsx@@ -7,9 +7,14 @@ import { palette } from '../../lib/theme'import { mascotShape, providerRegistry, providerTint, providerTintCSS, tightest } from './usage-model'import './usage.css'+/** Whether any of the provider's limits is nearly used up (its mascot shows a red alert). */+export function nearlyUsedUp(provider: UsageProvider) {+ return (tightest(provider)?.percent ?? 0) >= 90+}+/** A provider's character, with a red "!" once any of its limits is nearly used up. */export function ProviderMascot({ provider, size, style = 'character' }: { provider: UsageProvider; size: number; style?: 'character' | 'original' }) {- const full = (tightest(provider)?.percent ?? 0) >= 90+ const full = nearlyUsedUp(provider)if (style === 'original') {return (<span className="usage-mascot-logo" style={{ width: size, height: size }}>@@ -31,33 +36,27 @@ export function ProviderMascot({ provider, size, style = 'character' }: { providconst loaded = new Map<string, HTMLImageElement>()-/** The mascot as a menu bar image (16 pt). Original logos load once, then appear on the next update. */-export function mascotDataURL(provider: UsageProvider, size: number, style: 'character' | 'original', dark: boolean): string | null {- const ratio = 2- const canvas = document.createElement('canvas')- canvas.width = size * ratio- canvas.height = size * ratio- const ctx = canvas.getContext('2d')!- ctx.scale(ratio, ratio)+/** Draws the mascot at the context's origin; false while an original logo loads (it appears on the next update). */+export function drawMascot(ctx: CanvasRenderingContext2D, provider: UsageProvider, size: number, style: 'character' | 'original', dark: boolean): boolean {const tint = provider.id === 'claude' ? '#D97757' : dark ? '#FFFFFF' : '#000000'if (style === 'original') {const url = agentIconURL(providerRegistry(provider.id))- if (!url) return null+ if (!url) return falseconst image = loaded.get(url)if (!image) {const img = new Image()img.src = urlimg.onload = () => loaded.set(url, img)- return null+ return false}const inset = size * 0.08ctx.drawImage(image, inset, inset, size - inset * 2, size - inset * 2)ctx.globalCompositeOperation = 'source-in'ctx.fillStyle = tintctx.fillRect(0, 0, size, size)- return canvas.toDataURL('image/png')+ return true}- const full = (tightest(provider)?.percent ?? 0) >= 90+ const full = nearlyUsedUp(provider)drawCharacter(ctx, { shape: mascotShape(provider.id), fill: tint, size, mood: full ? 'needsInput' : 'idle', dark, t: 0, still: true })if (full) {ctx.beginPath()@@ -65,5 +64,16 @@ export function mascotDataURL(provider: UsageProvider, size: number, style: 'chactx.fillStyle = palette(dark).dangerctx.fill()}- return canvas.toDataURL('image/png')+ return true+}++/** The mascot as an image for a screen of `ratio` (the island), or null while it can't be drawn. */+export function mascotDataURL(provider: UsageProvider, size: number, style: 'character' | 'original', dark: boolean, ratio: number): string | null {+ const pixels = Math.max(1, Math.round(size * ratio))+ const canvas = document.createElement('canvas')+ canvas.width = pixels+ canvas.height = pixels+ const ctx = canvas.getContext('2d')!+ ctx.scale(pixels / size, pixels / size)+ return drawMascot(ctx, provider, size, style, dark) ? canvas.toDataURL('image/png') : null}diff --git a/apps/desktop/src/shared/ipc.ts b/apps/desktop/src/shared/ipc.tsindex 52c0ccd9..8d0bb30a 100644--- a/apps/desktop/src/shared/ipc.ts+++ b/apps/desktop/src/shared/ipc.ts@@ -36,13 +36,19 @@ export interface CallError {message: string}+/** A menu image as PNG data URLs drawn for 1x and 2x screens; each screen shows its own. */+export interface TrayImage {+ x1: string+ x2: string+}+/** What the tray menu shows; the renderer owns the stores and sends this on every change. */export interface TraySummary {status: stringcanPair: boolean- bots: { ref: string; name: string; detail: string; working: boolean; avatar: string | null }[]+ bots: { ref: string; name: string; detail: string; working: boolean; avatar: TrayImage | null }[]approval: string | null- usage: { name: string; icon: string | null; lines: { title: string; bar: string | null }[] }[]+ usage: { name: string; icon: TrayImage | null; lines: { title: string; bar: TrayImage | null }[] }[]screen: {enabled: booleansubtitle: stringdiff --git a/docs/design/mobile-widgets.md b/docs/design/mobile-widgets.mdindex cb18de12..91808c07 100644--- a/docs/design/mobile-widgets.md+++ b/docs/design/mobile-widgets.md@@ -104,7 +104,7 @@ Dynamic Island 固定黑底,文字採淺色;Lock Screen 卡片配合系統## Halftone 與 Thinking Orbs(2026-09-26)-Bot 的角色頭像使用 `CharacterAvatar` 點陣;provider 圖示由 `ProviderMascot` 選擇,小尺寸可使用隨 app 打包的官方 provider 圖示。15 pt 用 7 × 7、20–26 pt 用 9 × 9、28 pt 以上用 13 × 13 網格,保留鏤空眼睛並提高小尺寸墨色。iOS App 與 widgets 共用 provider 呈現邏輯;桌面 App 的對應實作在 `apps/desktop/src/renderer/views/usage/ProviderMascot.tsx`。+Bot 的角色頭像使用 `CharacterAvatar` 點陣;provider 圖示由 `ProviderMascot` 選擇,小尺寸可使用隨 app 打包的官方 provider 圖示。15 pt 用 7 × 7、20–26 pt 用 9 × 9、28 pt 以上用 13 × 13 網格,保留鏤空眼睛並提高小尺寸墨色。桌面另依裝置像素限制密度(13 格至少 52 px、9 格至少 27 px),1x 螢幕因此用較疏的網格;2x 以下還把點距對齊整數像素,讓點間距一致,點落在像素中心或角落以保持銳利(`apps/desktop/src/renderer/lib/dot-grid.ts`)。iPhone 螢幕至少 2x,維持原本網格;Android 目前仍只依 dp 選網格。iOS App 與 widgets 共用 provider 呈現邏輯;桌面 App 的對應實作在 `apps/desktop/src/renderer/views/usage/ProviderMascot.tsx`。狀態圖示以 [Jakub Antalik 的 thinking-orbs](https://github.com/Jakubantalik/thinking-orbs) 為來源,這次原生移植四種實際使用的造型: