A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
feat: enhance OpenCode Go account discovery and connection help in the dock
CristianOlivera123184c6673eb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04dde16..a8069d7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,12 +10,20 @@ copia la sección de la versión que se publica a la release de GitHub.### English+- Fixed OpenCode Go account discovery: read its `opencode-go` credential, respect+ `XDG_DATA_HOME`, and fall back from an empty environment key to the saved login.+ The usage card now identifies Go explicitly and provides a working connection+ guide button instead of an inert sign-in instruction.- WinGet manifests now use `/S` for both unattended modes and declare theVisual C++ x64 and WebView2 runtime dependencies. This addresses first-installUI and missing-runtime risks; Microsoft installation revalidation is pending.### Español+- Corregida la detección de cuentas OpenCode Go: se lee la credencial `opencode-go`,+ se respeta `XDG_DATA_HOME` y una variable de clave vacía permite usar la sesión+ guardada. La tarjeta identifica Go e incluye un botón funcional con instrucciones+ de conexión, en lugar de un texto de inicio de sesión sin acción.- Los manifiestos de WinGet usan `/S` en ambos modos desatendidos y declaranlas dependencias de Visual C++ x64 y WebView2. Se corrigen riesgos de interfazen la primera instalación y de runtimes ausentes; falta revalidar con Microsoft.diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rsindex a98e73f..2b37273 100644--- a/apps/dock/src/app.rs+++ b/apps/dock/src/app.rs@@ -100,7 +100,7 @@ use crate::{group_view::{DragGhost, GroupItem, GroupView, Placement, Released},mascot,menu::{self, MenuItem},- menubar::{self, MenuBar, MenuBarWidgets},+ menubar::{MenuBar, MenuBarWidgets},multi_window_view::MultiWindowView,scene::{Drag, Frame, Scene, SceneInput, SlotContent, Theme},shell_work::{self, Action as ShellAction},diff --git a/apps/dock/src/gfx.rs b/apps/dock/src/gfx.rsindex 8438b89..9da4c5b 100644--- a/apps/dock/src/gfx.rs+++ b/apps/dock/src/gfx.rs@@ -65,6 +65,13 @@ const WHITE: D2D1_COLOR_F = D2D1_COLOR_F {a: 1.0,};+/// Shared font glyphs belong to drawing code, which is also used by the+/// standalone diagnostics without a menu bar or application lifecycle.+pub(crate) mod network_glyph {+ pub const WIFI: [char; 4] = ['\u{E872}', '\u{E873}', '\u{E874}', '\u{E701}'];+ pub const WIFI_FULL: char = '\u{E701}';+}+pub struct LabelBrush {pub brush: CompositionSurfaceBrush,pub width: f32,@@ -1020,11 +1027,9 @@ impl Gfx {// SAFETY: The brush, format and text live for each drawing call.unsafe {let ink_brush = dc.CreateSolidColorBrush(&ink.color(), None)?;- let wifi_glyph = crate::menubar::glyph::WIFI[usize::from(bars.clamp(1, 4)) - 1];- for &(glyph, opacity) in &[- (crate::menubar::glyph::WIFI_FULL, 0.3f32),- (wifi_glyph, 1.0f32),- ] {+ let wifi_glyph = network_glyph::WIFI[usize::from(bars.clamp(1, 4)) - 1];+ for &(glyph, opacity) in &[(network_glyph::WIFI_FULL, 0.3f32), (wifi_glyph, 1.0f32)]+ {let mut units = [0u16; 2];let text = glyph.encode_utf16(&mut units);ink_brush.SetOpacity(opacity);@@ -1045,8 +1050,14 @@ impl Gfx {let bar_top = height * 0.22;let bar_bottom = height * 0.58;dc.DrawLine(- Vector2 { X: ex_x, Y: bar_top },- Vector2 { X: ex_x, Y: bar_bottom },+ Vector2 {+ X: ex_x,+ Y: bar_top,+ },+ Vector2 {+ X: ex_x,+ Y: bar_bottom,+ },&warn_brush,stroke,None,diff --git a/apps/dock/src/menubar.rs b/apps/dock/src/menubar.rsindex 54bce5a..e0d5ebd 100644--- a/apps/dock/src/menubar.rs+++ b/apps/dock/src/menubar.rs@@ -127,8 +127,6 @@ static PANEL_BOTTOM: AtomicI32 = AtomicI32::new(0);static ISLAND_HOOK_WINDOW: AtomicIsize = AtomicIsize::new(0);/// Segoe Fluent Icons code points.pub(crate) mod glyph {- pub const WIFI: [char; 4] = ['\u{E872}', '\u{E873}', '\u{E874}', '\u{E701}'];- pub const WIFI_FULL: char = '\u{E701}';pub const ETHERNET: char = '\u{E839}';pub const OFFLINE: char = '\u{F384}';pub const VOLUME: [char; 4] = ['\u{E992}', '\u{E993}', '\u{E994}', '\u{E995}'];@@ -266,6 +264,7 @@ enum IslandAction {Toggle(Island),Media(MediaControl),Refresh,+ OpenCodeConnectionHelp,}struct IslandHit {@@ -803,6 +802,7 @@ fn draw_usage_row(} else {let message = match usage.state {State::Loading => text.usage_loading,+ State::SignIn if provider == Provider::OpenCode => text.usage_opencode_connect,State::SignIn => text.usage_sign_in,State::Ready | State::Unavailable => text.usage_unavailable,};@@ -1035,7 +1035,6 @@ impl MenuBar {self.widgets = widgets;self.refresh(gfx)}- }/// The pointer reached the top edge or left the bar.pub fn hover(&mut self, gfx: &Gfx, inside: bool) -> Result<()> {@@ -1432,6 +1431,14 @@ impl MenuBar {usage.refresh(true);}}+ IslandAction::OpenCodeConnectionHelp => {+ // Shell extensions and browser activation run in the+ // existing disposable worker, never on the bar's UI thread.+ crate::shell_work::dispatch(crate::shell_work::Action::Open {+ id: "https://opencode.ai/docs/console/go/".to_owned(),+ })+ .inspect_err(|_| crate::shell_work::notify_not_started())?;+ }IslandAction::Media(control) => {if let Some(media) = &self.media&& let Some(track) = self.look.as_ref().and_then(|look| look.track.as_ref())@@ -2040,6 +2047,39 @@ impl MenuBar {island_width,y,)?;+ if *provider == Provider::OpenCode && usage.state == State::SignIn {+ let label =+ gfx.text_brush_sized(title.usage_connection_help, scale, 11.0, true, ink)?;+ let (left, top) = (px(76.0), y + px(65.0));+ let (width, height) = (label.width + px(20.0), px(25.0));+ add_rounded_box(+ c,+ content,+ left,+ top,+ width,+ height,+ px(12.5),+ geometry.control_fill(),+ Some(geometry.border()),+ )?;+ add_visual(+ c,+ content,+ &label.brush.cast()?,+ left + px(10.0),+ top + (height - label.height) / 2.0,+ label.width,+ label.height,+ )?;+ self.island_hits.push(geometry.hit(+ left,+ top,+ width,+ height,+ IslandAction::OpenCodeConnectionHelp,+ ));+ }}let newest_age = providers.iter()@@ -2712,6 +2752,80 @@ impl Drop for MenuBar {mod island_tests {use super::*;+ #[test]+ #[ignore = "Requires Windows desktop composition; keeps the test bar hidden"]+ fn opencode_connection_help_is_clickable_and_inactive_codex_stays_hidden() -> Result<()> {+ use anyhow::Context;+ use windows::Win32::System::WinRT::{+ CreateDispatcherQueueController, DQTAT_COM_STA, DQTYPE_THREAD_CURRENT,+ DispatcherQueueOptions,+ };+ let _queue = unsafe {+ CreateDispatcherQueueController(DispatcherQueueOptions {+ dwSize: size_of::<DispatcherQueueOptions>() as u32,+ threadType: DQTYPE_THREAD_CURRENT,+ apartmentType: DQTAT_COM_STA,+ })?+ };+ let gfx = Gfx::new()?;+ let mut bar = MenuBar::create(&gfx, false, true, MenuBarWidgets::default())?;+ bar.set_visible(false)?;+ let mut look = bar.look.clone().context("missing initial look")?;+ look.track = None;+ look.panel = Some(Island::Usage);+ look.usage_enabled = true;+ look.active_providers = ActiveProviders::default();+ look.active_providers.0[Provider::OpenCode as usize] = true;+ look.usage.providers[Provider::OpenCode as usize] = ProviderUsage {+ state: State::SignIn,+ windows: Vec::new(),+ fetched_at: None,+ };+ // Yesterday's saved reading is not evidence that Codex is running now.+ look.usage.providers[Provider::Codex as usize] = ProviderUsage {+ state: State::Ready,+ windows: vec![usage::Window {+ label: None,+ minutes: 300,+ used_percent: 42,+ resets_at: None,+ }],+ fetched_at: Some(std::time::SystemTime::now() - Duration::from_secs(24 * 60 * 60)),+ };+ assert!(+ island_providers(&look)+ .iter()+ .all(|entry| entry.0 == Provider::OpenCode)+ );+ for scale in [1.0, 1.25, 1.5, 2.0] {+ for light in [false, true] {+ look.scale = scale;+ look.light = light;+ bar.build(&gfx, &look)?;+ let hit = bar+ .island_hits+ .iter()+ .find(|hit| matches!(hit.action, IslandAction::OpenCodeConnectionHelp))+ .context("OpenCode connection help has no click target")?;+ let (left, top, right, bottom) = hit.bounds;+ let first = bar+ .island_hits+ .iter()+ .find(|hit| hit.at((left + right) / 2.0, (top + bottom) / 2.0))+ .context("connection help cannot be clicked")?;+ assert!(matches!(first.action, IslandAction::OpenCodeConnectionHelp));+ }+ }+ look.usage.providers[Provider::OpenCode as usize].state = State::Ready;+ bar.build(&gfx, &look)?;+ assert!(+ !bar.island_hits+ .iter()+ .any(|hit| matches!(hit.action, IslandAction::OpenCodeConnectionHelp))+ );+ Ok(())+ }+#[test]#[ignore = "Requires Windows desktop composition; keeps the bar hidden"]fn accessory_opt_out_blocks_startup_resume_and_retry() -> Result<()> {@@ -2727,7 +2841,7 @@ mod island_tests {})?};let gfx = Gfx::new()?;- let mut bar = MenuBar::create(&gfx, false, true)?;+ let mut bar = MenuBar::create(&gfx, false, true, MenuBarWidgets::default())?;bar.set_visible(false)?;assert!(!bar.accessories_enabled && bar.accessories.is_none());bar.restart_accessories(&gfx)?;@@ -2801,7 +2915,7 @@ mod island_tests {})?};let gfx = Gfx::new()?;- let mut bar = MenuBar::create(&gfx, false, true)?;+ let mut bar = MenuBar::create(&gfx, false, true, MenuBarWidgets::default())?;bar.set_visible(false)?;bar.accessories = None;let mut look = bar.look.clone().context("missing initial menu bar")?;diff --git a/apps/dock/src/strings.rs b/apps/dock/src/strings.rsindex 7c07ce8..88326a3 100644--- a/apps/dock/src/strings.rs+++ b/apps/dock/src/strings.rs@@ -30,6 +30,8 @@ pub struct Strings {pub usage_refresh: &'static str,pub usage_refreshing: &'static str,pub usage_sign_in: &'static str,+ pub usage_opencode_connect: &'static str,+ pub usage_connection_help: &'static str,pub usage_unavailable: &'static str,pub usage_loading: &'static str,pub usage_stale: &'static str,@@ -71,7 +73,9 @@ const ES: Strings = Strings {usage_title: "Uso de IA",usage_refresh: "Actualizar",usage_refreshing: "Actualizando…",- usage_sign_in: "Inicia sesión",+ usage_sign_in: "Inicia sesión en el cliente",+ usage_opencode_connect: "En OpenCode: /connect → OpenCode Go",+ usage_connection_help: "Cómo conectar",usage_unavailable: "No disponible",usage_loading: "Cargando…",usage_stale: "Sin actualizar",@@ -110,7 +114,9 @@ const EN: Strings = Strings {usage_title: "AI usage",usage_refresh: "Refresh",usage_refreshing: "Refreshing…",- usage_sign_in: "Sign in",+ usage_sign_in: "Sign in to the client",+ usage_opencode_connect: "In OpenCode: /connect → OpenCode Go",+ usage_connection_help: "Connection guide",usage_unavailable: "Unavailable",usage_loading: "Loading…",usage_stale: "Not updated",@@ -149,7 +155,9 @@ const FR: Strings = Strings {usage_title: "Utilisation de l'IA",usage_refresh: "Actualiser",usage_refreshing: "Actualisation…",- usage_sign_in: "Se connecter",+ usage_sign_in: "Se connecter dans le client",+ usage_opencode_connect: "Dans OpenCode : /connect → OpenCode Go",+ usage_connection_help: "Comment connecter",usage_unavailable: "Indisponible",usage_loading: "Chargement…",usage_stale: "Non actualisé",diff --git a/apps/dock/src/usage.rs b/apps/dock/src/usage.rsindex 21b5cca..e2c43b8 100644--- a/apps/dock/src/usage.rs+++ b/apps/dock/src/usage.rs@@ -4,7 +4,7 @@ use std::{env, fs,io::{Read, Seek, SeekFrom},os::windows::process::CommandExt,- path::PathBuf,+ path::{Path, PathBuf},process::Command,sync::{Arc, Mutex,@@ -123,7 +123,7 @@ impl Provider {match self {Self::Claude => "Claude",Self::Codex => "Codex",- Self::OpenCode => "OpenCode",+ Self::OpenCode => "OpenCode Go",Self::Gemini => "Gemini",}}@@ -499,17 +499,11 @@ fn fetch_codex(client: &Client) -> ProviderUsage {}fn fetch_opencode(client: &Client) -> ProviderUsage {- let Some(path) = home().map(|path| path.join(".local/share/opencode/auth.json")) else {- return sign_in();- };- let token = env::var("OPENCODE_API_KEY").ok().or_else(|| {- let contents = fs::read(path).ok()?;- let auth: Value = serde_json::from_slice(&contents).ok()?;- auth.pointer("/opencode/key")- .and_then(Value::as_str)- .map(str::to_owned)- });- let Some(token) = token.filter(|token| !token.is_empty()) else {+ let api_key = env::var("OPENCODE_API_KEY").ok();+ let data_home = env::var_os("XDG_DATA_HOME").map(PathBuf::from);+ let home = home();+ let Some(token) = opencode_token(api_key.as_deref(), data_home.as_deref(), home.as_deref())+ else {return sign_in();};let Ok(response) = client@@ -520,7 +514,7 @@ fn fetch_opencode(client: &Client) -> ProviderUsage {else {return unavailable();};- if response.status().as_u16() == 401 {+ if matches!(response.status().as_u16(), 401 | 403) {return sign_in();}let Ok(body) = response@@ -540,6 +534,57 @@ fn fetch_opencode(client: &Client) -> ProviderUsage {}}+fn opencode_auth_path(data_home: Option<&Path>, home: Option<&Path>) -> Option<PathBuf> {+ // OpenCode follows XDG on native Windows too. An explicit data directory+ // is authoritative: never silently reuse a different account from HOME.+ let data = match data_home.filter(|path| !path.as_os_str().is_empty()) {+ Some(path) => {+ if !path.is_absolute() {+ return None;+ }+ path.to_path_buf()+ }+ None => home?.join(".local/share"),+ };+ Some(data.join("opencode/auth.json"))+}++fn opencode_key<'a>(api_key: Option<&'a str>, auth: Option<&'a Value>) -> Option<&'a str> {+ let usable = |key: &'a str| {+ let key = key.trim();+ (!key.is_empty()+ && key != "opencode-oauth-dummy-key"+ && !key+ .bytes()+ .any(|byte| byte.is_ascii_whitespace() || byte.is_ascii_control()))+ .then_some(key)+ };+ api_key.and_then(usable).or_else(|| {+ // Go has its own provider ID. Keep the legacy Zen API-key entry as a+ // fallback, but never forward another provider's OAuth or API secrets.+ ["opencode-go", "opencode"].into_iter().find_map(|id| {+ let entry = auth?.get(id)?;+ if entry.get("type")?.as_str()? != "api" {+ return None;+ }+ entry.get("key")?.as_str().and_then(usable)+ })+ })+}++fn opencode_token(+ api_key: Option<&str>,+ data_home: Option<&Path>,+ home: Option<&Path>,+) -> Option<String> {+ if let Some(key) = opencode_key(api_key, None) {+ return Some(key.to_owned());+ }+ let path = opencode_auth_path(data_home, home)?;+ let auth: Value = serde_json::from_slice(&fs::read(path).ok()?).ok()?;+ opencode_key(None, Some(&auth)).map(str::to_owned)+}+fn parse_opencode(value: &Value) -> Vec<Window> {let Some(usage) = value.get("usage") else {return Vec::new();@@ -1063,6 +1108,91 @@ mod tests {assert_eq!(windows[1].title(), "30 d");}+ #[test]+ fn opencode_go_credentials_take_precedence_over_legacy_zen() {+ let auth = json!({+ "opencode-go": {"type": "api", "key": "go-fixture"},+ "opencode": {"type": "api", "key": "zen-fixture"}+ });+ assert_eq!(opencode_key(None, Some(&auth)), Some("go-fixture"));+ assert_eq!(+ opencode_key(Some("explicit-fixture"), Some(&auth)),+ Some("explicit-fixture")+ );+ assert_eq!(opencode_key(Some(" "), Some(&auth)), Some("go-fixture"));+ }++ #[test]+ fn opencode_never_reuses_oauth_dummy_keys_or_another_providers_credentials() {+ let auth = json!({+ "opencode-go": {"type": "oauth", "key": "wrong-type", "access": "oauth-fixture"},+ "opencode": {"type": "api", "key": "opencode-oauth-dummy-key"},+ "openai": {"type": "api", "key": "unrelated-fixture"}+ });+ assert_eq!(opencode_key(None, Some(&auth)), None);+ assert_eq!(opencode_key(Some("invalid\r\nheader"), Some(&auth)), None);+ let legacy = json!({"opencode": {"type": "api", "key": " legacy-fixture "}});+ assert_eq!(opencode_key(None, Some(&legacy)), Some("legacy-fixture"));+ }++ #[test]+ fn opencode_reads_native_windows_xdg_storage_without_changing_environment() -> anyhow::Result<()>+ {+ let root = env::temp_dir().join(format!(+ "muelle-opencode-auth-{}-{}",+ std::process::id(),+ SystemTime::now().duration_since(UNIX_EPOCH)?.as_nanos()+ ));+ // This test owns only this newly created temporary directory.+ fs::create_dir(&root)?;+ let result = (|| -> anyhow::Result<()> {+ let data = root.join("custom-data");+ let home = root.join("home");+ let path = opencode_auth_path(Some(&data), Some(&home))+ .ok_or_else(|| anyhow::anyhow!("missing fixture path"))?;+ fs::create_dir_all(+ path.parent()+ .ok_or_else(|| anyhow::anyhow!("missing fixture parent"))?,+ )?;+ let original = br#"{"opencode-go":{"type":"api","key":"saved-go-fixture"}}"#;+ fs::write(&path, original)?;+ assert_eq!(+ opencode_token(None, Some(&data), Some(&home)).as_deref(),+ Some("saved-go-fixture")+ );+ assert_eq!(fs::read(&path)?, original);+ let default_path = home.join(".local/share/opencode/auth.json");+ assert_eq!(+ opencode_auth_path(None, Some(&home)),+ Some(default_path.clone())+ );+ fs::create_dir_all(+ default_path+ .parent()+ .ok_or_else(|| anyhow::anyhow!("missing default parent"))?,+ )?;+ fs::write(+ &default_path,+ br#"{"opencode":{"type":"api","key":"other-account-fixture"}}"#,+ )?;+ assert_eq!(+ opencode_token(None, None, Some(&home)).as_deref(),+ Some("other-account-fixture")+ );+ // A missing explicit account must not fall back to another directory.+ assert!(opencode_token(None, Some(&root.join("missing")), Some(&home)).is_none());+ assert!(opencode_auth_path(Some(Path::new("relative-store")), Some(&home)).is_none());+ // An explicitly configured environment key works without HOME.+ assert_eq!(+ opencode_token(Some("env-fixture"), None, None).as_deref(),+ Some("env-fixture")+ );+ Ok(())+ })();+ fs::remove_dir_all(&root)?;+ result+ }+#[test]fn antigravity_only_reports_measured_gemini_buckets() {let windows = parse_antigravity(&json!({"response": {"groups": [