Skip to content

Commit

Permalink
Update to objc2 0.6.0 family
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Jan 28, 2025
1 parent b35fceb commit 01af0a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 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
21 changes: 8 additions & 13 deletions src/app_delegate.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
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:)]
#[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.
Expand All @@ -31,7 +26,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 01af0a7

Please sign in to comment.