Browse Source

Converting to block based KVO.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
319ab3f85a
  1. 16
      Clocker/AppDelegate.swift
  2. 3
      Clocker/Panel/PanelController.swift

16
Clocker/AppDelegate.swift

@ -7,18 +7,15 @@ open class AppDelegate : NSObject, NSApplicationDelegate {
lazy private var floatingWindow: FloatingWindowController = FloatingWindowController.shared() lazy private var floatingWindow: FloatingWindowController = FloatingWindowController.shared()
lazy private var panelController: PanelController = PanelController.shared() lazy private var panelController: PanelController = PanelController.shared()
private var statusBarHandler: StatusItemHandler! private var statusBarHandler: StatusItemHandler!
private var panelObserver: NSKeyValueObservation?
deinit { deinit {
panelController.removeObserver(self, forKeyPath: "hasActivePanel") panelObserver?.invalidate()
} }
private var kContextActivePanel = 0
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if context == &kContextActivePanel { if let path = keyPath, path == "values.globalPing" {
statusBarHandler.setHasActiveIcon(panelController.hasActivePanelGetter())
} else if let path = keyPath, path == "values.globalPing" {
let hotKeyCenter = PTHotKeyCenter.shared() let hotKeyCenter = PTHotKeyCenter.shared()
@ -129,10 +126,9 @@ open class AppDelegate : NSObject, NSApplicationDelegate {
assignShortcut() assignShortcut()
panelController.addObserver(self, panelObserver = panelController.observe(\.hasActivePanel, options: [.new]) { (obj, change) in
forKeyPath: "hasActivePanel", self.statusBarHandler.setHasActiveIcon(obj.hasActivePanelGetter())
options: [.new], }
context: &kContextActivePanel)
let defaults = UserDefaults.standard let defaults = UserDefaults.standard

3
Clocker/Panel/PanelController.swift

@ -3,7 +3,8 @@
import Cocoa import Cocoa
class PanelController: ParentPanelController { class PanelController: ParentPanelController {
var hasActivePanel: Bool = false
@objc dynamic var hasActivePanel: Bool = false
static var sharedWindow = PanelController(windowNibName: .panel) static var sharedWindow = PanelController(windowNibName: .panel)

Loading…
Cancel
Save