Commit 4d559151 authored by Davide De Rosa's avatar Davide De Rosa
Browse files

Encapsulate AppPreferences reset

- Theme
- PIA (OpenVPN) socket type
parent 9b0ad13b
......@@ -36,6 +36,8 @@ class AppPreferences {
private let defaults: UserDefaults
private var isTransitioningTheme = false
var wasLaunched: Bool {
get {
return defaults.bool(forKey: Entries.launched)
......@@ -170,7 +172,34 @@ class AppPreferences {
}
func reset() {
piaSocketType = nil
transitionTheme(to: .light)
}
// + (void)eraseForTesting;
func transitionTheme(to code: ThemeCode) {
guard !isTransitioningTheme else {
return
}
guard (code != AppPreferences.shared.currentThemeCode) else {
return
}
AppPreferences.shared.currentThemeCode = code
guard let window = UIApplication.shared.windows.first else {
fatalError("No window?")
}
isTransitioningTheme = true
UIView.animate(withDuration: AppConfiguration.Animations.duration, animations: {
window.alpha = 0.0
}, completion: { (success) in
code.apply(theme: Theme.current, reload: true)
UIView.animate(withDuration: AppConfiguration.Animations.duration) {
window.alpha = 1.0
self.isTransitioningTheme = false
}
})
}
}
......@@ -142,8 +142,6 @@ class SettingsViewController: AutolayoutViewController {
private var isContentBlockerEnabled = false
private var isTransitioningTheme = false
// private lazy var buttonConfirm = UIBarButtonItem(
// barButtonSystemItem: .save,
// target: self,
......@@ -233,7 +231,7 @@ class SettingsViewController: AutolayoutViewController {
// XXX: no need to bufferize app preferences
@objc private func toggleDarkMode(_ sender: UISwitch) {
transitionTheme(to: sender.isOn ? .dark : .light)
AppPreferences.shared.transitionTheme(to: sender.isOn ? .dark : .light)
}
@objc private func showContentBlockerTutorial() {
......@@ -327,8 +325,7 @@ class SettingsViewController: AutolayoutViewController {
pendingOpenVPNSocketType = AppPreferences.shared.piaSocketType
pendingOpenVPNConfiguration = currentOpenVPNConfiguration.builder()
AppPreferences.shared.piaSocketType = nil
transitionTheme(to: .light)
AppPreferences.shared.reset()
redisplaySettings()
reportUpdatedPreferences()
......@@ -521,31 +518,6 @@ class SettingsViewController: AutolayoutViewController {
pendingVPNAction = pendingPreferences.requiredVPNAction()
}
private func transitionTheme(to code: ThemeCode) {
guard !isTransitioningTheme else {
return
}
guard (code != AppPreferences.shared.currentThemeCode) else {
return
}
AppPreferences.shared.currentThemeCode = code
guard let window = UIApplication.shared.windows.first else {
fatalError("No window?")
}
isTransitioningTheme = true
UIView.animate(withDuration: AppConfiguration.Animations.duration, animations: {
window.alpha = 0.0
}, completion: { (success) in
code.apply(theme: Theme.current, reload: true)
UIView.animate(withDuration: AppConfiguration.Animations.duration) {
window.alpha = 1.0
self.isTransitioningTheme = false
}
})
}
// MARK: ModalController
override func dismissModal() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment