libnyanpasu/clash-nyanpasu · warning

failed to set traffic lights pos

Error message

failed to set traffic lights pos

What it means

Inside `apply_traffic_lights_pos`, the helper `set_traffic_lights_pos` (which manipulates the NSWindow's standard window buttons via objc calls) has its Result discarded with this expect. The panic means the AppKit manipulation failed — the standard window buttons (close/minimize/zoom) were absent or the objc message returned an error. This is a cosmetic macOS customization failing hard instead of degrading.

Source

Thrown at backend/tauri/src/window.rs:976

    impl WindowState {
        fn new(window: WebviewWindow<tauri::Wry>, traffic_lights_pos: Position) -> Self {
            Self {
                window,
                traffic_lights_pos,
            }
        }

        fn with_ns_window<T>(&self, func: impl FnOnce(Retained<NSWindow>) -> T) -> T {
            let ns_window = self.window.ns_window().expect("window not found");
            let ns_window = unsafe { Retained::retain_autoreleased(ns_window as *mut NSWindow) }
                .expect("failed to retain window");
            func(ns_window)
        }

        fn apply_traffic_lights_pos(&self) {
            self.with_ns_window(|win| {
                set_traffic_lights_pos(win, self.traffic_lights_pos)
                    .expect("failed to set traffic lights pos");
            });
        }
    }

    #[derive(Debug)]
    struct TrafficLightsWindowDelegateIvars {
        app_box: WindowState,
        super_class: Retained<ProtocolObject<dyn NSWindowDelegate>>,
    }

    const WINDOW_DID_ENTER_FULL_SCREEN: &str = "internal:://window-did-enter-full-screen";
    const WINDOW_WILL_ENTER_FULL_SCREEN: &str = "internal:://window-will-enter-full-screen";
    const WINDOW_WILL_EXIT_FULL_SCREEN: &str = "internal:://window-will-exit-full-screen";
    const WINDOW_DID_EXIT_FULL_SCREEN: &str = "internal:://window-did-exit-full-screen";

    define_class! {
        #[unsafe(super(NSObject))]
        #[name = "TrafficLightsPosWindowDelegate"]

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Retry the positioning after a short main-thread dispatch or on the window's `did-resize`/`did-become-visible` event when buttons exist.
  2. Return/log the error instead of expecting so a cosmetic failure never crashes the app: `let _ = set_traffic_lights_pos(win, pos);` with a warn log.
  3. Check the window's titlebar style configuration — positions cannot be applied when standard buttons are hidden.
  4. Verify the saved `traffic_lights_pos` values are sane offsets; clamp before applying.

Example fix

// before
set_traffic_lights_pos(win, self.traffic_lights_pos)
    .expect("failed to set traffic lights pos");
// after
if let Err(e) = set_traffic_lights_pos(win, self.traffic_lights_pos) {
    tracing::warn!("failed to set traffic lights pos: {e}");
}
Defensive patterns

Strategy: fallback

Validate before calling

// ensure standard buttons exist before positioning
if win.standardWindowButton(NSWindowButton::CloseButton).is_none() {
    tracing::warn!("standard buttons missing; skip traffic light pos");
}

Try / catch

if let Err(e) = set_traffic_lights_pos(win, self.traffic_lights_pos) {
    tracing::warn!("failed to set traffic lights pos: {e}");
}

Prevention

When it happens

Trigger: Calling `apply_traffic_lights_pos` on a window whose titlebar buttons were not created (custom titlebar styles, fullscreen transitions, window mid-close), or `set_traffic_lights_pos` returning Err from a failed objc2 method call.

Common situations: Applying saved traffic-light positions at startup before AppKit finishes building buttons; toggling `titleBarStyle`/`hiddenTitle` at runtime; fullscreen enter/exit invalidating the button handles; restored windows on macOS during state restoration.

Related errors


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/c7524b69d6bc597c. Report an issue: GitHub.