diff --git a/.changes/set-theme-none-macos-crash.md b/.changes/set-theme-none-macos-crash.md new file mode 100644 index 000000000..86c983123 --- /dev/null +++ b/.changes/set-theme-none-macos-crash.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Fix setting theme to `None` crashes the app on macOS diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 6ac3ab4c0..da57bb6ce 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -345,15 +345,15 @@ pub(super) fn set_ns_theme(theme: Option) { let app: id = msg_send![app_class, sharedApplication]; let has_theme: BOOL = msg_send![app, respondsToSelector: sel!(effectiveAppearance)]; if has_theme == YES { - let name = if let Some(theme) = theme { - NSString::alloc(nil).init_str(match theme { + let appearance = if let Some(theme) = theme { + let name = NSString::alloc(nil).init_str(match theme { Theme::Dark => "NSAppearanceNameDarkAqua", Theme::Light => "NSAppearanceNameAqua", - }) + }); + msg_send![class!(NSAppearance), appearanceNamed: name] } else { nil }; - let appearance: id = msg_send![class!(NSAppearance), appearanceNamed: name]; let _: () = msg_send![app, setAppearance: appearance]; } }