Add current user to SettingsView
This commit is contained in:
parent
4d40b0c083
commit
b9b61fa7eb
@ -12,16 +12,18 @@ class AuthStateController: ObservableObject {
|
|||||||
@Published var serverUrl: URL?
|
@Published var serverUrl: URL?
|
||||||
@Published var authToken: String?
|
@Published var authToken: String?
|
||||||
@Published var userId: String?
|
@Published var userId: String?
|
||||||
|
@Published var username: String?
|
||||||
|
|
||||||
private let defaults = UserDefaults.standard
|
private let defaults = UserDefaults.standard
|
||||||
|
|
||||||
static let shared = AuthStateController()
|
static let shared = AuthStateController()
|
||||||
|
|
||||||
init(loggedIn: Bool = false, serverUrl: URL? = nil, authToken: String? = nil, userId: String? = nil) {
|
init(loggedIn: Bool = false, serverUrl: URL? = nil, authToken: String? = nil, userId: String? = nil, username: String? = nil) {
|
||||||
self.loggedIn = loggedIn
|
self.loggedIn = loggedIn
|
||||||
self.serverUrl = serverUrl
|
self.serverUrl = serverUrl
|
||||||
self.authToken = authToken
|
self.authToken = authToken
|
||||||
self.userId = userId
|
self.userId = userId
|
||||||
|
self.username = username
|
||||||
}
|
}
|
||||||
|
|
||||||
func load() {
|
func load() {
|
||||||
@ -35,6 +37,9 @@ class AuthStateController: ObservableObject {
|
|||||||
if let oldUserId = defaults.string(forKey: "AuthState_userId") {
|
if let oldUserId = defaults.string(forKey: "AuthState_userId") {
|
||||||
self.userId = oldUserId
|
self.userId = oldUserId
|
||||||
}
|
}
|
||||||
|
if let oldUsername = defaults.string(forKey: "AuthState_username") {
|
||||||
|
self.username = oldUsername
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func save() {
|
func save() {
|
||||||
@ -42,5 +47,6 @@ class AuthStateController: ObservableObject {
|
|||||||
defaults.set(self.serverUrl, forKey: "AuthState_serverUrl")
|
defaults.set(self.serverUrl, forKey: "AuthState_serverUrl")
|
||||||
defaults.set(self.authToken, forKey: "AuthState_authToken")
|
defaults.set(self.authToken, forKey: "AuthState_authToken")
|
||||||
defaults.set(self.userId, forKey: "AuthState_userId")
|
defaults.set(self.userId, forKey: "AuthState_userId")
|
||||||
|
defaults.set(self.username, forKey: "AuthState_username")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,7 @@ extension JellyfinClientController {
|
|||||||
self.authState.loggedIn = true
|
self.authState.loggedIn = true
|
||||||
self.authState.authToken = res.value.accessToken
|
self.authState.authToken = res.value.accessToken
|
||||||
self.authState.userId = res.value.user?.id
|
self.authState.userId = res.value.user?.id
|
||||||
|
self.authState.username = username
|
||||||
self.authState.save()
|
self.authState.save()
|
||||||
|
|
||||||
self.setToken(token: self.authState.authToken ?? "")
|
self.setToken(token: self.authState.authToken ?? "")
|
||||||
|
@ -18,17 +18,14 @@ struct SettingsView: View {
|
|||||||
NavigationStack {
|
NavigationStack {
|
||||||
Form {
|
Form {
|
||||||
Section() {
|
Section() {
|
||||||
AppearancePicker()
|
LabeledContent("Username") {
|
||||||
} header: {
|
Text("\(authState.username ?? "---")")
|
||||||
Text("Accessibility")
|
.textSelection(.enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
LabeledContent("Auth Token") {
|
||||||
NavigationLink {
|
Text("\(authState.authToken ?? "---")")
|
||||||
ConsoleView()
|
.textSelection(.enabled)
|
||||||
.closeButtonHidden()
|
|
||||||
} label: {
|
|
||||||
Text("Logs")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
@ -37,6 +34,25 @@ struct SettingsView: View {
|
|||||||
} label: {
|
} label: {
|
||||||
Text("Sign out")
|
Text("Sign out")
|
||||||
}
|
}
|
||||||
|
} header: {
|
||||||
|
Text("Current User")
|
||||||
|
}
|
||||||
|
|
||||||
|
Section() {
|
||||||
|
AppearancePicker()
|
||||||
|
} header: {
|
||||||
|
Text("Accessibility")
|
||||||
|
}
|
||||||
|
|
||||||
|
Section() {
|
||||||
|
NavigationLink {
|
||||||
|
ConsoleView()
|
||||||
|
.closeButtonHidden()
|
||||||
|
} label: {
|
||||||
|
Text("Logs")
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
Text("Debug")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Settings")
|
.navigationTitle("Settings")
|
||||||
|
Loading…
Reference in New Issue
Block a user