2017-02-28 20:53:49 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Swifter
|
|
|
|
import RxSwift
|
|
|
|
|
|
|
|
fileprivate let defaults = UserDefaults.standard
|
|
|
|
|
2017-04-02 18:15:30 +03:00
|
|
|
class PrefService {
|
2017-02-28 20:53:49 +03:00
|
|
|
|
2017-03-29 22:36:12 +03:00
|
|
|
static let compatibleVersion = "168"
|
2017-03-11 19:00:55 +03:00
|
|
|
static let lastCompatibleVersion = "128"
|
2017-03-01 18:59:23 +03:00
|
|
|
|
2017-04-02 18:15:30 +03:00
|
|
|
let forMainWindow = PrefMainWindowService()
|
|
|
|
let forPrefPanes = PrefPaneService()
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PrefService {
|
|
|
|
|
|
|
|
class PrefMainWindowService: Service {
|
|
|
|
|
|
|
|
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
|
|
|
|
|
|
|
func apply(_ pair: Pair) {
|
|
|
|
guard case .close = pair.action.payload else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defaults.setValue(pair.state.dict(), forKey: PrefService.compatibleVersion)
|
2017-02-28 20:53:49 +03:00
|
|
|
}
|
2017-04-02 18:15:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class PrefPaneService: StateService {
|
2017-02-28 20:53:49 +03:00
|
|
|
|
2017-04-02 18:15:30 +03:00
|
|
|
typealias StateType = AppState
|
|
|
|
|
|
|
|
func apply(_ state: StateType) {
|
|
|
|
defaults.setValue(state.dict(), forKey: PrefService.compatibleVersion)
|
|
|
|
}
|
2017-02-28 20:53:49 +03:00
|
|
|
}
|
2017-04-02 18:15:30 +03:00
|
|
|
}
|