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" : { "setting.appearence.displayed-name" : {
"localizations" : { "localizations" : {
"en" : { "en" : {

View File

@ -42,6 +42,21 @@ struct AppearenceView: View {
.pickerStyle(.inline) .pickerStyle(.inline)
.listRowThreaded() .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 { if userPreferences.showExperimental {
Section(header: Text("experimental")) { Section(header: Text("experimental")) {
Toggle(LocalizedStringKey("setting.appearence.reply-symbols"), isOn: $userPreferences.experimental.replySymbol) Toggle(LocalizedStringKey("setting.appearence.reply-symbols"), isOn: $userPreferences.experimental.replySymbol)
@ -54,34 +69,13 @@ struct AppearenceView: View {
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden() .navigationBarBackButtonHidden()
.onAppear { .onAppear {
do { loadOld()
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()
}
} }
.toolbar { .toolbar {
ToolbarItem(placement: .cancellationAction) { ToolbarItem(placement: .cancellationAction) {
Button { Button {
do { loadOld()
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.displayedName = oldPreferences.displayedName
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
dismiss() dismiss()
} catch {
print(error)
dismiss()
}
} label: { } label: {
Text("settings.cancel") 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 { #Preview {