Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(tray): "Plan & Credits…" keeps its ampersand; lines fresh before the click (T2)

purplea17ca7fb3dfa
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 7dd5c004..fc32e903 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1460,10 +1460,10 @@ pub fn run() {
tauri::tray::TrayIconEvent::DoubleClick { .. } => {
onboarding_window::bring_to_front(tray.app_handle());
}
- // Fresh lines for the menu that is about to open
- // (or already is: they change in place). Enter
- // comes first on a Mac and Windows, so most of the
- // time the menu opens with them already there.
+ // Fresh lines for the menu that is about to open.
+ // Enter (the pointer reaching the icon) comes
+ // before the click; an open Mac menu does not
+ // change any more (tray_menu.rs).
tauri::tray::TrayIconEvent::Click { .. } | tauri::tray::TrayIconEvent::Enter { .. } => {
let _ = tray.app_handle().emit(tray_menu::OPENED_EVENT, ());
}
diff --git a/src-tauri/src/tray_menu.rs b/src-tauri/src/tray_menu.rs
index abb9be5c..b297b395 100644
--- a/src-tauri/src/tray_menu.rs
+++ b/src-tauri/src/tray_menu.rs
@@ -14,14 +14,17 @@
// engine and the model, so it sends the lines (`tray_update`); this side
// only checks and lays them out. The action is one of two fixed actions with
// labels from here, so a page can change what the menu says but never what
-// a click does. A click on the icon emits `lu-tray-opened`, and the frontend
-// answers with fresh lines; texts change in place, so a menu that is
-// already open on a Mac updates while it is open.
+// a click does. Hovering or clicking the icon emits `lu-tray-opened`, and
+// the frontend answers with fresh lines; it also refreshes on its own timer.
//
-// Only a different number of grey lines builds a new menu, and a new menu
-// closes one that is open (seen in the Mac test build, 31.10.). So the action
-// is one item whose label changes, and the page keeps the line count steady
-// (three lines in every state once the memory figure is in).
+// An open menu does NOT change on a Mac (test build, 31.10.): while it is
+// open, AppKit's menu loop holds the main thread, and the update lands when
+// the menu has closed. So the lines have to be fresh before the click, which
+// is what the hover and the timer are for.
+//
+// Texts, dots and the action's label change in place; only a different
+// number of grey lines builds a new menu. The page keeps that number at
+// three, so the menu is built once and then only relabelled.
use serde::Deserialize;
@@ -62,7 +65,9 @@ pub(crate) enum TrayAction {
impl TrayAction {
pub(crate) fn label(self) -> &'static str {
match self {
- TrayAction::Plan => "Plan & Credits…",
+ // `&&`: a single `&` marks a keyboard mnemonic in a native menu
+ // and disappears ("Plan Credits…" in the first Mac build).
+ TrayAction::Plan => "Plan && Credits…",
TrayAction::Models => "Models…",
}
}
@@ -91,17 +96,21 @@ pub(crate) struct TrayStatus {
}
/// One line as the menu shows it: no control characters (a newline would
-/// break a native menu item), no padding, cut to `MAX_LINE_CHARS`.
+/// break a native menu item), no padding, cut to `MAX_LINE_CHARS`, and every
+/// `&` doubled, because a single one is a mnemonic marker to the native menu
+/// and would vanish from a model name like "R&D-7B".
pub(crate) fn clean_line(text: &str) -> String {
let flat: String = text.chars().map(|c| if c.is_control() { ' ' } else { c }).collect();
let flat = flat.split_whitespace().collect::<Vec<_>>().join(" ");
- if flat.chars().count() <= MAX_LINE_CHARS {
- return flat;
- }
- let mut cut: String = flat.chars().take(MAX_LINE_CHARS - 1).collect();
- cut.truncate(cut.trim_end().len());
- cut.push('…');
- cut
+ let cut = if flat.chars().count() <= MAX_LINE_CHARS {
+ flat
+ } else {
+ let mut cut: String = flat.chars().take(MAX_LINE_CHARS - 1).collect();
+ cut.truncate(cut.trim_end().len());
+ cut.push('…');
+ cut
+ };
+ cut.replace('&', "&&")
}
/// What the frontend sent, made safe to show: empty lines dropped, at most
@@ -404,6 +413,11 @@ mod tests {
assert_eq!(clean_line("Qwen3\n8B\t· ready\r"), "Qwen3 8B · ready");
}
+ #[test]
+ fn an_ampersand_survives_the_native_menu() {
+ assert_eq!(clean_line("R&D-7B · ready"), "R&&D-7B · ready");
+ }
+
#[test]
fn a_long_model_name_is_cut_with_an_ellipsis() {
let long = "Llama-3.3-70B-Instruct-abliterated-Q4_K_M-imatrix-final.gguf · ready";
@@ -419,7 +433,7 @@ mod tests {
assert!(serde_json::from_str::<TrayStatus>(r#"{"action":"delete-everything"}"#).is_err());
let s: TrayStatus = serde_json::from_str(r#"{"lines":[{"text":"x","dot":"green"}],"action":"models"}"#).unwrap();
assert_eq!(s.action, Some(TrayAction::Models));
- assert_eq!(TrayAction::Plan.label(), "Plan & Credits…");
+ assert_eq!(TrayAction::Plan.label(), "Plan && Credits…", "a single & would vanish");
assert_eq!(TrayAction::Models.event_name(), "models");
}
diff --git a/src/hooks/__tests__/tray-sync.test.ts b/src/hooks/__tests__/tray-sync.test.ts
index 6e9fd6d6..2b2aa2e0 100644
--- a/src/hooks/__tests__/tray-sync.test.ts
+++ b/src/hooks/__tests__/tray-sync.test.ts
@@ -28,7 +28,11 @@ vi.mock('../../api/ollama', async (orig) => ({
}),
}))
-import { currentTrayStatus, openTrayAction, probeModelState, trayEngineName } from '../useTraySync'
+vi.mock('../../api/in-tauri', () => ({ isTauri: () => true }))
+vi.mock('@tauri-apps/api/event', () => ({ listen: vi.fn(async () => () => {}) }))
+
+import { renderHook } from '@testing-library/react'
+import { currentTrayStatus, openTrayAction, probeModelState, trayEngineName, useTraySync } from '../useTraySync'
import { useCloudAuthStore } from '../../stores/cloudAuthStore'
import { useModelStore } from '../../stores/modelStore'
import { useSettingsStore } from '../../stores/settingsStore'
@@ -126,4 +130,22 @@ describe('tray sync (T2)', () => {
openTrayAction('delete')
expect(useUIStore.getState().currentView).toBe('chat')
})
+
+ it('local lines are measured again every 15 s, so a click finds them fresh', async () => {
+ vi.useFakeTimers()
+ try {
+ const { unmount } = renderHook(() => useTraySync())
+ await vi.advanceTimersByTimeAsync(1_000)
+ const before = calls.filter((c) => c.cmd === 'tray_memory').length
+ await vi.advanceTimersByTimeAsync(15_000)
+ expect(calls.filter((c) => c.cmd === 'tray_memory').length).toBeGreaterThan(before)
+ // and nothing more once the app is gone
+ unmount()
+ const after = calls.length
+ await vi.advanceTimersByTimeAsync(60_000)
+ expect(calls.length).toBe(after)
+ } finally {
+ vi.useRealTimers()
+ }
+ })
})
diff --git a/src/hooks/useTraySync.ts b/src/hooks/useTraySync.ts
index abc9d7e3..ee4f3b02 100644
--- a/src/hooks/useTraySync.ts
+++ b/src/hooks/useTraySync.ts
@@ -1,9 +1,10 @@
// Keeps the tray menu's grey lines current (T2, 3.0.9; lines: lib/tray-menu).
//
// Sent on every change of mode, account or selected model, and again when the
-// tray icon is clicked or hovered (`lu-tray-opened`): then the engine, Ollama
-// and the memory are asked fresh, and the account at most once a minute. A
-// menu that is already open on a Mac takes the new texts in place.
+// tray icon is hovered or clicked (`lu-tray-opened`) and every 15 seconds:
+// then the engine, Ollama and the memory are asked fresh, and the account at
+// most once a minute. The lines must be fresh BEFORE the click: an open menu
+// on a Mac does not change (tray_menu.rs).
// `lu-tray-action` is the click on "Plan & Credits…" or "Models…"; the window
// is already in front by then (tray_menu.rs).
@@ -36,6 +37,9 @@ const ACTION_EVENT = 'lu-tray-action'
/** Hovering the icon on the way to somewhere else must not hammer anything. */
const LOCAL_REFRESH_MS = 3_000
const ACCOUNT_REFRESH_MS = 60_000
+/** The timer that keeps the local lines fresh without a hover. Asks the
+ * engine status, Ollama's /api/ps and the memory: all local and cheap. */
+const BACKGROUND_REFRESH_MS = 15_000
type Memory = TrayLocalInput['memory']
interface LocalProbe {
@@ -161,6 +165,10 @@ export function useTraySync(): void {
if (s.activeModel !== prev.activeModel) void refresh()
}))
void refresh().then(sync)
+ const timer = setInterval(() => {
+ if (useSettingsStore.getState().settings.appMode !== 'cloud') void refresh()
+ }, BACKGROUND_REFRESH_MS)
+ offs.push(() => clearInterval(timer))
void import('@tauri-apps/api/event').then(async ({ listen }) => {
const offOpened = await listen(OPENED_EVENT, () => { void refresh() })
const offAction = await listen(ACTION_EVENT, (e) => openTrayAction(e.payload))