diff --git a/src/cmd.rs b/src/cmd.rs index bfebe34..43753af 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -122,7 +122,7 @@ impl Clavy { #[allow(clippy::too_many_lines)] fn launch>(detect_popup: impl IntoIterator) -> Result<()> { const NOTIF_NAME_LVL: Level = Level::DEBUG; - let activation_signal = |notif: &NSNotification, bundle_id: Retained| unsafe { + let activation_signal = |notif: &NSNotification, bundle_id: Retained| { ( event_enabled!(NOTIF_NAME_LVL).then(|| notif.name().to_string()), bundle_id.to_string(), diff --git a/src/observer/notification.rs b/src/observer/notification.rs index 3279d55..dc34538 100644 --- a/src/observer/notification.rs +++ b/src/observer/notification.rs @@ -6,7 +6,7 @@ use objc2_foundation::{NSNotification, NSNotificationCenter, NSNotificationName, use tracing::trace; pub static LOCAL_NOTIFICATION_CENTER: LazyLock> = - LazyLock::new(|| unsafe { NSNotificationCenter::new() }); + LazyLock::new(NSNotificationCenter::new); pub const FOCUSED_WINDOW_CHANGED_NOTIFICATION: &str = "ClavyFocusedWindowsChangedNotification"; pub const APP_HIDDEN_NOTIFICATION: &str = "ClavyAppHiddenNotification"; diff --git a/src/observer/workspace.rs b/src/observer/workspace.rs index bda1faa..1abb40d 100644 --- a/src/observer/workspace.rs +++ b/src/observer/workspace.rs @@ -46,7 +46,7 @@ define_class![ #[unsafe(method_id(init))] fn init(this: Allocated) -> Option> { let this = this.set_ivars(WorkspaceObserverIvars { - workspace: unsafe { NSWorkspace::sharedWorkspace() }, + workspace: NSWorkspace::sharedWorkspace(), children: Mutex::default(), allowed_app_ids: OnceLock::default(), }); @@ -144,15 +144,14 @@ impl WorkspaceObserver { key_path: Option<&NSString>, _change: Option<&NSDictionary>, ) { - if !key_path.is_some_and(|p| unsafe { p.isEqualToString(ns_string!(RUNNING_APPLICATIONS)) }) - { + if !key_path.is_some_and(|p| p.isEqualToString(ns_string!(RUNNING_APPLICATIONS))) { warn!("received an unexpected change from key path `{key_path:?}`"); return; } let ivars = self.ivars(); - let new = unsafe { ivars.workspace.runningApplications() }; + let new = ivars.workspace.runningApplications(); let new_keys = self.window_change_pids(&new.to_vec()); let mut children = ivars.children.lock().expect("failed to lock children"); @@ -218,7 +217,7 @@ impl WorkspaceObserver { running_apps .iter() .filter(|&app| { - unsafe { app.bundleIdentifier() }.is_some_and(|nss| { + app.bundleIdentifier().is_some_and(|nss| { self.ivars() .allowed_app_ids .get() @@ -226,7 +225,7 @@ impl WorkspaceObserver { .contains(&nss.to_string()) }) }) - .map(|app| unsafe { app.processIdentifier() }) + .map(|app| app.processIdentifier()) .filter(|pid| windowed_pids.contains(pid)) .collect() } diff --git a/src/util.rs b/src/util.rs index 513f3fc..935e560 100644 --- a/src/util.rs +++ b/src/util.rs @@ -66,12 +66,10 @@ fn ax_ui_element_value(elem: AXUIElementRef, key: &str) -> Result Option> { - unsafe { - NSWorkspace::sharedWorkspace() - .runningApplications() - .iter() - .find_map(|app| (app.processIdentifier() == pid).then(|| app.bundleIdentifier())?) - } + NSWorkspace::sharedWorkspace() + .runningApplications() + .iter() + .find_map(|app| (app.processIdentifier() == pid).then(|| app.bundleIdentifier())?) } /// Returns the PID of the frontmost application from a notification @@ -110,11 +108,9 @@ pub fn pid_from_current_app() -> Result { /// are ignored by this API. #[must_use] pub fn bundle_id_from_frontmost_app() -> Option> { - unsafe { - NSWorkspace::sharedWorkspace() - .frontmostApplication()? - .bundleIdentifier() - } + NSWorkspace::sharedWorkspace() + .frontmostApplication()? + .bundleIdentifier() } /// Returns the Bundle ID of the currently focused application.