{"record":{"id":"06303f2be5df2f5d","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-title-bar-container-view-06303f","errorCode":null,"errorMessage":"failed to get title bar container view","messagePattern":"failed to get title bar container view","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"backend/tauri/src/window.rs","lineNumber":925,"sourceCode":"        pos: Position,\n    ) -> anyhow::Result<()> {\n        use objc2_app_kit::NSWindowButton;\n        use objc2_foundation::NSRect;\n        let close = window\n            .standardWindowButton(NSWindowButton::CloseButton)\n            .ok_or(anyhow::anyhow!(\"failed to get close button\"))?;\n        let miniaturize = window\n            .standardWindowButton(NSWindowButton::MiniaturizeButton)\n            .ok_or(anyhow::anyhow!(\"failed to get miniaturize button\"))?;\n        let zoom = window\n            .standardWindowButton(NSWindowButton::ZoomButton)\n            .ok_or(anyhow::anyhow!(\"failed to get zoom button\"))?;\n\n        let title_bar_container_view = unsafe {\n            close\n                .superview()\n                .and_then(|view| view.superview())\n                .ok_or(anyhow::anyhow!(\"failed to get title bar container view\"))?\n        };\n\n        let close_rect = close.frame();\n        let button_height = close_rect.size.height;\n\n        let title_bar_frame_height = button_height + pos.y;\n        let mut title_bar_rect = title_bar_container_view.frame();\n        title_bar_rect.size.height = title_bar_frame_height;\n        title_bar_rect.origin.y = window.frame().size.height - title_bar_frame_height;\n        unsafe {\n            title_bar_container_view.setFrame(title_bar_rect);\n        }\n\n        let space_between = miniaturize.frame().origin.x - close.frame().origin.x;\n        let window_buttons = vec![close, miniaturize, zoom];\n\n        for (i, button) in window_buttons.into_iter().enumerate() {\n            let mut rect: NSRect = button.frame();","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/window.rs#L907-L943","documentation":"After obtaining the close button, set_traffic_lights_pos navigates two superview levels up to reach AppKit's private title bar container view (NSTitlebarContainerView). If either superview is nil, the code fails with this error. The title bar container is an undocumented view hierarchy detail, so this breaks when AppKit changes the hierarchy or the window is styled differently.","triggerScenarios":"set_traffic_lights_pos called on a window whose close button has no two-level superview chain — undecorated/overlay title bars, macOS versions where NSTitlebarContainerView is absent (no titlebar), or bridged views from a non-standard window setup.","commonSituations":"macOS version upgrades changing the private view hierarchy; Tauri titleBarStyle overlay windows; windows in fullscreen where the titlebar container is detached; very new macOS releases where the private class layout differs.","solutions":["Walk the superview chain searching for the NSTitlebarContainerView class instead of assuming a fixed two-level depth","Guard with respondsToSelector/class checks and skip repositioning gracefully on hierarchy mismatch","Pin behavior per macOS version and test on each supported release after upgrades","If the hierarchy lookup fails, fall back to not adjusting traffic lights (log a warning)"],"exampleFix":"// before\nlet title_bar_container_view = unsafe {\n    close.superview().and_then(|view| view.superview())\n        .ok_or(anyhow::anyhow!(\"failed to get title bar container view\"))?\n};\n// after\nlet title_bar_container_view = unsafe {\n    let mut v = close.superview();\n    while let Some(view) = v {\n        if view.is_kind_of::<objc2_app_kit::NSTitlebarContainerView>() { break; }\n        v = view.superview();\n    }\n    v.ok_or_else(|| anyhow::anyhow!(\"NSTitlebarContainerView not found in superview chain\"))?\n};","handlingStrategy":"try-catch","validationCode":"// verify the expected superview depth before casting\nlet container = close.superview().and_then(|v| v.superview());\nif container.is_none() {\n    return Ok(()); // hierarchy not as expected\n}","typeGuard":"fn is_titlebar_container(view: &objc2_runtime::AnyObject) -> bool {\n    unsafe { view.is_kind_of::<objc2_app_kit::NSTitlebarContainerView>() }\n}","tryCatchPattern":"if let Err(e) = set_traffic_lights_pos(window, pos) {\n    log::warn!(\"traffic light positioning unavailable (AppKit hierarchy changed?): {e}\");\n}","preventionTips":["Search the superview chain by class rather than fixed depth — AppKit may change the hierarchy","Re-test private-view navigation after every macOS upgrade","Treat title-bar container manipulation as best-effort; never fail window creation on it"],"tags":["macos","appkit","private-api"],"backgroundTag":"appkit-view-hierarchy-mismatch","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}