diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift
index ada059a..dfb5d8f 100644
--- a/MTMR/AppDelegate.swift
+++ b/MTMR/AppDelegate.swift
@@ -12,6 +12,8 @@ import Sparkle
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
+ var isBlockedApp: Bool = false
+
private var fileSystemSource: DispatchSourceFileSystemObject?
func applicationDidFinishLaunching(_ aNotification: Notification) {
@@ -30,12 +32,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
createMenu()
reloadOnDefaultConfigChanged()
+
+ NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
+ NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
+ NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didActivateApplicationNotification, object: nil)
}
func applicationWillTerminate(_ aNotification: Notification) {
}
+ @objc func updateIsBlockedApp() -> Void {
+ var blacklistAppIdentifiers: [String] = []
+ if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
+ blacklistAppIdentifiers = blackListed
+ }
+ var frontmostApplicationIdentifier: String? {
+ get {
+ guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
+ return frontmostId
+ }
+ }
+
+ self.isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil
+ createMenu()
+ }
+
@objc func openPreferences(_ sender: Any?) {
let task = Process()
let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR")
@@ -47,8 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func toggleControlStrip(_ sender: Any?) {
TouchBarController.shared.showControlStripState = !TouchBarController.shared.showControlStripState
- createMenu()
TouchBarController.shared.resetControlStrip()
+ createMenu()
}
@objc func toggleBlackListedApp(_ sender: Any?) {
@@ -64,6 +86,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
UserDefaults.standard.synchronize()
TouchBarController.shared.updateActiveApp()
+ updateIsBlockedApp()
}
}
@@ -95,6 +118,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let startAtLogin = NSMenuItem(title: "Start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L")
startAtLogin.state = LaunchAtLoginController().launchAtLogin ? .on : .off
+ let toggleBlackList = NSMenuItem(title: "Toggle current app in blacklist", action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
+ toggleBlackList.state = self.isBlockedApp ? .on : .off
+
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
@@ -108,7 +134,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem.separator())
menu.addItem(settingSeparator)
menu.addItem(hideControlStrip)
- menu.addItem(withTitle: "Toggle current app in blacklist" , action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
+ menu.addItem(toggleBlackList)
menu.addItem(startAtLogin)
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
diff --git a/MTMR/Info.plist b/MTMR/Info.plist
index d854e31..b1ab140 100644
--- a/MTMR/Info.plist
+++ b/MTMR/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
0.18.5
CFBundleVersion
- 55
+ 79
LSApplicationCategoryType
public.app-category.utilities
LSMinimumSystemVersion
diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift
index 2988acd..4b1fe39 100644
--- a/MTMR/TouchBarController.swift
+++ b/MTMR/TouchBarController.swift
@@ -150,11 +150,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil {
dismissTouchBar()
} else {
- if self.showControlStripState {
- updateControlStripPresence()
- } else {
- presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
- }
+ presentTouchBar()
}
}
@@ -215,6 +211,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
@objc private func presentTouchBar() {
if self.showControlStripState {
+ updateControlStripPresence()
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
} else {
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)