libnyanpasu/clash-nyanpasu · warning · anyhow::Error
failed to get miniaturize button
Error message
failed to get miniaturize button
What it means
Same traffic-light repositioning path as the close button, but for the miniaturize button: NSWindow.standardWindowButton(.miniaturizeButton) returned nil. The code needs all three buttons to compute the title-bar container, so it aborts with this error.
Source
Thrown at backend/tauri/src/window.rs:916
impl From<Position> for (f64, f64) {
fn from(value: Position) -> Self {
(value.x, value.y)
}
}
fn set_traffic_lights_pos(
window: objc2::rc::Retained<objc2_app_kit::NSWindow>,
pos: Position,
) -> anyhow::Result<()> {
use objc2_app_kit::NSWindowButton;
use objc2_foundation::NSRect;
let close = window
.standardWindowButton(NSWindowButton::CloseButton)
.ok_or(anyhow::anyhow!("failed to get close button"))?;
let miniaturize = window
.standardWindowButton(NSWindowButton::MiniaturizeButton)
.ok_or(anyhow::anyhow!("failed to get miniaturize button"))?;
let zoom = window
.standardWindowButton(NSWindowButton::ZoomButton)
.ok_or(anyhow::anyhow!("failed to get zoom button"))?;
let title_bar_container_view = unsafe {
close
.superview()
.and_then(|view| view.superview())
.ok_or(anyhow::anyhow!("failed to get title bar container view"))?
};
let close_rect = close.frame();
let button_height = close_rect.size.height;
let title_bar_frame_height = button_height + pos.y;
let mut title_bar_rect = title_bar_container_view.frame();
title_bar_rect.size.height = title_bar_frame_height;
title_bar_rect.origin.y = window.frame().size.height - title_bar_frame_height;View on GitHub (pinned to f7dbce2997)
Solutions
- Ensure the window style mask includes .miniaturizable (Tauri: default decorations, not decorations:false)
- Call set_traffic_lights_pos after the window is shown and retry if buttons are not yet available
- Degrade gracefully: if any button is nil, skip repositioning with a warning rather than erroring
- Verify with Objective-C that buttons exist: [window standardWindowButton:] before applying offsets
Example fix
// before
let miniaturize = window
.standardWindowButton(NSWindowButton::MiniaturizeButton)
.ok_or(anyhow::anyhow!("failed to get miniaturize button"))?;
// after
let Some(miniaturize) = window.standardWindowButton(NSWindowButton::MiniaturizeButton) else {
log::warn!("miniaturize button unavailable; skipping traffic light reposition");
return Ok(());
}; Defensive patterns
Strategy: fallback
Validate before calling
if window.standardWindowButton(NSWindowButton::MiniaturizeButton).is_none() {
return Ok(()); // window lacks miniaturize; skip repositioning
} Type guard
fn has_miniaturize(window: &NSWindow) -> bool {
window.standardWindowButton(NSWindowButton::MiniaturizeButton).is_some()
} Try / catch
match apply_traffic_lights_pos(window, pos) {
Err(e) => log::warn!("traffic light reposition skipped: {e}"),
Ok(()) => {}
} Prevention
- Keep .miniaturizable in the window style mask when repositioning traffic lights
- Invoke after window shown; AppKit creates buttons lazily
- Design set_traffic_lights_pos to degrade to partial repositioning
When it happens
Trigger: set_traffic_lights_pos called on a window whose style mask lacks .miniaturizable, an undecorated/borderless Tauri window, or before the window is visible so AppKit hasn't created the buttons.
Common situations: Windows created with decorations:false; style masks customized to remove the minimize button; calling the API during window setup before performDrag/appearance; dialogs/utility windows with restricted button sets.
Related errors
- failed to get close button
- failed to get miniaturize button
- failed to get zoom button
- failed to get close button
- failed to get zoom button
AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08).
Data as JSON: /api/errors/493414fba0c10be4.
Report an issue: GitHub.