forked from shadowfacts/Tusker
Add logout button to preferences
This commit is contained in:
parent
bc2e3c37a0
commit
65ceb83d2d
|
@ -22,6 +22,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
showOnboardingUI()
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
|
||||
|
||||
window!.makeKeyAndVisible()
|
||||
|
||||
return true
|
||||
|
@ -94,6 +96,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
window!.rootViewController = onboarding
|
||||
}
|
||||
|
||||
@objc func onUserLoggedOut() {
|
||||
showOnboardingUI()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension AppDelegate: OnboardingViewControllerDelegate {
|
||||
|
|
|
@ -68,3 +68,7 @@ class LocalData {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let userLoggedOut = Notification.Name("userLoggedOut")
|
||||
}
|
||||
|
|
|
@ -8,21 +8,35 @@
|
|||
import SwiftUI
|
||||
|
||||
struct PreferencesView : View {
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
var body: some View {
|
||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||
// NavigationView {
|
||||
List {
|
||||
NavigationLink(destination: AppearancePrefsView()) {
|
||||
Text("Appearance")
|
||||
Section {
|
||||
Button(action: {
|
||||
self.showingLogoutConfirmation = true
|
||||
}) {
|
||||
Text("Logout")
|
||||
}.alert(isPresented: $showingLogoutConfirmation) {
|
||||
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: BehaviorPrefsView()) {
|
||||
Text("Behavior")
|
||||
}
|
||||
NavigationLink(destination: WellnessPrefsView()) {
|
||||
Text("Digital Wellness")
|
||||
}
|
||||
NavigationLink(destination: AdvancedPrefsView()) {
|
||||
Text("Advanced")
|
||||
|
||||
Section {
|
||||
NavigationLink(destination: AppearancePrefsView()) {
|
||||
Text("Appearance")
|
||||
}
|
||||
NavigationLink(destination: BehaviorPrefsView()) {
|
||||
Text("Behavior")
|
||||
}
|
||||
NavigationLink(destination: WellnessPrefsView()) {
|
||||
Text("Digital Wellness")
|
||||
}
|
||||
NavigationLink(destination: AdvancedPrefsView()) {
|
||||
Text("Advanced")
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(GroupedListStyle())
|
||||
|
@ -33,6 +47,15 @@ struct PreferencesView : View {
|
|||
}
|
||||
// }
|
||||
}
|
||||
|
||||
func logoutPressed() {
|
||||
LocalData.shared.onboardingComplete = false
|
||||
LocalData.shared.instanceURL = nil
|
||||
LocalData.shared.clientID = nil
|
||||
LocalData.shared.clientSecret = nil
|
||||
LocalData.shared.accessToken = nil
|
||||
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
|
Loading…
Reference in New Issue