Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to objc2 0.6.0 family #749

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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