diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index 0c9c060..5a3d4ee 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -46,17 +46,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @objc func updateIsBlockedApp() { - var blacklistAppIdentifiers: [String] = [] - if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { - blacklistAppIdentifiers = blackListed - } - var frontmostApplicationIdentifier: String? { - guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil } - return frontmostId - } - - if frontmostApplicationIdentifier != nil { - isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil + if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier { + let blacklistAppIdentifiers = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") ?? [] + isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostAppId) != nil } else { isBlockedApp = false } @@ -79,12 +71,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @objc func toggleBlackListedApp(_: Any?) { - let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier - if appIdentifier != nil { - if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier!) { + if let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier { + if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier) { TouchBarController.shared.blacklistAppIdentifiers.remove(at: index) } else { - TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!) + TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier) } UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps") diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index a56e8c9..28b9d5e 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -101,8 +101,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { var blacklistAppIdentifiers: [String] = [] var frontmostApplicationIdentifier: String? { - guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil } - return frontmostId + return NSWorkspace.shared.frontmostApplication?.bundleIdentifier } private override init() {