2022-12-01 09:05:26 +01:00
|
|
|
import Account
|
2023-01-12 18:17:21 +01:00
|
|
|
import AppAccount
|
2023-01-17 11:36:01 +01:00
|
|
|
import DesignSystem
|
|
|
|
import Env
|
2023-01-27 14:53:05 +09:00
|
|
|
import Foundation
|
2023-01-17 11:36:01 +01:00
|
|
|
import Models
|
|
|
|
import Network
|
2023-02-26 06:45:57 +01:00
|
|
|
import Nuke
|
2023-10-01 09:37:09 +02:00
|
|
|
import SwiftData
|
2023-01-17 11:36:01 +01:00
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-12-01 09:05:26 +01:00
|
|
|
|
2023-09-19 09:18:20 +02:00
|
|
|
@MainActor
|
2022-12-29 17:22:07 +01:00
|
|
|
struct SettingsTabs: View {
|
2023-01-26 07:34:29 +01:00
|
|
|
@Environment(\.dismiss) private var dismiss
|
2023-12-29 18:50:53 +01:00
|
|
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
2023-01-27 20:36:40 +01:00
|
|
|
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(PushNotificationsService.self) private var pushNotifications
|
2023-09-19 09:18:20 +02:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@Environment(CurrentInstance.self) private var currentInstance
|
|
|
|
@Environment(AppAccountsManager.self) private var appAccountsManager
|
2023-09-18 21:03:52 +02:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-09-18 07:01:23 +02:00
|
|
|
@State private var routerPath = RouterPath()
|
2022-12-29 14:07:58 +01:00
|
|
|
@State private var addAccountSheetPresented = false
|
2023-02-16 07:19:20 +01:00
|
|
|
@State private var isEditingAccount = false
|
2023-02-23 18:43:09 +01:00
|
|
|
@State private var cachedRemoved = false
|
2023-09-22 08:32:13 +02:00
|
|
|
@State private var timelineCache = TimelineCache()
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-10 06:58:50 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-12-18 08:22:59 +01:00
|
|
|
|
2023-11-18 11:58:04 +01:00
|
|
|
let isModal: Bool
|
2023-10-01 09:37:09 +02:00
|
|
|
|
2022-12-01 09:05:26 +01:00
|
|
|
var body: some View {
|
2023-01-17 15:14:50 +01:00
|
|
|
NavigationStack(path: $routerPath.path) {
|
2022-12-01 09:05:26 +01:00
|
|
|
Form {
|
2022-12-04 09:50:25 +01:00
|
|
|
appSection
|
2022-12-29 07:00:00 +01:00
|
|
|
accountsSection
|
2023-01-06 17:14:34 +01:00
|
|
|
generalSection
|
2023-01-23 20:45:18 +01:00
|
|
|
otherSections
|
2023-02-23 18:43:09 +01:00
|
|
|
cacheSection
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2022-12-29 10:39:34 +01:00
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle(Text("settings.title"))
|
2022-12-01 09:05:26 +01:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2023-01-22 06:53:18 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
|
2023-01-26 07:34:29 +01:00
|
|
|
.toolbar {
|
2024-01-02 09:50:50 -08:00
|
|
|
if isModal {
|
2023-01-26 07:34:29 +01:00
|
|
|
ToolbarItem {
|
2023-02-22 22:12:10 +01:00
|
|
|
Button {
|
2023-01-26 07:34:29 +01:00
|
|
|
dismiss()
|
2023-02-22 22:12:10 +01:00
|
|
|
} label: {
|
|
|
|
Text("action.done").bold()
|
2023-01-26 07:34:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-02 09:50:50 -08:00
|
|
|
if UIDevice.current.userInterfaceIdiom == .pad, !preferences.showiPadSecondaryColumn, !isModal {
|
2023-02-21 13:37:31 +01:00
|
|
|
SecondaryColumnToolbarItem()
|
|
|
|
}
|
2023-01-26 07:34:29 +01:00
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
.withAppRouter()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2023-01-01 09:19:00 +01:00
|
|
|
.onAppear {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.client = client
|
2023-01-01 09:19:00 +01:00
|
|
|
}
|
2022-12-01 09:05:26 +01:00
|
|
|
.task {
|
|
|
|
if appAccountsManager.currentAccount.oauthToken != nil {
|
2022-12-28 08:06:46 +01:00
|
|
|
await currentInstance.fetchCurrentInstance()
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
.withSafariRouter()
|
2023-09-18 07:01:23 +02:00
|
|
|
.environment(routerPath)
|
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
|
|
|
|
if newValue == .notifications {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.path = []
|
2023-01-10 06:58:50 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-29 07:00:00 +01:00
|
|
|
private var accountsSection: some View {
|
2023-01-19 18:14:08 +01:00
|
|
|
Section("settings.section.accounts") {
|
2022-12-30 08:36:22 +01:00
|
|
|
ForEach(appAccountsManager.availableAccounts) { account in
|
2023-02-16 07:19:20 +01:00
|
|
|
HStack {
|
|
|
|
if isEditingAccount {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
await logoutAccount(account: account)
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "trash")
|
|
|
|
.renderingMode(.template)
|
|
|
|
.tint(.red)
|
|
|
|
}
|
|
|
|
}
|
2024-01-05 18:57:02 +01:00
|
|
|
AppAccountView(viewModel: .init(appAccount: account), isParentPresented: .constant(false))
|
2023-02-16 07:19:20 +01:00
|
|
|
}
|
2022-12-30 08:36:22 +01:00
|
|
|
}
|
|
|
|
.onDelete { indexSet in
|
|
|
|
if let index = indexSet.first {
|
|
|
|
let account = appAccountsManager.availableAccounts[index]
|
2023-02-16 07:19:20 +01:00
|
|
|
Task {
|
|
|
|
await logoutAccount(account: account)
|
2023-01-08 14:16:43 +01:00
|
|
|
}
|
2022-12-30 08:36:22 +01:00
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-02-16 07:19:20 +01:00
|
|
|
if !appAccountsManager.availableAccounts.isEmpty {
|
|
|
|
editAccountButton
|
|
|
|
}
|
2022-12-29 14:07:58 +01:00
|
|
|
addAccountButton
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-02-18 07:26:48 +01:00
|
|
|
|
2023-02-16 07:19:20 +01:00
|
|
|
private func logoutAccount(account: AppAccount) async {
|
|
|
|
if let token = account.oauthToken,
|
|
|
|
let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token })
|
|
|
|
{
|
|
|
|
let client = Client(server: account.server, oauthToken: token)
|
2023-09-22 08:32:13 +02:00
|
|
|
await timelineCache.clearCache(for: client.id)
|
2023-02-16 07:19:20 +01:00
|
|
|
await sub.deleteSubscription()
|
|
|
|
appAccountsManager.delete(account: account)
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
@ViewBuilder
|
|
|
|
private var generalSection: some View {
|
2023-01-19 18:14:08 +01:00
|
|
|
Section("settings.section.general") {
|
2023-01-06 17:14:34 +01:00
|
|
|
if let instanceData = currentInstance.instance {
|
|
|
|
NavigationLink(destination: InstanceInfoView(instance: instanceData)) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.general.instance", systemImage: "server.rack")
|
2022-12-31 12:29:19 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
NavigationLink(destination: DisplaySettingsView()) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.general.display", systemImage: "paintpalette")
|
2023-01-04 17:48:02 +01:00
|
|
|
}
|
2023-02-12 16:29:41 +01:00
|
|
|
if HapticManager.shared.supportsHaptics {
|
|
|
|
NavigationLink(destination: HapticSettingsView()) {
|
|
|
|
Label("settings.general.haptic", systemImage: "waveform.path")
|
2023-02-06 10:53:27 -06:00
|
|
|
}
|
2023-02-12 16:29:41 +01:00
|
|
|
}
|
2024-01-06 10:51:47 +01:00
|
|
|
NavigationLink(destination: RemoteTimelinesSettingView()) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.general.remote-timelines", systemImage: "dot.radiowaves.right")
|
2022-12-24 14:55:04 +01:00
|
|
|
}
|
2024-01-06 10:51:47 +01:00
|
|
|
NavigationLink(destination: TagsGroupSettingView()) {
|
2023-07-19 07:46:25 +02:00
|
|
|
Label("timeline.filter.tag-groups", systemImage: "number")
|
|
|
|
}
|
2024-01-06 10:51:47 +01:00
|
|
|
NavigationLink(destination: RecenTagsSettingView()) {
|
|
|
|
Label("settings.general.recent-tags", systemImage: "clock")
|
|
|
|
}
|
2023-01-25 05:28:16 +00:00
|
|
|
NavigationLink(destination: ContentSettingsView()) {
|
2023-02-21 06:04:17 +00:00
|
|
|
Label("settings.general.content", systemImage: "rectangle.stack")
|
2023-01-25 05:28:16 +00:00
|
|
|
}
|
2023-02-11 21:48:08 +01:00
|
|
|
NavigationLink(destination: SwipeActionsSettingsView()) {
|
|
|
|
Label("settings.general.swipeactions", systemImage: "hand.draw")
|
2023-03-14 18:50:19 +01:00
|
|
|
}
|
2023-12-29 18:50:53 +01:00
|
|
|
if UIDevice.current.userInterfaceIdiom == .phone || horizontalSizeClass == .compact {
|
2023-12-28 11:26:00 +01:00
|
|
|
NavigationLink(destination: TabbarEntriesSettingsView()) {
|
|
|
|
Label("settings.general.tabbarEntries", systemImage: "platter.filled.bottom.iphone")
|
|
|
|
}
|
|
|
|
}
|
2023-03-14 18:50:19 +01:00
|
|
|
NavigationLink(destination: TranslationSettingsView()) {
|
|
|
|
Label("settings.general.translate", systemImage: "captions.bubble")
|
2023-02-11 21:48:08 +01:00
|
|
|
}
|
2023-11-20 11:27:58 +03:00
|
|
|
#if !targetEnvironment(macCatalyst)
|
2023-12-18 08:22:59 +01:00
|
|
|
Link(destination: URL(string: UIApplication.openSettingsURLString)!) {
|
|
|
|
Label("settings.system", systemImage: "gear")
|
|
|
|
}
|
|
|
|
.tint(theme.labelColor)
|
2023-11-20 11:27:58 +03:00
|
|
|
#endif
|
2023-01-23 20:45:18 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-01-23 20:45:18 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-01-23 20:45:18 +01:00
|
|
|
}
|
2023-01-25 13:02:28 +01:00
|
|
|
|
2023-09-19 09:18:20 +02:00
|
|
|
@ViewBuilder
|
2023-01-23 20:45:18 +01:00
|
|
|
private var otherSections: some View {
|
2023-09-19 09:18:20 +02:00
|
|
|
@Bindable var preferences = preferences
|
2023-12-27 16:27:31 +01:00
|
|
|
Section {
|
2023-12-18 08:22:59 +01:00
|
|
|
#if !targetEnvironment(macCatalyst)
|
|
|
|
Picker(selection: $preferences.preferredBrowser) {
|
|
|
|
ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in
|
|
|
|
switch browser {
|
|
|
|
case .inAppSafari:
|
|
|
|
Text("settings.general.browser.in-app").tag(browser)
|
|
|
|
case .safari:
|
|
|
|
Text("settings.general.browser.system").tag(browser)
|
|
|
|
}
|
2023-01-08 19:56:16 +01:00
|
|
|
}
|
2023-12-18 08:22:59 +01:00
|
|
|
} label: {
|
|
|
|
Label("settings.general.browser", systemImage: "network")
|
2023-02-03 07:04:00 +01:00
|
|
|
}
|
2023-12-18 08:22:59 +01:00
|
|
|
Toggle(isOn: $preferences.inAppBrowserReaderView) {
|
|
|
|
Label("settings.general.browser.in-app.readerview", systemImage: "doc.plaintext")
|
|
|
|
}
|
|
|
|
.disabled(preferences.preferredBrowser != PreferredBrowser.inAppSafari)
|
|
|
|
#endif
|
2023-01-23 20:45:18 +01:00
|
|
|
Toggle(isOn: $preferences.isOpenAIEnabled) {
|
|
|
|
Label("settings.other.hide-openai", systemImage: "faxmachine")
|
|
|
|
}
|
2023-01-24 21:44:33 +01:00
|
|
|
Toggle(isOn: $preferences.isSocialKeyboardEnabled) {
|
|
|
|
Label("settings.other.social-keyboard", systemImage: "keyboard")
|
|
|
|
}
|
2023-02-28 18:55:08 +01:00
|
|
|
Toggle(isOn: $preferences.soundEffectEnabled) {
|
|
|
|
Label("settings.other.sound-effect", systemImage: "hifispeaker")
|
|
|
|
}
|
2023-12-01 08:51:19 +01:00
|
|
|
Toggle(isOn: $preferences.fastRefreshEnabled) {
|
|
|
|
Label("settings.other.fast-refresh", systemImage: "arrow.clockwise")
|
|
|
|
}
|
2023-12-27 16:27:31 +01:00
|
|
|
} header: {
|
|
|
|
Text("settings.section.other")
|
|
|
|
} footer: {
|
|
|
|
Text("settings.section.other.footer")
|
2022-12-24 14:55:04 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2022-12-24 14:55:04 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-04 09:50:25 +01:00
|
|
|
private var appSection: some View {
|
2023-01-21 09:38:30 +01:00
|
|
|
Section {
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
2023-12-18 08:22:59 +01:00
|
|
|
NavigationLink(destination: IconSelectorView()) {
|
|
|
|
Label {
|
|
|
|
Text("settings.app.icon")
|
|
|
|
} icon: {
|
|
|
|
let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon")
|
2023-12-26 13:24:39 +01:00
|
|
|
Image(uiImage: .init(named: icon.appIconName)!)
|
2023-12-18 08:22:59 +01:00
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-12-18 08:22:59 +01:00
|
|
|
#endif
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-08 19:56:16 +01:00
|
|
|
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp")!) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.app.source", systemImage: "link")
|
2023-01-08 19:56:16 +01:00
|
|
|
}
|
2023-03-17 16:38:50 +11:00
|
|
|
.accessibilityRemoveTraits(.isButton)
|
2023-01-08 19:56:16 +01:00
|
|
|
.tint(theme.labelColor)
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-07 13:44:13 +01:00
|
|
|
NavigationLink(destination: SupportAppView()) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.app.support", systemImage: "wand.and.stars")
|
2022-12-23 16:21:31 +01:00
|
|
|
}
|
2023-01-22 06:38:30 +01:00
|
|
|
|
2023-01-21 07:16:20 +01:00
|
|
|
if let reviewURL = URL(string: "https://apps.apple.com/app/id\(AppInfo.appStoreAppId)?action=write-review") {
|
|
|
|
Link(destination: reviewURL) {
|
2023-01-22 11:16:48 +01:00
|
|
|
Label("settings.rate", systemImage: "link")
|
2023-01-21 07:16:20 +01:00
|
|
|
}
|
2023-03-17 16:38:50 +11:00
|
|
|
.accessibilityRemoveTraits(.isButton)
|
2023-01-21 07:16:20 +01:00
|
|
|
.tint(theme.labelColor)
|
|
|
|
}
|
2023-02-03 06:03:32 +00:00
|
|
|
|
|
|
|
NavigationLink(destination: AboutView()) {
|
|
|
|
Label("settings.app.about", systemImage: "info.circle")
|
|
|
|
}
|
|
|
|
|
2023-01-21 09:38:30 +01:00
|
|
|
} header: {
|
2023-01-22 06:38:30 +01:00
|
|
|
Text("settings.section.app")
|
2023-01-21 09:38:30 +01:00
|
|
|
} footer: {
|
2023-01-22 06:38:30 +01:00
|
|
|
if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
|
2023-01-23 13:24:49 +01:00
|
|
|
Text("settings.section.app.footer \(appVersion)").frame(maxWidth: .infinity, alignment: .center)
|
2023-01-22 06:38:30 +01:00
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
private var addAccountButton: some View {
|
2022-12-01 09:05:26 +01:00
|
|
|
Button {
|
2022-12-29 14:07:58 +01:00
|
|
|
addAccountSheetPresented.toggle()
|
2022-12-01 09:05:26 +01:00
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.account.add")
|
2022-12-29 14:07:58 +01:00
|
|
|
}
|
|
|
|
.sheet(isPresented: $addAccountSheetPresented) {
|
|
|
|
AddAccountView()
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-18 07:26:48 +01:00
|
|
|
|
2023-02-16 07:19:20 +01:00
|
|
|
private var editAccountButton: some View {
|
|
|
|
Button(role: isEditingAccount ? .none : .destructive) {
|
|
|
|
withAnimation {
|
|
|
|
isEditingAccount.toggle()
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
if isEditingAccount {
|
|
|
|
Text("action.done")
|
|
|
|
} else {
|
|
|
|
Text("account.action.logout")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-19 07:46:25 +02:00
|
|
|
|
2023-02-23 18:43:09 +01:00
|
|
|
private var cacheSection: some View {
|
|
|
|
Section("settings.section.cache") {
|
|
|
|
if cachedRemoved {
|
|
|
|
Text("action.done")
|
|
|
|
.transition(.move(edge: .leading))
|
|
|
|
} else {
|
|
|
|
Button("settings.cache-media.clear", role: .destructive) {
|
|
|
|
ImagePipeline.shared.cache.removeAll()
|
|
|
|
withAnimation {
|
|
|
|
cachedRemoved = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-02-23 18:43:09 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-02-23 18:43:09 +01:00
|
|
|
}
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|