2017-02-28 20:53:49 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
fileprivate let defaults = UserDefaults.standard
|
|
|
|
|
2017-04-02 18:15:30 +03:00
|
|
|
class PrefService {
|
2017-02-28 20:53:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
typealias MainWindowPair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
|
|
|
|
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-08-15 18:48:04 +03:00
|
|
|
// The following should only be used when Cmd-Q'ing
|
|
|
|
func applyPref(from appState: AppState) {
|
|
|
|
defaults.setValue(appState.dict(), forKey: PrefService.compatibleVersion)
|
|
|
|
}
|
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
func applyPref<ActionType>(_ pair: StateActionPair<AppState, ActionType>) {
|
|
|
|
defaults.setValue(pair.state.dict(), forKey: PrefService.compatibleVersion)
|
2017-04-02 18:15:30 +03:00
|
|
|
}
|
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
func applyMainWindow(_ pair: MainWindowPair) {
|
|
|
|
guard case .close = pair.action.payload else {
|
|
|
|
return
|
2017-04-02 18:15:30 +03:00
|
|
|
}
|
2017-04-30 10:25:15 +03:00
|
|
|
|
|
|
|
defaults.setValue(pair.state.dict(), forKey: PrefService.compatibleVersion)
|
2017-02-28 20:53:49 +03:00
|
|
|
}
|
2017-04-30 10:25:15 +03:00
|
|
|
}
|