import Cocoa
-fileprivate extension Selector {
- static let henseiDidChangeNotification = #selector(HMAnchorageRepairManager.henseiDidChangeNotification(_:))
- static let didReturnToBaseNotification = #selector(HMAnchorageRepairManager.didReturnToBaseNotification(_:))
-}
class HMAnchorageRepairManager: NSObject {
static let `default`: HMAnchorageRepairManager = HMAnchorageRepairManager()
super.init()
let nc = NotificationCenter.default
- nc.addObserver(self, selector: .henseiDidChangeNotification, name: .HenseiDidChange, object: nil)
- nc.addObserver(self, selector: .didReturnToBaseNotification, name: .PortAPIReceived, object: nil)
+ nc.addObserver(forName: .HenseiDidChange, object: nil, queue: nil) { notification in
+ guard let userInfo = notification.userInfo,
+ let info = userInfo[HMChangeHenseiCommand.userInfoKey] as? HenseiDidChangeUserInfo
+ else { return }
+ self.resetIfNeeds(info: info)
+ }
+ nc.addObserver(forName: .PortAPIReceived, object: nil, queue: nil) { (Notification) in
+ if Date().timeIntervalSince(self.repairTime) < 20 * 60 { return }
+ self.reset()
+ }
+ }
+ deinit {
+ NotificationCenter.default.removeObserver(self)
}
private func reset() {
private func resetIfNeeds(info: HenseiDidChangeUserInfo) {
if needsReset(info: info) { reset() }
}
-
- @objc fileprivate func didReturnToBaseNotification(_ notification: Notification) {
- let now = Date()
- let passedTime = now.timeIntervalSince(repairTime)
- if passedTime < 20 * 60 { return }
- reset()
- }
- @objc fileprivate func henseiDidChangeNotification(_ notification: Notification) {
- guard let userInfo = notification.userInfo,
- let info = userInfo[HMChangeHenseiCommand.userInfoKey] as? HenseiDidChangeUserInfo
- else { return }
- resetIfNeeds(info: info)
- }
}
fileprivate extension Selector {
- static let didCangeCombined = #selector(HMBroserWindowController.didCangeCombined(_:))
-
static let reloadContent = #selector(HMBroserWindowController.reloadContent(_:))
static let deleteCacheAndReload = #selector(HMBroserWindowController.deleteCacheAndReload(_:))
static let clearQuestList = #selector(HMBroserWindowController.clearQuestList(_:))
bind("flagShipID", to: deckContoller, withKeyPath: "selection.ship_0", options: nil)
- NotificationCenter.default.addObserver(self, selector: .didCangeCombined, name: .CombinedDidCange, object: nil)
+ NotificationCenter.default
+ .addObserver(forName: .CombinedDidCange, object: nil, queue: nil) { (notification) in
+ guard UserDefaults.standard.autoCombinedView,
+ let type = notification.userInfo?[HMCombinedType] as? CombineType
+ else { return }
+ if !Thread.isMainThread { Thread.sleep(forTimeInterval: 0.1) }
+ DispatchQueue.main.async {
+ switch type {
+ case .cancel:
+ self.hideCombinedView()
+ case .maneuver, .water, .transportation:
+ self.showCombinedView()
+ }
+ }
+ }
if UserDefaults.standard.lastHasCombinedView { showCombinedView() }
}
+ deinit {
+ NotificationCenter.default.removeObserver(self)
+ }
func windowWillClose(_ notification: Notification) {
UserDefaults.standard.lastHasCombinedView = isCombinedMode
window?.setFrame(winFrame, display: true, animate: true)
combinedViewController.view.isHidden = true
}
- func didCangeCombined(_ notification: Notification?) {
- guard UserDefaults.standard.autoCombinedView else { return }
- guard let type = notification?.userInfo?[HMCombinedType] as? CombineType else { return }
- if !Thread.isMainThread { Thread.sleep(forTimeInterval: 0.1) }
- DispatchQueue.main.async {
- switch type {
- case .cancel:
- self.hideCombinedView()
- case .maneuver, .water, .transportation:
- self.showCombinedView()
- }
- }
- }
override func swipe(with event: NSEvent) {
guard UserDefaults.standard.useSwipeChangeCombinedView else { return }
case miniVierticalType = 2
}
-fileprivate extension Selector {
- static let updateFleet = #selector(HMFleetViewController.updateFleet(_:))
-}
-
fileprivate var shipKeysContext: Int = 0
fileprivate var shipsContext: Int = 0
}
fleetNumber = 1
- NotificationCenter.default.addObserver(self, selector: .updateFleet, name: .DidPrepareFleet, object: nil)
+ NotificationCenter.default
+ .addObserver(forName: .DidPrepareFleet, object: nil, queue: nil) { _ in
+ self.willChangeValue(forKey: "fleetNumber")
+ self.didChangeValue(forKey: "fleetNumber")
+ }
+ }
+ deinit {
+ NotificationCenter.default.removeObserver(self)
}
private let type: HMFleetViewType
didChangeValue(forKey: $0)
}
}
-
- func updateFleet(_ notification: Notification) {
- willChangeValue(forKey: "fleetNumber")
- didChangeValue(forKey: "fleetNumber")
- }
}
extension HMFleetViewController {
notifyIfNeeded(nil)
}
+ deinit {
+ NotificationCenter.default.removeObserver(self)
+ }
private let hour: Int
private let minutes: Int
import Cocoa
fileprivate extension Selector {
- static let reduce = #selector(HMResourceHistoryManager.reduce(_:))
static let notifyIfNeeded = #selector(HMResourceHistoryManager.notifyIfNeeded(_:))
}
periodicNotification = HMPeriodicNotifier(hour: 23, minutes: 3)
super.init()
notifyIfNeeded(nil)
- NotificationCenter.default.addObserver(self, selector: .reduce, name: .Periodic, object: periodicNotification)
+ NotificationCenter.default
+ .addObserver(forName: .Periodic, object: periodicNotification, queue: nil, using: reduce)
}
@objc fileprivate func notifyIfNeeded(_ timer: Timer?) {
}
}
-fileprivate extension Selector {
- static let viewFrameDidChange = #selector(HMScreenshotListViewController.viewFrameDidChange(_:))
- static let scrollViewDidLiveScrollNotification = #selector(HMScreenshotListViewController.scrollViewDidLiveScrollNotification(_:))
- static let reloadData = #selector(HMScreenshotListViewController.reloadData(_:))
-}
-
class HMScreenshotListViewController: NSViewController {
override func viewDidLoad() {
let nc = NotificationCenter.default
let scrollView = collectionView.enclosingScrollView
- nc.addObserver(self, selector: .viewFrameDidChange, name: .NSViewFrameDidChange, object: collectionView)
- nc.addObserver(self, selector: .scrollViewDidLiveScrollNotification, name: .NSScrollViewDidLiveScroll, object: scrollView)
+
+
+ nc.addObserver(forName: .NSViewFrameDidChange, object: collectionView, queue: nil, using: viewFrameDidChange)
+ nc.addObserver(forName: .NSScrollViewDidLiveScroll, object: collectionView.enclosingScrollView, queue: nil) { _ in
+ let visibleItems = self.collectionView.indexPathsForVisibleItems()
+ self.collectionVisibleDidChangeHandler?(visibleItems)
+ }
nc.addObserver(forName: .NSScrollViewWillStartLiveScroll, object: scrollView, queue: nil) { _ in
self.inLiveScrolling = true
}
viewFrameDidChange(nil)
- perform(.reloadData, with: nil, afterDelay: 0.0)
+ DispatchQueue.main
+ .asyncAfter(deadline: .now() + 0.0001 ) { self.reloadData() }
}
var screenshots: HMScreenshotModel = HMScreenshotModel()
}
fileprivate var collectionVisibleDidChangeHandler: ((Set<IndexPath>) -> Void)? = nil
- func scrollViewDidLiveScrollNotification(_ notification: Notification?) {
- let visibleItems = collectionView.indexPathsForVisibleItems()
- collectionVisibleDidChangeHandler?(visibleItems)
- }
-
+
fileprivate var collectionSelectionDidChangeHandler: ((Int) -> Void)? = nil
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let object = object as? NSCollectionView {
case power3
}
-fileprivate extension Selector {
- static let scrollViewDidEndLiveScrollNotification = #selector(HMShipViewController.scrollViewDidEndLiveScrollNotification(_:))
-}
-
class HMShipViewController: HMMainTabVIewItemViewController {
override var nibName: String! {
return "HMShipViewController"
shipController.addObserver(self, forKeyPath: NSSortDescriptorsBinding, context: nil)
shipController.addObserver(self, forKeyPath: "arrangedObjects", context: nil)
- let nc = NotificationCenter.default
- [expTableView,powerTableView,power2TableView,power3TableView].forEach {
- nc.addObserver(self, selector: .scrollViewDidEndLiveScrollNotification, name: .NSScrollViewDidEndLiveScroll, object: $0)
+ let tableViews = [expTableView,powerTableView,power2TableView,power3TableView]
+ tableViews
+ .forEach {
+ NotificationCenter.default
+ .addObserver(forName: .NSScrollViewDidEndLiveScroll, object: $0, queue: nil) { notification in
+ guard let target = notification.object as? NSScrollView else { return }
+ let visibleRect = target.documentVisibleRect
+ tableViews
+ .filter { $0 != target }
+ .forEach { $0?.documentView?.scrollToVisible(visibleRect) }
+ }
}
#if DEBUG
standardDeviationField.isHidden = false
return tableView.make(withIdentifier: identifier, owner: nil)
}
}
-
-extension HMShipViewController {
- func scrollViewDidEndLiveScrollNotification(_ notification: Notification) {
- guard let target = notification.object as? NSScrollView else { return }
- let visibleRect = target.documentVisibleRect
- [expTableView,powerTableView,power2TableView,power3TableView].forEach {
- if $0 != target {
- $0?.documentView?.scrollToVisible(visibleRect)
- }
- }
- }
-}