use std::{
cell::{Cell, RefCell},
collections::HashMap,
ffi::c_void,
ptr::null_mut,
sync::{Arc, Mutex},
};
use block2::{Block, RcBlock};
use objc2::{
ClassType, DeclaredClass,
declare::ClassBuilder,
declare_class,
ffi::{
OBJC_ASSOCIATION_RETAIN_NONATOMIC, objc_getAssociatedObject, objc_setAssociatedObject,
object_setClass,
},
msg_send_id,
mutability::{InteriorMutable, MainThreadOnly},
rc::Retained,
runtime::{AnyClass, AnyObject, Bool, NSObjectProtocol, ProtocolObject, Sel},
sel,
};
use objc2_app_kit::{
NSApplication, NSApplicationDidBecomeActiveNotification,
NSApplicationDidChangeScreenParametersNotification, NSWorkspace,
NSWorkspaceDidWakeNotification,
};
use objc2_foundation::{
MainThreadMarker, NSArray, NSBundle, NSError, NSNotification, NSNotificationCenter, NSObject,
NSSet, NSString, NSURL, NSUTF8StringEncoding,
};
use objc2_user_notifications::{
UNAuthorizationOptions, UNMutableNotificationContent, UNNotification, UNNotificationAction,
UNNotificationActionOptions, UNNotificationCategory, UNNotificationCategoryOptions,
UNNotificationDefaultActionIdentifier, UNNotificationDismissActionIdentifier,
UNNotificationPresentationOptions, UNNotificationRequest, UNNotificationResponse,
UNUserNotificationCenter, UNUserNotificationCenterDelegate,
};
use winit::event_loop::EventLoopProxy;
use crate::{
OpenUrls, SystemNotification, SystemNotificationAction, SystemNotificationResponse,
platform::{
MAX_OPEN_URLS, MAX_OPEN_URLS_TOTAL_BYTES, MAX_PENDING_SYSTEM_NOTIFICATIONS,
MAX_PLATFORM_TEXT_BYTES, MAX_PLATFORM_URL_BYTES, MAX_SYSTEM_NOTIFICATION_ACTION_BYTES,
MAX_SYSTEM_NOTIFICATION_CATEGORIES, MAX_SYSTEM_NOTIFICATION_TAG_BYTES,
},
runtime::RuntimeEvent,
};
struct ApplicationStateIvars {
proxy: EventLoopProxy<RuntimeEvent>,
observe_open_urls: bool,
observe_reopen: bool,
}
declare_class!(
struct QuickGuiApplicationState;
unsafe impl ClassType for QuickGuiApplicationState {
type Super = NSObject;
type Mutability = MainThreadOnly;
const NAME: &'static str = "QuickGuiApplicationState";
}
impl DeclaredClass for QuickGuiApplicationState {
type Ivars = ApplicationStateIvars;
}
);
impl QuickGuiApplicationState {
fn new(
mtm: MainThreadMarker,
proxy: EventLoopProxy<RuntimeEvent>,
observe_open_urls: bool,
observe_reopen: bool,
) -> Retained<Self> {
let allocated = mtm.alloc().set_ivars(ApplicationStateIvars {
proxy,
observe_open_urls,
observe_reopen,
});
unsafe { msg_send_id![super(allocated), init] }
}
}
static APPLICATION_DELEGATE_SUBCLASSES: Mutex<Vec<(&'static AnyClass, &'static AnyClass)>> =
Mutex::new(Vec::new());
static APPLICATION_STATE_ASSOCIATED_OBJECT_KEY: u8 = 0;
fn application_state_associated_object_key() -> *const c_void {
(&APPLICATION_STATE_ASSOCIATED_OBJECT_KEY as *const u8).cast()
}
fn application_state(delegate: &AnyObject) -> Option<&QuickGuiApplicationState> {
let state = unsafe {
objc_getAssociatedObject(
(delegate as *const AnyObject).cast(),
application_state_associated_object_key(),
)
};
unsafe { (state as *const QuickGuiApplicationState).as_ref() }
}
unsafe extern "C" fn application_open_urls(
delegate: &AnyObject,
_cmd: Sel,
_application: &NSApplication,
urls: &NSArray<NSURL>,
) {
let Some(state) = application_state(delegate) else {
return;
};
if !state.ivars().observe_open_urls {
return;
}
let urls = bounded_open_urls(urls);
if !urls.is_empty() {
let _ = state.ivars().proxy.send_event(RuntimeEvent::OpenUrls(urls));
}
}
unsafe extern "C" fn application_should_handle_reopen(
delegate: &AnyObject,
_cmd: Sel,
_application: &NSApplication,
has_visible_windows: Bool,
) -> Bool {
let Some(state) = application_state(delegate) else {
return Bool::NO;
};
if !state.ivars().observe_reopen {
return Bool::NO;
}
let _ = state.ivars().proxy.send_event(RuntimeEvent::Reopen {
has_visible_windows: has_visible_windows.as_bool(),
});
Bool::YES
}
struct MacApplicationDelegateHost {
delegate: Retained<AnyObject>,
associated: Retained<QuickGuiApplicationState>,
previous_class: &'static AnyClass,
}
impl MacApplicationDelegateHost {
fn new(
mtm: MainThreadMarker,
proxy: EventLoopProxy<RuntimeEvent>,
observe_open_urls: bool,
observe_reopen: bool,
) -> Result<Self, String> {
let application = NSApplication::sharedApplication(mtm);
let delegate = unsafe { application.delegate() }
.ok_or_else(|| "Winit did not install its NSApplicationDelegate".to_owned())?;
let delegate: Retained<AnyObject> = unsafe { Retained::cast(delegate) };
let existing = unsafe {
objc_getAssociatedObject(
Retained::as_ptr(&delegate).cast(),
application_state_associated_object_key(),
)
};
if !existing.is_null() {
return Err("QuickGUI application callbacks are already installed".to_owned());
}
let previous_class = unsafe { &*(delegate.class() as *const AnyClass) };
let subclass = {
let mut subclasses = APPLICATION_DELEGATE_SUBCLASSES
.lock()
.map_err(|_| "application-delegate class registry is poisoned".to_owned())?;
if let Some((_, subclass)) = subclasses
.iter()
.find(|(candidate, _)| *candidate == previous_class)
{
*subclass
} else {
let name = format!("QuickGuiApplicationOf{}", previous_class.name());
let mut builder = ClassBuilder::new(&name, previous_class).ok_or_else(|| {
format!("could not declare Objective-C application subclass {name}")
})?;
unsafe {
builder.add_method(
sel!(application:openURLs:),
application_open_urls as unsafe extern "C" fn(_, _, _, _),
);
builder.add_method(
sel!(applicationShouldHandleReopen:hasVisibleWindows:),
application_should_handle_reopen as unsafe extern "C" fn(_, _, _, _) -> _,
);
}
let subclass = builder.register();
subclasses.push((previous_class, subclass));
subclass
}
};
let associated =
QuickGuiApplicationState::new(mtm, proxy, observe_open_urls, observe_reopen);
unsafe {
objc_setAssociatedObject(
Retained::as_ptr(&delegate).cast_mut().cast(),
application_state_associated_object_key(),
Retained::as_ptr(&associated).cast_mut().cast(),
OBJC_ASSOCIATION_RETAIN_NONATOMIC,
);
object_setClass(
Retained::as_ptr(&delegate).cast_mut().cast(),
(subclass as *const AnyClass).cast(),
);
}
Ok(Self {
delegate,
associated,
previous_class,
})
}
}
impl Drop for MacApplicationDelegateHost {
fn drop(&mut self) {
unsafe {
object_setClass(
Retained::as_ptr(&self.delegate).cast_mut().cast(),
(self.previous_class as *const AnyClass).cast(),
);
objc_setAssociatedObject(
Retained::as_ptr(&self.delegate).cast_mut().cast(),
application_state_associated_object_key(),
null_mut(),
OBJC_ASSOCIATION_RETAIN_NONATOMIC,
);
}
let _ = &self.associated;
}
}
struct ApplicationObserverIvars {
proxy: EventLoopProxy<RuntimeEvent>,
}
declare_class!(
struct QuickGuiApplicationObserver;
unsafe impl ClassType for QuickGuiApplicationObserver {
type Super = NSObject;
type Mutability = InteriorMutable;
const NAME: &'static str = "QuickGuiApplicationObserver";
}
impl DeclaredClass for QuickGuiApplicationObserver {
type Ivars = ApplicationObserverIvars;
}
unsafe impl NSObjectProtocol for QuickGuiApplicationObserver {}
unsafe impl QuickGuiApplicationObserver {
#[method(quickGuiSystemDidWake:)]
fn system_did_wake(&self, _notification: &NSNotification) {
let _ = self.ivars().proxy.send_event(RuntimeEvent::SystemWake);
}
#[method(quickGuiDisplaysDidChange:)]
fn displays_did_change(&self, _notification: &NSNotification) {
let _ = self.ivars().proxy.send_event(RuntimeEvent::DisplaysChanged);
}
#[method(quickGuiKeyboardLayoutDidChange:)]
fn keyboard_layout_did_change(&self, _notification: &NSNotification) {
let _ = self
.ivars()
.proxy
.send_event(RuntimeEvent::KeyboardLayoutChanged);
}
}
);
impl QuickGuiApplicationObserver {
fn new(proxy: EventLoopProxy<RuntimeEvent>) -> Retained<Self> {
let allocated = Self::alloc().set_ivars(ApplicationObserverIvars { proxy });
unsafe { msg_send_id![super(allocated), init] }
}
}
struct NotificationDelegateIvars {
proxy: EventLoopProxy<RuntimeEvent>,
}
type NotificationCategories =
HashMap<Vec<SystemNotificationAction>, (Arc<str>, Retained<UNNotificationCategory>)>;
declare_class!(
struct QuickGuiNotificationDelegate;
unsafe impl ClassType for QuickGuiNotificationDelegate {
type Super = NSObject;
type Mutability = InteriorMutable;
const NAME: &'static str = "QuickGuiNotificationDelegate";
}
impl DeclaredClass for QuickGuiNotificationDelegate {
type Ivars = NotificationDelegateIvars;
}
unsafe impl NSObjectProtocol for QuickGuiNotificationDelegate {}
unsafe impl UNUserNotificationCenterDelegate for QuickGuiNotificationDelegate {
#[method(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]
fn did_receive_notification_response(
&self,
_center: &UNUserNotificationCenter,
response: &UNNotificationResponse,
completion_handler: &Block<dyn Fn()>,
) {
let notification = unsafe { response.notification() };
let request = unsafe { notification.request() };
let tag = unsafe { request.identifier() };
let action = unsafe { response.actionIdentifier() };
let tag = bounded_string(&tag, MAX_SYSTEM_NOTIFICATION_TAG_BYTES);
let action_id = if action.as_ref() == unsafe { UNNotificationDefaultActionIdentifier }
{
Some(None)
} else if action.as_ref() == unsafe { UNNotificationDismissActionIdentifier } {
None
} else {
bounded_string(&action, MAX_SYSTEM_NOTIFICATION_ACTION_BYTES).map(Some)
};
if let (Some(tag), Some(action_id)) = (tag, action_id) {
let _ = self.ivars().proxy.send_event(
RuntimeEvent::SystemNotificationResponse(SystemNotificationResponse {
tag,
action_id,
}),
);
}
completion_handler.call(());
}
#[method(userNotificationCenter:willPresentNotification:withCompletionHandler:)]
fn will_present_notification(
&self,
_center: &UNUserNotificationCenter,
_notification: &UNNotification,
completion_handler: &Block<dyn Fn(UNNotificationPresentationOptions)>,
) {
completion_handler.call((
UNNotificationPresentationOptions::UNNotificationPresentationOptionBanner
| UNNotificationPresentationOptions::UNNotificationPresentationOptionList,
));
}
}
);
impl QuickGuiNotificationDelegate {
fn new(proxy: EventLoopProxy<RuntimeEvent>) -> Retained<QuickGuiNotificationDelegate> {
let allocated = Self::alloc().set_ivars(NotificationDelegateIvars { proxy });
unsafe { msg_send_id![super(allocated), init] }
}
}
struct MacSystemNotificationCenter {
center: Retained<UNUserNotificationCenter>,
_delegate: Retained<QuickGuiNotificationDelegate>,
categories: RefCell<NotificationCategories>,
authorization: Cell<NotificationAuthorization>,
pending: RefCell<Vec<SystemNotification>>,
proxy: EventLoopProxy<RuntimeEvent>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum NotificationAuthorization {
NotRequested,
Pending,
Granted,
Denied,
}
impl MacSystemNotificationCenter {
fn new(proxy: EventLoopProxy<RuntimeEvent>) -> Option<Self> {
if unsafe { NSBundle::mainBundle().bundleIdentifier() }.is_none() {
tracing::info!("system notifications are unavailable outside an application bundle");
return None;
}
let center = unsafe { UNUserNotificationCenter::currentNotificationCenter() };
let delegate = QuickGuiNotificationDelegate::new(proxy.clone());
unsafe {
center.setDelegate(Some(ProtocolObject::from_ref(delegate.as_ref())));
}
Some(Self {
center,
_delegate: delegate,
categories: RefCell::new(HashMap::new()),
authorization: Cell::new(NotificationAuthorization::NotRequested),
pending: RefCell::new(Vec::with_capacity(4)),
proxy,
})
}
fn request_authorization(&self) {
debug_assert_eq!(self.authorization.get(), NotificationAuthorization::Pending);
let proxy = self.proxy.clone();
let completion = RcBlock::new(move |granted: Bool, error: *mut NSError| {
let error = unsafe { error.as_ref() }.and_then(|error| {
bounded_string(&error.localizedDescription(), MAX_PLATFORM_TEXT_BYTES)
});
let granted = granted.as_bool() && error.is_none();
let _ =
proxy.send_event(RuntimeEvent::SystemNotificationAuthorization { granted, error });
});
unsafe {
self.center
.requestAuthorizationWithOptions_completionHandler(
UNAuthorizationOptions::UNAuthorizationOptionAlert
| UNAuthorizationOptions::UNAuthorizationOptionSound,
&completion,
);
}
}
fn show(&self, notification: SystemNotification) {
match self.authorization.get() {
NotificationAuthorization::NotRequested => {
self.enqueue_pending(notification);
self.authorization.set(NotificationAuthorization::Pending);
self.request_authorization();
}
NotificationAuthorization::Pending => self.enqueue_pending(notification),
NotificationAuthorization::Granted => self.post(notification),
NotificationAuthorization::Denied => {}
}
}
fn enqueue_pending(&self, notification: SystemNotification) {
let mut pending = self.pending.borrow_mut();
if enqueue_pending_system_notification(&mut pending, notification) {
tracing::warn!(
maximum = MAX_PENDING_SYSTEM_NOTIFICATIONS,
"system notification authorization queue is full; replacing its oldest tag"
);
}
}
fn complete_authorization(&self, granted: bool, error: Option<Arc<str>>) {
if self.authorization.get() != NotificationAuthorization::Pending {
return;
}
if let Some(error) = error {
tracing::warn!(%error, "system notification authorization failed");
} else if !granted {
tracing::info!("system notification authorization was denied");
}
self.authorization.set(if granted {
NotificationAuthorization::Granted
} else {
NotificationAuthorization::Denied
});
let pending = std::mem::take(&mut *self.pending.borrow_mut());
if granted {
for notification in pending {
self.post(notification);
}
}
}
fn post(&self, notification: SystemNotification) {
let content = unsafe { UNMutableNotificationContent::new() };
unsafe {
content.setTitle(&NSString::from_str(¬ification.title));
content.setBody(&NSString::from_str(¬ification.body));
}
if !notification.actions.is_empty() {
if let Some(identifier) = self.register_category(¬ification.actions) {
unsafe {
content.setCategoryIdentifier(&NSString::from_str(&identifier));
}
} else {
tracing::warn!(
maximum = MAX_SYSTEM_NOTIFICATION_CATEGORIES,
"system notification action-category capacity reached; posting without actions"
);
}
}
let request = unsafe {
UNNotificationRequest::requestWithIdentifier_content_trigger(
&NSString::from_str(¬ification.tag),
&content,
None,
)
};
let completion = RcBlock::new(|error: *mut NSError| {
if let Some(error) = unsafe { error.as_ref() } {
tracing::warn!(
error = %error.localizedDescription(),
"could not deliver system notification"
);
}
});
unsafe {
self.center
.addNotificationRequest_withCompletionHandler(&request, Some(&completion));
}
}
fn register_category(&self, actions: &[SystemNotificationAction]) -> Option<Arc<str>> {
let mut categories = self.categories.borrow_mut();
if let Some((identifier, _)) = categories.get(actions) {
return Some(identifier.clone());
}
if categories.len() == MAX_SYSTEM_NOTIFICATION_CATEGORIES {
return None;
}
let identifier: Arc<str> =
Arc::from(format!("quickgui-system-notification-{}", categories.len()));
let native_actions = actions
.iter()
.map(|action| unsafe {
UNNotificationAction::actionWithIdentifier_title_options(
&NSString::from_str(&action.id),
&NSString::from_str(&action.label),
UNNotificationActionOptions::empty(),
)
})
.collect();
let native_actions = NSArray::from_vec(native_actions);
let category = unsafe {
UNNotificationCategory::categoryWithIdentifier_actions_intentIdentifiers_options(
&NSString::from_str(&identifier),
&native_actions,
&NSArray::new(),
UNNotificationCategoryOptions::empty(),
)
};
categories.insert(actions.to_vec(), (identifier.clone(), category));
let all = categories
.values()
.map(|(_, category)| category.clone())
.collect();
let all = NSArray::from_vec(all);
let all = unsafe { NSSet::setWithArray(&all) };
unsafe {
self.center.setNotificationCategories(&all);
}
Some(identifier)
}
fn dismiss(&self, tag: &str) {
self.pending
.borrow_mut()
.retain(|notification| notification.tag.as_ref() != tag);
let identifiers = NSArray::from_vec(vec![NSString::from_str(tag)]);
unsafe {
self.center
.removePendingNotificationRequestsWithIdentifiers(&identifiers);
self.center
.removeDeliveredNotificationsWithIdentifiers(&identifiers);
}
}
}
impl Drop for MacSystemNotificationCenter {
fn drop(&mut self) {
unsafe {
self.center.setDelegate(None);
}
}
}
pub(crate) struct MacApplicationHost {
application_delegate: Option<MacApplicationDelegateHost>,
application_notifications: Retained<NSNotificationCenter>,
application_observer: Retained<QuickGuiApplicationObserver>,
workspace_notifications: Option<Retained<NSNotificationCenter>>,
notifications_initialized: bool,
notifications: Option<MacSystemNotificationCenter>,
proxy: EventLoopProxy<RuntimeEvent>,
}
impl MacApplicationHost {
pub(crate) fn new(
proxy: EventLoopProxy<RuntimeEvent>,
observe_open_urls: bool,
observe_reopen: bool,
observe_system_wake: bool,
observe_notification_responses: bool,
) -> Result<Self, String> {
let mtm = MainThreadMarker::new().ok_or_else(|| {
"the AppKit application host must be installed on the main thread".to_owned()
})?;
let application_delegate = (observe_open_urls || observe_reopen)
.then(|| {
MacApplicationDelegateHost::new(
mtm,
proxy.clone(),
observe_open_urls,
observe_reopen,
)
})
.transpose()?;
let application_observer = QuickGuiApplicationObserver::new(proxy.clone());
let application_notifications = unsafe { NSNotificationCenter::defaultCenter() };
unsafe {
application_notifications.addObserver_selector_name_object(
application_observer.as_ref(),
sel!(quickGuiDisplaysDidChange:),
Some(NSApplicationDidChangeScreenParametersNotification),
None,
);
application_notifications.addObserver_selector_name_object(
application_observer.as_ref(),
sel!(quickGuiDisplaysDidChange:),
Some(NSApplicationDidBecomeActiveNotification),
None,
);
let keyboard_layout_notification =
NSString::from_str("NSTextInputContextKeyboardSelectionDidChangeNotification");
application_notifications.addObserver_selector_name_object(
application_observer.as_ref(),
sel!(quickGuiKeyboardLayoutDidChange:),
Some(&keyboard_layout_notification),
None,
);
}
let workspace_notifications = if observe_system_wake {
unsafe {
let center = NSWorkspace::sharedWorkspace().notificationCenter();
center.addObserver_selector_name_object(
application_observer.as_ref(),
sel!(quickGuiSystemDidWake:),
Some(NSWorkspaceDidWakeNotification),
None,
);
Some(center)
}
} else {
None
};
let mut host = Self {
application_delegate,
application_notifications,
application_observer,
workspace_notifications,
notifications_initialized: false,
notifications: None,
proxy,
};
if observe_notification_responses {
host.ensure_notifications();
}
Ok(host)
}
pub(crate) fn show_system_notification(&mut self, notification: SystemNotification) {
self.ensure_notifications();
if let Some(center) = &self.notifications {
center.show(notification);
}
}
pub(crate) fn dismiss_system_notification(&mut self, tag: &str) {
self.ensure_notifications();
if let Some(center) = &self.notifications {
center.dismiss(tag);
}
}
pub(crate) fn complete_system_notification_authorization(
&mut self,
granted: bool,
error: Option<Arc<str>>,
) {
if let Some(center) = &self.notifications {
center.complete_authorization(granted, error);
}
}
fn ensure_notifications(&mut self) {
if self.notifications_initialized {
return;
}
self.notifications_initialized = true;
self.notifications = MacSystemNotificationCenter::new(self.proxy.clone());
}
}
impl Drop for MacApplicationHost {
fn drop(&mut self) {
unsafe {
self.application_notifications
.removeObserver(self.application_observer.as_ref());
}
if let Some(center) = self.workspace_notifications.take() {
unsafe {
center.removeObserver(self.application_observer.as_ref());
}
}
drop(self.application_delegate.take());
}
}
fn bounded_open_urls(urls: &NSArray<NSURL>) -> OpenUrls {
let mut retained = Vec::with_capacity(urls.len().min(MAX_OPEN_URLS));
let mut total = 0_usize;
for index in 0..urls.len().min(MAX_OPEN_URLS) {
let Some(url) = urls.get(index) else {
continue;
};
let Some(absolute) = (unsafe { url.absoluteString() }) else {
continue;
};
let Some(url) = bounded_string(&absolute, MAX_PLATFORM_URL_BYTES) else {
continue;
};
let Some(next_total) = total.checked_add(url.len()) else {
break;
};
if next_total > MAX_OPEN_URLS_TOTAL_BYTES {
break;
}
total = next_total;
retained.push(url);
}
OpenUrls::from_bounded(retained)
}
fn bounded_string(value: &NSString, maximum: usize) -> Option<Arc<str>> {
if value.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > maximum {
return None;
}
let value = value.to_string();
if value.len() > maximum || value.contains('\0') {
None
} else {
Some(Arc::from(value))
}
}
fn enqueue_pending_system_notification(
pending: &mut Vec<SystemNotification>,
notification: SystemNotification,
) -> bool {
if let Some(existing) = pending
.iter_mut()
.find(|existing| existing.tag == notification.tag)
{
*existing = notification;
return false;
}
let evicted = pending.len() == MAX_PENDING_SYSTEM_NOTIFICATIONS;
if evicted {
pending.remove(0);
}
pending.push(notification);
evicted
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn native_strings_are_bounded_before_rust_retention() {
assert_eq!(
bounded_string(&NSString::from_str("quickgui://open"), 32).as_deref(),
Some("quickgui://open")
);
assert!(bounded_string(&NSString::from_str("too long"), 4).is_none());
assert!(bounded_string(&NSString::from_str("bad\0value"), 32).is_none());
}
#[test]
fn pending_notification_authorization_is_bounded_and_coalesces_tags() {
let mut pending = Vec::new();
assert!(!enqueue_pending_system_notification(
&mut pending,
SystemNotification::new("build", "First", "Body"),
));
assert!(!enqueue_pending_system_notification(
&mut pending,
SystemNotification::new("build", "Replacement", "Body"),
));
assert_eq!(pending.len(), 1);
assert_eq!(pending[0].title.as_ref(), "Replacement");
for index in 1..MAX_PENDING_SYSTEM_NOTIFICATIONS {
assert!(!enqueue_pending_system_notification(
&mut pending,
SystemNotification::new(format!("tag-{index}"), "Title", "Body"),
));
}
assert_eq!(pending.len(), MAX_PENDING_SYSTEM_NOTIFICATIONS);
assert!(enqueue_pending_system_notification(
&mut pending,
SystemNotification::new("newest", "Title", "Body"),
));
assert_eq!(pending.len(), MAX_PENDING_SYSTEM_NOTIFICATIONS);
assert!(
pending
.iter()
.all(|notification| notification.tag.as_ref() != "build")
);
assert_eq!(pending.last().unwrap().tag.as_ref(), "newest");
}
}