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
|
|
|
|
import Models
|
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-12-01 09:05:26 +01:00
|
|
|
|
2022-12-29 17:22:07 +01:00
|
|
|
struct SettingsTabs: View {
|
2023-01-08 14:16:43 +01:00
|
|
|
@EnvironmentObject private var pushNotifications: PushNotificationsService
|
2023-01-06 17:14:34 +01:00
|
|
|
@EnvironmentObject private var preferences: UserPreferences
|
2022-12-01 09:05:26 +01:00
|
|
|
@EnvironmentObject private var client: Client
|
2022-12-28 08:06:46 +01:00
|
|
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
2022-12-01 09:05:26 +01:00
|
|
|
@EnvironmentObject private var appAccountsManager: AppAccountsManager
|
2022-12-24 14:55:04 +01:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-17 15:14:50 +01:00
|
|
|
@StateObject private var routerPath = RouterPath()
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
@State private var addAccountSheetPresented = false
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-10 06:58:50 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-01-17 11:36:01 +01: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
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle(Text("settings.title"))
|
2022-12-01 09:05:26 +01:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2023-01-02 17:18:16 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor, for: .navigationBar)
|
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()
|
|
|
|
.environmentObject(routerPath)
|
2023-01-10 06:58:50 +01:00
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
|
|
|
if popToRootTab == .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-01-10 06:58:50 +01:00
|
|
|
AppAccountView(viewModel: .init(appAccount: account))
|
2022-12-30 08:36:22 +01:00
|
|
|
}
|
|
|
|
.onDelete { indexSet in
|
|
|
|
if let index = indexSet.first {
|
|
|
|
let account = appAccountsManager.availableAccounts[index]
|
2023-01-08 14:16:43 +01:00
|
|
|
if let token = account.oauthToken {
|
|
|
|
Task {
|
|
|
|
await pushNotifications.deleteSubscriptions(accounts: [.init(server: account.server, token: token)])
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 08:36:22 +01:00
|
|
|
appAccountsManager.delete(account: account)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 14:07:58 +01:00
|
|
|
addAccountButton
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
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-08 10:22:52 +01:00
|
|
|
NavigationLink(destination: PushNotificationsView()) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.general.push-notifications", systemImage: "bell.and.waves.left.and.right")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
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-01-06 17:14:34 +01:00
|
|
|
NavigationLink(destination: remoteLocalTimelinesView) {
|
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
|
|
|
}
|
2023-01-19 11:59:12 +01:00
|
|
|
if !ProcessInfo.processInfo.isiOSAppOnMac {
|
|
|
|
Picker(selection: $preferences.preferredBrowser) {
|
|
|
|
ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in
|
|
|
|
switch browser {
|
|
|
|
case .inAppSafari:
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.general.browser.in-app").tag(browser)
|
2023-01-19 11:59:12 +01:00
|
|
|
case .safari:
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.general.browser.system").tag(browser)
|
2023-01-19 11:59:12 +01:00
|
|
|
}
|
2023-01-08 19:56:16 +01:00
|
|
|
}
|
2023-01-19 11:59:12 +01:00
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.general.browser", systemImage: "network")
|
2023-01-08 19:56:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-24 14:55:04 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
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-01-17 21:08:05 +01:00
|
|
|
if !ProcessInfo.processInfo.isiOSAppOnMac {
|
|
|
|
NavigationLink(destination: IconSelectorView()) {
|
|
|
|
Label {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.app.icon")
|
2023-01-17 21:08:05 +01:00
|
|
|
} icon: {
|
|
|
|
if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
|
|
|
|
Image(uiImage: .init(named: icon.iconName)!)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
2022-12-27 21:35:41 +01:00
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
.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) {
|
|
|
|
Label("Rate Ice Cubes", systemImage: "link")
|
|
|
|
}
|
|
|
|
.tint(theme.labelColor)
|
|
|
|
}
|
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 {
|
|
|
|
Text("App Version: \(appVersion)").frame(maxWidth: .infinity, alignment: .center)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
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-01-17 11:36:01 +01:00
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
private var remoteLocalTimelinesView: some View {
|
|
|
|
Form {
|
|
|
|
ForEach(preferences.remoteLocalTimelines, id: \.self) { server in
|
|
|
|
Text(server)
|
|
|
|
}.onDelete { indexes in
|
|
|
|
if let index = indexes.first {
|
|
|
|
_ = preferences.remoteLocalTimelines.remove(at: index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-03 14:42:09 +01:00
|
|
|
Button {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.presentedSheet = .addRemoteLocalTimeline
|
2023-01-03 14:42:09 +01:00
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.timeline.add", systemImage: "badge.plus.radiowaves.right")
|
2023-01-03 14:42:09 +01:00
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-03 14:42:09 +01:00
|
|
|
}
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle("settings.general.remote-timelines")
|
2023-01-06 17:14:34 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
|
|
|
}
|