CloudKit feature gate, move wrapper over to the module
This commit is contained in:
parent
79bb456b93
commit
66ffd83db0
|
@ -19,5 +19,6 @@ uuid = { version = "0.8", features = ["v4"] }
|
||||||
url = "2.1.1"
|
url = "2.1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
cloudkit = []
|
||||||
user-notifications = []
|
user-notifications = []
|
||||||
enable-webview-downloading = []
|
enable-webview-downloading = []
|
||||||
|
|
|
@ -8,6 +8,9 @@ fn main() {
|
||||||
println!("cargo:rustc-link-lib=framework=Security");
|
println!("cargo:rustc-link-lib=framework=Security");
|
||||||
println!("cargo:rustc-link-lib=framework=WebKit");
|
println!("cargo:rustc-link-lib=framework=WebKit");
|
||||||
|
|
||||||
|
#[cfg(feature = "cloudkit")]
|
||||||
|
println!("cargo:rustc-link-lib=framework=CloudKit");
|
||||||
|
|
||||||
#[cfg(feature = "user-notifications")]
|
#[cfg(feature = "user-notifications")]
|
||||||
println!("cargo:rustc-link-lib=framework=UserNotifications");
|
println!("cargo:rustc-link-lib=framework=UserNotifications");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@ use crate::printing::PrintSettings;
|
||||||
use crate::user_activity::UserActivity;
|
use crate::user_activity::UserActivity;
|
||||||
use crate::utils::{map_nsarray, str_from};
|
use crate::utils::{map_nsarray, str_from};
|
||||||
|
|
||||||
|
#[cfg(feature = "cloudkit")]
|
||||||
|
use crate::cloudkit::share::CKShareMetaData;
|
||||||
|
|
||||||
/// A handy method for grabbing our `AppController` from the pointer. This is different from our
|
/// A handy method for grabbing our `AppController` from the pointer. This is different from our
|
||||||
/// standard `utils` version as this doesn't require `RefCell` backing.
|
/// standard `utils` version as this doesn't require `RefCell` backing.
|
||||||
fn app<T: AppController>(this: &Object) -> &T {
|
fn app<T: AppController>(this: &Object) -> &T {
|
||||||
|
@ -196,8 +199,10 @@ extern fn did_receive_remote_notification<T: AppController>(_this: &Object, _: S
|
||||||
|
|
||||||
/// Fires when the application receives a `application:userDidAcceptCloudKitShareWithMetadata:`
|
/// Fires when the application receives a `application:userDidAcceptCloudKitShareWithMetadata:`
|
||||||
/// message.
|
/// message.
|
||||||
extern fn accepted_cloudkit_share<T: AppController>(_this: &Object, _: Sel, _: id, _: id) {
|
#[cfg(feature = "cloudkit")]
|
||||||
|
extern fn accepted_cloudkit_share<T: AppController>(_this: &Object, _: Sel, _: id, metadata: id) {
|
||||||
|
let share = CKShareMetaData::with_inner(metadata);
|
||||||
|
app::<T>(this).user_accepted_cloudkit_share(share);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fires when the application receives an `application:openURLs` message.
|
/// Fires when the application receives an `application:openURLs` message.
|
||||||
|
@ -349,6 +354,7 @@ pub(crate) fn register_app_controller_class<T: AppController>() -> *const Class
|
||||||
decl.add_method(sel!(application:didReceiveRemoteNotification:), did_receive_remote_notification::<T> as extern fn(&Object, _, _, id));
|
decl.add_method(sel!(application:didReceiveRemoteNotification:), did_receive_remote_notification::<T> as extern fn(&Object, _, _, id));
|
||||||
|
|
||||||
// CloudKit
|
// CloudKit
|
||||||
|
#[cfg(feature = "cloudkit")]
|
||||||
decl.add_method(sel!(application:userDidAcceptCloudKitShareWithMetadata:), accepted_cloudkit_share::<T> as extern fn(&Object, _, _, id));
|
decl.add_method(sel!(application:userDidAcceptCloudKitShareWithMetadata:), accepted_cloudkit_share::<T> as extern fn(&Object, _, _, id));
|
||||||
|
|
||||||
// Opening Files
|
// Opening Files
|
||||||
|
|
|
@ -9,7 +9,8 @@ use crate::menu::Menu;
|
||||||
use crate::printing::settings::PrintSettings;
|
use crate::printing::settings::PrintSettings;
|
||||||
use crate::user_activity::UserActivity;
|
use crate::user_activity::UserActivity;
|
||||||
|
|
||||||
pub struct CKShareMetaData;
|
#[cfg(feature = "user-notifications")]
|
||||||
|
use crate::cloudkit::share::CKShareMetaData;
|
||||||
|
|
||||||
/// Controllers interested in processing messages can implement this to respond to messages as
|
/// Controllers interested in processing messages can implement this to respond to messages as
|
||||||
/// they're dispatched. All messages come in on the main thread.
|
/// they're dispatched. All messages come in on the main thread.
|
||||||
|
@ -122,6 +123,7 @@ pub trait AppController {
|
||||||
|
|
||||||
/// Fires after the user accepted a CloudKit sharing invitation associated with your
|
/// Fires after the user accepted a CloudKit sharing invitation associated with your
|
||||||
/// application.
|
/// application.
|
||||||
|
#[cfg(feature = "cloudkit")]
|
||||||
fn user_accepted_cloudkit_share(&self, _share_metadata: CKShareMetaData) {}
|
fn user_accepted_cloudkit_share(&self, _share_metadata: CKShareMetaData) {}
|
||||||
|
|
||||||
/// Fired when you have a list of `Url`'s to open. This is best explained by quoting the Apple
|
/// Fired when you have a list of `Url`'s to open. This is best explained by quoting the Apple
|
||||||
|
|
6
appkit/src/cloudkit/mod.rs
Normal file
6
appkit/src/cloudkit/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
//! This module wraps a portion of the CloudKit API. This is a fairly extensive API, and is not
|
||||||
|
//! easy to wrap - if you use this and need something that's not implemented, please consider
|
||||||
|
//! helping out with an implementation and pull request.
|
||||||
|
|
||||||
|
pub mod share;
|
||||||
|
pub use share::CKShareMetaData;
|
21
appkit/src/cloudkit/share.rs
Normal file
21
appkit/src/cloudkit/share.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
//! This module includes wrappers for `CKShare` and `CKShareMetaData`.
|
||||||
|
|
||||||
|
use cocoa::base::id;
|
||||||
|
use objc::runtime::Object;
|
||||||
|
use objc_id::ShareId;
|
||||||
|
|
||||||
|
/// A wrapper for `CKShareMetaData`, which describes details about a `CKShare`. You might use this
|
||||||
|
/// to, say, handle accepting an invite for a share.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct CKShareMetaData {
|
||||||
|
pub inner: ShareId<Object>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CKShareMetaData {
|
||||||
|
/// Internal method for wrapping a system-provided `CKShareMetaData` object.
|
||||||
|
pub(crate) fn with_inner(object: id) -> Self {
|
||||||
|
CKShareMetaData {
|
||||||
|
inner: unsafe { ShareId::from_ptr(object) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,10 @@ pub use cocoa::base::id;
|
||||||
pub mod alert;
|
pub mod alert;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod button;
|
pub mod button;
|
||||||
|
|
||||||
|
#[cfg(feature = "user-notifications")]
|
||||||
|
pub mod cloudkit;
|
||||||
|
|
||||||
pub mod color;
|
pub mod color;
|
||||||
pub mod collection_view;
|
pub mod collection_view;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
|
Loading…
Reference in a new issue