use objc2::{rc::Retained, runtime::ProtocolObject};
use objc2_foundation::{NSActivityOptions, NSObjectProtocol, NSProcessInfo, NSString};
pub(super) struct Activity(Retained<ProtocolObject<dyn NSObjectProtocol>>);
unsafe impl Send for Activity {}
impl Activity {
pub(super) fn new(reason: &str) -> Self {
objc2::rc::autoreleasepool(|_| {
let token = NSProcessInfo::processInfo().beginActivityWithOptions_reason(
NSActivityOptions::UserInitiated,
&NSString::from_str(reason),
);
Self(token)
})
}
}
impl Drop for Activity {
fn drop(&mut self) {
objc2::rc::autoreleasepool(|_| {
unsafe { NSProcessInfo::processInfo().endActivity(&self.0) }
});
}
}