1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 17:38:38 +00:00

Fix problem with blocked apps if turn off Hide control Strip.

Also for blocked apps available state in Menu
This commit is contained in:
Toxblh 2018-10-20 12:09:33 +01:00
parent bd2cd6d0b7
commit 8554dfeb5e
3 changed files with 31 additions and 8 deletions

View File

@ -12,6 +12,8 @@ import Sparkle
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength) let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
var isBlockedApp: Bool = false
private var fileSystemSource: DispatchSourceFileSystemObject? private var fileSystemSource: DispatchSourceFileSystemObject?
func applicationDidFinishLaunching(_ aNotification: Notification) { func applicationDidFinishLaunching(_ aNotification: Notification) {
@ -30,12 +32,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
createMenu() createMenu()
reloadOnDefaultConfigChanged() 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) { 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?) { @objc func openPreferences(_ sender: Any?) {
let task = Process() let task = Process()
let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR") let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR")
@ -47,8 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func toggleControlStrip(_ sender: Any?) { @objc func toggleControlStrip(_ sender: Any?) {
TouchBarController.shared.showControlStripState = !TouchBarController.shared.showControlStripState TouchBarController.shared.showControlStripState = !TouchBarController.shared.showControlStripState
createMenu()
TouchBarController.shared.resetControlStrip() TouchBarController.shared.resetControlStrip()
createMenu()
} }
@objc func toggleBlackListedApp(_ sender: Any?) { @objc func toggleBlackListedApp(_ sender: Any?) {
@ -64,6 +86,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()
TouchBarController.shared.updateActiveApp() TouchBarController.shared.updateActiveApp()
updateIsBlockedApp()
} }
} }
@ -95,6 +118,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let startAtLogin = NSMenuItem(title: "Start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L") let startAtLogin = NSMenuItem(title: "Start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L")
startAtLogin.state = LaunchAtLoginController().launchAtLogin ? .on : .off 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") let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
@ -108,7 +134,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
menu.addItem(settingSeparator) menu.addItem(settingSeparator)
menu.addItem(hideControlStrip) menu.addItem(hideControlStrip)
menu.addItem(withTitle: "Toggle current app in blacklist" , action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B") menu.addItem(toggleBlackList)
menu.addItem(startAtLogin) menu.addItem(startAtLogin)
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q") menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.18.5</string> <string>0.18.5</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>55</string> <string>79</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@ -150,11 +150,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil { if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil {
dismissTouchBar() dismissTouchBar()
} else { } else {
if self.showControlStripState { presentTouchBar()
updateControlStripPresence()
} else {
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
}
} }
} }
@ -215,6 +211,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
@objc private func presentTouchBar() { @objc private func presentTouchBar() {
if self.showControlStripState { if self.showControlStripState {
updateControlStripPresence()
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem) presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
} else { } else {
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)