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()
|
showOnboardingUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
|
||||||
|
|
||||||
window!.makeKeyAndVisible()
|
window!.makeKeyAndVisible()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -94,6 +96,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
window!.rootViewController = onboarding
|
window!.rootViewController = onboarding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func onUserLoggedOut() {
|
||||||
|
showOnboardingUI()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AppDelegate: OnboardingViewControllerDelegate {
|
extension AppDelegate: OnboardingViewControllerDelegate {
|
||||||
|
|
|
@ -68,3 +68,7 @@ class LocalData {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static let userLoggedOut = Notification.Name("userLoggedOut")
|
||||||
|
}
|
||||||
|
|
|
@ -8,10 +8,23 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PreferencesView : View {
|
struct PreferencesView : View {
|
||||||
|
@State private var showingLogoutConfirmation = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||||
// NavigationView {
|
// NavigationView {
|
||||||
List {
|
List {
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section {
|
||||||
NavigationLink(destination: AppearancePrefsView()) {
|
NavigationLink(destination: AppearancePrefsView()) {
|
||||||
Text("Appearance")
|
Text("Appearance")
|
||||||
}
|
}
|
||||||
|
@ -25,6 +38,7 @@ struct PreferencesView : View {
|
||||||
Text("Advanced")
|
Text("Advanced")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.listStyle(GroupedListStyle())
|
.listStyle(GroupedListStyle())
|
||||||
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
|
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
|
@ -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
|
#if DEBUG
|
||||||
|
|
Loading…
Reference in New Issue