}
dynamic var time: NSNumber?
dynamic var state: NSNumber? {
- didSet {
- guard let state = state as? Int,
- let s = DockState(rawValue: state)
- else { return print("unknown State") }
- switch s {
- case .empty, .notOpen:
- isTasking = false
- didNotify = false
- case .hasShip, .completed:
- isTasking = true
- }
- }
+ didSet { updateState() }
}
+ dynamic var completeTime: NSNumber?
init?(number: Int) {
guard 1...4 ~= number else { return nil }
controller.automaticallyRearrangesObjects = true
controller.fetch(nil)
- bind("state", to: controller, withKeyPath: "selection.state")
+ bind(#keyPath(state), to: controller, withKeyPath: "selection.state")
+ bind(#keyPath(completeTime), to: controller, withKeyPath: "selection.complete_time")
+ }
+
+ private func updateState() {
+ guard let state = state as? Int,
+ let s = DockState(rawValue: state)
+ else { return print("unknown State") }
+ switch s {
+ case .empty, .notOpen:
+ isTasking = false
+ didNotify = false
+ case .hasShip, .completed:
+ isTasking = true
+ }
}
func update() {
time = nil
return
}
- guard let t = controller.value(forKeyPath: "selection.complete_time") as? Int
+ guard let completeTime = completeTime as? Int
else {
time = nil
return
}
- let compTime = TimeInterval(Int(t / 1_000))
- let now = Date()
- let diff = compTime - now.timeIntervalSince1970
+ let compTime = TimeInterval(Int(completeTime / 1_000))
+ let diff = compTime - Date().timeIntervalSince1970
realTime = diff < 0 ? 0 : diff
dynamic var missionId: NSNumber? {
didSet { updateState() }
}
+ dynamic var milliseconds: NSNumber?
+ dynamic var fleetName: String?
init?(number: Int) {
guard 2...4 ~= number else { return nil }
controller.automaticallyRearrangesObjects = true
controller.fetch(nil)
- bind("state", to: controller, withKeyPath: "selection.mission_0")
- bind("missionId", to: controller, withKeyPath: "selection.mission_1")
+ bind(#keyPath(state), to: controller, withKeyPath: "selection.mission_0")
+ bind(#keyPath(missionId), to: controller, withKeyPath: "selection.mission_1")
+ bind(#keyPath(milliseconds), to: controller, withKeyPath: "selection.mission_2")
+ bind(#keyPath(fleetName), to: controller, withKeyPath: "selection.name")
+ }
+ deinit {
+ unbind(#keyPath(state))
+ unbind(#keyPath(missionId))
+ unbind(#keyPath(milliseconds))
+ unbind(#keyPath(fleetName))
}
private func updateState() {
time = nil
return
}
- guard let t = controller.value(forKeyPath: "selection.mission_2") as? Int
+ guard let milliSeconds = milliseconds as? Int
else {
name = nil
time = nil
return
}
- let compTime = TimeInterval(Int(t / 1_000))
- let now = Date()
- let diff = compTime - now.timeIntervalSince1970
+ let compTime = TimeInterval(Int(milliSeconds / 1_000))
+ let diff = compTime - Date().timeIntervalSince1970
realTime = diff < 0 ? 0 : diff
if didNotify { return }
if diff >= 1 * 60 { return }
- guard let fleetName = controller.value(forKeyPath: "selection.name") as? String
+ guard let fleetName = fleetName
else { return }
let notification = NSUserNotification()
let format = NSLocalizedString("%@ Will Return From Mission.", comment: "%@ Will Return From Mission.")
dynamic var state: NSNumber? {
didSet { updateState() }
}
+ dynamic var shipId: NSNumber?
+ dynamic var completeTime: NSNumber?
init?(number: Int) {
guard 1...4 ~= number else { return nil }
controller.automaticallyRearrangesObjects = true
controller.fetch(nil)
- bind("state", to: controller, withKeyPath: "selection.state")
+ bind(#keyPath(state), to: controller, withKeyPath: "selection.state")
+ bind(#keyPath(shipId), to: controller, withKeyPath: "selection.ship_id")
+ bind(#keyPath(completeTime), to: controller, withKeyPath: "selection.complete_time")
+ }
+ deinit {
+ unbind(#keyPath(state))
+ unbind(#keyPath(shipId))
+ unbind(#keyPath(completeTime))
}
private func updateState() {
return
}
- guard let si = controller.value(forKeyPath: "selection.ship_id") as? Int,
- si != 0
+ guard let shipId = shipId as? Int,
+ shipId != 0
else { return }
- guard let ship = ServerDataStore.default.ship(byId: si)
+ guard let ship = ServerDataStore.default.ship(byId: shipId)
else {
name = "Unknown"
DispatchQueue(label: "NyukyoDockStatus")
time = nil
return
}
- guard let t = controller.value(forKeyPath: "selection.complete_time") as? Int
+ guard let completeTime = completeTime as? Int
else {
name = nil
time = nil
return
}
- let compTime = TimeInterval(Int(t / 1_000))
- let now = Date()
- let diff = compTime - now.timeIntervalSince1970
+ let compTime = TimeInterval(Int(completeTime / 1_000))
+ let diff = compTime - Date().timeIntervalSince1970
realTime = diff < 0 ? 0 : diff