Browser setting in "Appearence"

This commit is contained in:
Lumaa 2024-01-26 14:38:43 +01:00
parent 81e62bb2bc
commit 095c811572
2 changed files with 63 additions and 24 deletions

View File

@ -277,6 +277,36 @@
}
}
},
"setting.appearence.browser" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open links"
}
}
}
},
"setting.appearence.browser.in-app" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "in-app"
}
}
}
},
"setting.appearence.browser.out-app" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "in a browser"
}
}
}
},
"setting.appearence.displayed-name" : {
"localizations" : {
"en" : {

View File

@ -42,6 +42,21 @@ struct AppearenceView: View {
.pickerStyle(.inline)
.listRowThreaded()
Picker(LocalizedStringKey("setting.appearence.browser"), selection: $userPreferences.browserType) {
ForEach(UserPreferences.BrowserType.allCases, id: \.self) { type in
switch (type) {
case .inApp:
Text("setting.appearence.browser.in-app")
.tag(UserPreferences.BrowserType.inApp)
case .outApp:
Text("setting.appearence.browser.out-app")
.tag(UserPreferences.BrowserType.outApp)
}
}
}
.pickerStyle(.inline)
.listRowThreaded()
if userPreferences.showExperimental {
Section(header: Text("experimental")) {
Toggle(LocalizedStringKey("setting.appearence.reply-symbols"), isOn: $userPreferences.experimental.replySymbol)
@ -54,34 +69,13 @@ struct AppearenceView: View {
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden()
.onAppear {
do {
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.displayedName = oldPreferences.displayedName
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
} catch {
print(error)
dismiss()
}
loadOld()
}
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button {
do {
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.displayedName = oldPreferences.displayedName
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
dismiss()
} catch {
print(error)
dismiss()
}
loadOld()
dismiss()
} label: {
Text("settings.cancel")
}
@ -101,6 +95,21 @@ struct AppearenceView: View {
}
}
}
private func loadOld() {
do {
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.displayedName = oldPreferences.displayedName
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
userPreferences.browserType = oldPreferences.browserType
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
} catch {
print(error)
dismiss()
}
}
}
#Preview {