Skip to content

Commit

Permalink
Update to objc2 0.6.0 family (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Feb 1, 2025
1 parent b35fceb commit 07e1821
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ web-time = "1"
clipboard-win = "3.1.1"

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.5.2"
objc2-foundation = "0.2.2"
objc2-app-kit = "0.2.2"
objc2 = { version = "0.6.0", default-features = false }
objc2-foundation = { version = "0.3.0", default-features = false }
objc2-app-kit = { version = "0.3.0", default-features = false, features = ["NSApplication", "NSResponder"] }

[features]
default = ["editor", "default-image-formats", "vger"]
Expand Down
31 changes: 16 additions & 15 deletions src/app_delegate.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, ProtocolObject};
use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass};
use objc2::{define_class, msg_send, MainThreadMarker, MainThreadOnly};
use objc2_app_kit::{NSApplication, NSApplicationDelegate};
use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
use objc2_foundation::{NSObject, NSObjectProtocol};

use crate::app::UserEvent;

declare_class!(
define_class!(
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[name = "MyAppDelegate"]
struct AppDelegate;

unsafe impl ClassType for AppDelegate {
type Super = NSObject;
type Mutability = mutability::MainThreadOnly;
const NAME: &'static str = "MyAppDelegate";
}

impl DeclaredClass for AppDelegate {}

unsafe impl NSObjectProtocol for AppDelegate {}

unsafe impl NSApplicationDelegate for AppDelegate {
#[method(applicationShouldHandleReopen:hasVisibleWindows:)]
fn should_handle_reopen(&self, _sender: &Option<&AnyObject>, has_visible_windows: bool) -> bool {
crate::Application::send_proxy_event(UserEvent::Reopen { has_visible_windows });
#[unsafe(method(applicationShouldHandleReopen:hasVisibleWindows:))]
fn should_handle_reopen(
&self,
_sender: &Option<&AnyObject>,
has_visible_windows: bool,
) -> bool {
crate::Application::send_proxy_event(UserEvent::Reopen {
has_visible_windows,
});
// return true to preserve the default behavior, such as showing the minimized window.
true
}
Expand All @@ -31,7 +32,7 @@ declare_class!(

impl AppDelegate {
fn new(mtm: MainThreadMarker) -> Retained<Self> {
unsafe { msg_send_id![super(mtm.alloc().set_ivars(())), init] }
unsafe { msg_send![super(mtm.alloc().set_ivars(())), init] }
}
}

Expand Down

0 comments on commit 07e1821

Please sign in to comment.