//! Traits that an implementing application can conform to. These aim to wrap the general
//! lifecycles across macOS/iOS/etc, while still conforming to a Rust-ish approach.
use url::Url;
use crate::app::enums::TerminateResponse;
use crate::error::AppKitError;
use crate::menu::Menu;
use crate::printing::enums::PrintResponse;
use crate::printing::settings::PrintSettings;
use crate::user_activity::UserActivity;
#[cfg(feature = "cloudkit")]
use crate::cloudkit::share::CKShareMetaData;
/// Controllers interested in processing messages can implement this to respond to messages as
/// they're dispatched. All messages come in on the main thread.
pub trait Dispatcher {
type Message: Send + Sync;
fn on_message(&self, _message: Self::Message) {}
}
/// `AppDelegate` is more or less `NSAppDelegate` from the Objective-C/Swift side, just named
/// differently to fit in with the general naming scheme found within this framework. You can
/// implement methods from this trait in order to respond to lifecycle events that the system will
/// fire off.
pub trait AppDelegate {
/// Called right before the application will finish launching. You really, probably, want to do
/// your setup in `did_finish_launching` unless you're sure of what you're doing.
fn will_finish_launching(&self) {}
/// Fired when the application has finished launching. Unlike most other "load" lifecycle
/// events in this framework, you don't get a reference to an app here - if you need to call
/// through to your shared application, then used the `App::shared()` call.
fn did_finish_launching(&self) {}
/// Fired immediately before the application is about to become active.
fn will_become_active(&self) {}
/// Fired when the application is about to become active.
fn did_become_active(&self) {}
/// Fired when the application is about to resign active state.
fn will_resign_active(&self) {}
/// Fired when the application has resigned active state.
fn did_resign_active(&self) {}
/// Fired when the application is about to hide.
fn will_hide(&self) {}
/// Fired after the application has hidden.
fn did_hide(&self) {}
/// Fired when the application is about to unhide itself.
fn will_unhide(&self) {}
/// Fired after the application has unhidden itself.
fn did_unhide(&self) {}
/// Fired immediately before the application object updates its windows.
fn will_update(&self) {}
/// Fired immediately after the application object updates its windows.
fn did_update(&self) {}
/// This is fired after the `Quit` menu item has been selected, or after you've called `App::terminate()`.
///
/// In most cases you just want `TerminateResponse::Now` here, which enables business as usual. If you need,
/// though, you can cancel the termination via `TerminateResponse::Cancel` to continue something essential. If
/// you do this, you'll need to be sure to call `App::reply_to_termination_request()` to circle
/// back.
fn should_terminate(&self) -> TerminateResponse { TerminateResponse::Now }
/// Fired before the application terminates. You can use this to do any required cleanup.
fn will_terminate(&self) {}
/// Sent by the application to the delegate prior to default behavior to reopen AppleEvents.
///
/// `has_visible_windows` indicates whether the Application object found any visible windows in your application.
/// You can use this value as an indication of whether the application would do anything if you return `true`.
///
/// Return `true` if you want the application to perform its normal tasks, or `false` if you want the
/// application to do nothing. The default implementation of this method returns `true`.
///
/// Some finer points of discussion, from Apple documentation:
///
/// These events are sent whenever the Finder reactivates an already running application because someone
/// double-clicked it again or used the dock to activate it.
///
/// For most document-based applications, an untitled document will be created.
///
/// [Read more
/// here](https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428638-applicationshouldhandlereopen?language=objc)
fn should_handle_reopen(&self, _has_visible_windows: bool) -> bool { true }
/// Supply a dock menu for the application dynamically. The default implementation for this
/// method returns `None`, for no menu.
fn dock_menu(&self) -> Option