From 2525cbfee4d38a1bcfa06b98ac723c8426088d45 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 12 Oct 2022 14:32:23 -0400 Subject: [PATCH] Update webview implementation to use load_or_register_class (Issue #63) --- src/webview/class.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/webview/class.rs b/src/webview/class.rs index 920002c..e6da759 100644 --- a/src/webview/class.rs +++ b/src/webview/class.rs @@ -12,7 +12,7 @@ use objc::declare::ClassDecl; use objc::runtime::{Class, Object, Sel}; use objc::{class, msg_send, sel, sel_impl}; -use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES, load_or_register_class}; use crate::webview::actions::{NavigationAction, NavigationResponse}; use crate::webview::{mimetype::MimeType, WebViewDelegate, WEBVIEW_DELEGATE_PTR}; //, OpenPanelParameters}; //use crate::webview::enums::{NavigationPolicy, NavigationResponsePolicy}; @@ -186,13 +186,7 @@ pub fn register_webview_class() -> *const Class { /// both a subclass of `NSViewController` and a delegate of the held `WKWebView` (for the various /// varieties of delegates needed there). pub fn register_webview_delegate_class() -> *const Class { - static mut VIEW_CLASS: *const Class = 0 as *const Class; - static INIT: Once = Once::new(); - - INIT.call_once(|| unsafe { - let superclass = class!(NSObject); - let mut decl = ClassDecl::new("RSTWebViewDelegate", superclass).unwrap(); - + load_or_register_class("NSObject", "RSTWebViewDelegate", |decl| unsafe { decl.add_ivar::(WEBVIEW_DELEGATE_PTR); // WKNavigationDelegate @@ -239,9 +233,5 @@ pub fn register_webview_delegate_class() -> *const Class { sel!(_download:decideDestinationWithSuggestedFilename:completionHandler:), handle_download:: as extern "C" fn(&Object, _, id, id, usize) ); - - VIEW_CLASS = decl.register(); - }); - - unsafe { VIEW_CLASS } + }) }