From 70d19691a7d9c24fd968801f1721010a67399d06 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 20 May 2019 16:26:02 +0530 Subject: [PATCH] macOS: Simplify detecting the type of an Apple event Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift | 6 +----- .../WireGuard/UI/macOS/MacAppStoreUpdateDetector.swift | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift index 53a4dae..185aced 100644 --- a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift +++ b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift @@ -13,9 +13,5 @@ class LaunchedAtLoginDetector { } private func isOpenEvent(_ event: NSAppleEventDescriptor) -> Bool { - if let eventClassDescriptor = event.attributeDescriptor(forKeyword: keyEventClassAttr), - let eventIdDescriptor = event.attributeDescriptor(forKeyword: keyEventIDAttr) { - return eventClassDescriptor.typeCodeValue == kCoreEventClass && eventIdDescriptor.typeCodeValue == kAEOpenApplication - } - return false + return event.eventClass == kCoreEventClass && event.eventID == kAEOpenApplication } diff --git a/WireGuard/WireGuard/UI/macOS/MacAppStoreUpdateDetector.swift b/WireGuard/WireGuard/UI/macOS/MacAppStoreUpdateDetector.swift index 7fbb011..68608ca 100644 --- a/WireGuard/WireGuard/UI/macOS/MacAppStoreUpdateDetector.swift +++ b/WireGuard/WireGuard/UI/macOS/MacAppStoreUpdateDetector.swift @@ -19,11 +19,7 @@ class MacAppStoreUpdateDetector { } private func isQuitEvent(_ event: NSAppleEventDescriptor) -> Bool { - if let eventClassDescriptor = event.attributeDescriptor(forKeyword: keyEventClassAttr), - let eventIdDescriptor = event.attributeDescriptor(forKeyword: keyEventIDAttr) { - return eventClassDescriptor.typeCodeValue == kCoreEventClass && eventIdDescriptor.typeCodeValue == kAEQuitApplication - } - return false + return event.eventClass == kCoreEventClass && event.eventID == kAEQuitApplication } private func getExecutablePath(from pid: pid_t) -> String? {