From 5eb2124e706b57f236a42503d530f9671cd0a2cf Mon Sep 17 00:00:00 2001 From: Harry Mallon Date: Tue, 28 Nov 2023 12:13:32 +0000 Subject: [PATCH] fix(macos): Enable applicationSupportsSecureRestorableState = YES (#852) --- .changes/macos-secure-coding.md | 6 ++++++ src/platform_impl/macos/app_delegate.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changes/macos-secure-coding.md diff --git a/.changes/macos-secure-coding.md b/.changes/macos-secure-coding.md new file mode 100644 index 00000000..272b2e31 --- /dev/null +++ b/.changes/macos-secure-coding.md @@ -0,0 +1,6 @@ +--- +"tao": patch +--- + +Enable macOS secure state restoration on OS versions that support it. This avoids +'WARNING: Secure coding is not enabled for restorable state!' on macOS Sonoma. diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 8cb6c009..6beea942 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -8,7 +8,7 @@ use cocoa::base::id; use cocoa::foundation::NSString; use objc::{ declare::ClassDecl, - runtime::{Class, Object, Sel}, + runtime::{Class, Object, Sel, BOOL}, }; use std::{ cell::{RefCell, RefMut}, @@ -54,6 +54,10 @@ lazy_static! { sel!(application:openURLs:), application_open_urls as extern "C" fn(&Object, Sel, id, id), ); + decl.add_method( + sel!(applicationSupportsSecureRestorableState:), + application_supports_secure_restorable_state as extern "C" fn(&Object, Sel, id) -> BOOL, + ); decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME); AppDelegateClass(decl.register()) @@ -120,3 +124,9 @@ extern "C" fn application_open_urls(_: &Object, _: Sel, _: id, urls: id) -> () { AppState::open_urls(urls); trace!("Completed `application:openURLs:`"); } + +extern "C" fn application_supports_secure_restorable_state(_: &Object, _: Sel, _: id) -> BOOL { + trace!("Triggered `applicationSupportsSecureRestorableState`"); + trace!("Completed `applicationSupportsSecureRestorableState`"); + objc::runtime::YES +}