2022-12-01 08:05:26 +00:00
|
|
|
import Account
|
2023-01-12 17:17:21 +00:00
|
|
|
import AppAccount
|
2023-01-17 10:36:01 +00:00
|
|
|
import DesignSystem
|
|
|
|
import Env
|
|
|
|
import Models
|
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-12-01 08:05:26 +00:00
|
|
|
|
2022-12-29 16:22:07 +00:00
|
|
|
struct SettingsTabs: View {
|
2023-01-08 13:16:43 +00:00
|
|
|
@EnvironmentObject private var pushNotifications: PushNotificationsService
|
2023-01-06 16:14:34 +00:00
|
|
|
@EnvironmentObject private var preferences: UserPreferences
|
2022-12-01 08:05:26 +00:00
|
|
|
@EnvironmentObject private var client: Client
|
2022-12-28 07:06:46 +00:00
|
|
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
2022-12-01 08:05:26 +00:00
|
|
|
@EnvironmentObject private var appAccountsManager: AppAccountsManager
|
2022-12-24 13:55:04 +00:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-01 08:19:00 +00:00
|
|
|
@StateObject private var routeurPath = RouterPath()
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-29 13:07:58 +00:00
|
|
|
@State private var addAccountSheetPresented = false
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-10 05:58:50 +00:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-01 08:05:26 +00:00
|
|
|
var body: some View {
|
2023-01-04 11:50:57 +00:00
|
|
|
NavigationStack(path: $routeurPath.path) {
|
2022-12-01 08:05:26 +00:00
|
|
|
Form {
|
2022-12-04 08:50:25 +00:00
|
|
|
appSection
|
2022-12-29 06:00:00 +00:00
|
|
|
accountsSection
|
2023-01-06 16:14:34 +00:00
|
|
|
generalSection
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
2022-12-29 09:39:34 +00:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2022-12-01 08:05:26 +00:00
|
|
|
.navigationTitle(Text("Settings"))
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2023-01-02 16:18:16 +00:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor, for: .navigationBar)
|
2023-01-06 16:14:34 +00:00
|
|
|
.withAppRouteur()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
2023-01-01 08:19:00 +00:00
|
|
|
.onAppear {
|
|
|
|
routeurPath.client = client
|
|
|
|
}
|
2022-12-01 08:05:26 +00:00
|
|
|
.task {
|
|
|
|
if appAccountsManager.currentAccount.oauthToken != nil {
|
2022-12-28 07:06:46 +00:00
|
|
|
await currentInstance.fetchCurrentInstance()
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-08 18:56:16 +00:00
|
|
|
.withSafariRouteur()
|
|
|
|
.environmentObject(routeurPath)
|
2023-01-10 05:58:50 +00:00
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
|
|
|
if popToRootTab == .notifications {
|
|
|
|
routeurPath.path = []
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-29 06:00:00 +00:00
|
|
|
private var accountsSection: some View {
|
2022-12-30 09:11:05 +00:00
|
|
|
Section("Accounts") {
|
2022-12-30 07:36:22 +00:00
|
|
|
ForEach(appAccountsManager.availableAccounts) { account in
|
2023-01-10 05:58:50 +00:00
|
|
|
AppAccountView(viewModel: .init(appAccount: account))
|
2022-12-30 07:36:22 +00:00
|
|
|
}
|
|
|
|
.onDelete { indexSet in
|
|
|
|
if let index = indexSet.first {
|
|
|
|
let account = appAccountsManager.availableAccounts[index]
|
2023-01-08 13:16:43 +00:00
|
|
|
if let token = account.oauthToken {
|
|
|
|
Task {
|
|
|
|
await pushNotifications.deleteSubscriptions(accounts: [.init(server: account.server, token: token)])
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 07:36:22 +00:00
|
|
|
appAccountsManager.delete(account: account)
|
|
|
|
}
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
2022-12-29 13:07:58 +00:00
|
|
|
addAccountButton
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
2022-12-29 09:39:34 +00:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 16:14:34 +00:00
|
|
|
@ViewBuilder
|
|
|
|
private var generalSection: some View {
|
|
|
|
Section("General") {
|
2023-01-08 09:22:52 +00:00
|
|
|
NavigationLink(destination: PushNotificationsView()) {
|
|
|
|
Label("Push notifications", systemImage: "bell.and.waves.left.and.right")
|
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
if let instanceData = currentInstance.instance {
|
|
|
|
NavigationLink(destination: InstanceInfoView(instance: instanceData)) {
|
|
|
|
Label("Instance Information", systemImage: "server.rack")
|
2022-12-31 11:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
NavigationLink(destination: DisplaySettingsView()) {
|
|
|
|
Label("Display Settings", systemImage: "paintpalette")
|
2023-01-04 16:48:02 +00:00
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
NavigationLink(destination: remoteLocalTimelinesView) {
|
|
|
|
Label("Remote Local Timelines", systemImage: "dot.radiowaves.right")
|
2022-12-24 13:55:04 +00:00
|
|
|
}
|
2023-01-08 18:56:16 +00:00
|
|
|
Picker(selection: $preferences.preferredBrowser) {
|
|
|
|
ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in
|
|
|
|
switch browser {
|
|
|
|
case .inAppSafari:
|
|
|
|
Text("In-App Safari").tag(browser)
|
|
|
|
case .safari:
|
|
|
|
Text("System Safari").tag(browser)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("Browser", systemImage: "network")
|
|
|
|
}
|
2022-12-24 13:55:04 +00:00
|
|
|
}
|
2022-12-29 09:39:34 +00:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-24 13:55:04 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-04 08:50:25 +00:00
|
|
|
private var appSection: some View {
|
|
|
|
Section("App") {
|
|
|
|
NavigationLink(destination: IconSelectorView()) {
|
|
|
|
Label {
|
2023-01-06 16:14:34 +00:00
|
|
|
Text("App Icon")
|
2022-12-04 08:50:25 +00:00
|
|
|
} icon: {
|
2022-12-31 13:01:00 +00:00
|
|
|
if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
|
2022-12-27 20:35:41 +00:00
|
|
|
Image(uiImage: .init(named: icon.iconName)!)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-08 18:56:16 +00:00
|
|
|
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp")!) {
|
2023-01-17 05:32:12 +00:00
|
|
|
Label("Source (GitHub link)", systemImage: "link")
|
2023-01-08 18:56:16 +00:00
|
|
|
}
|
|
|
|
.tint(theme.labelColor)
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-07 12:44:13 +00:00
|
|
|
NavigationLink(destination: SupportAppView()) {
|
|
|
|
Label("Support the app", systemImage: "wand.and.stars")
|
2022-12-23 15:21:31 +00:00
|
|
|
}
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
2022-12-29 09:39:34 +00:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-04 08:50:25 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-29 13:07:58 +00:00
|
|
|
private var addAccountButton: some View {
|
2022-12-01 08:05:26 +00:00
|
|
|
Button {
|
2022-12-29 13:07:58 +00:00
|
|
|
addAccountSheetPresented.toggle()
|
2022-12-01 08:05:26 +00:00
|
|
|
} label: {
|
2022-12-29 13:07:58 +00:00
|
|
|
Text("Add account")
|
|
|
|
}
|
|
|
|
.sheet(isPresented: $addAccountSheetPresented) {
|
|
|
|
AddAccountView()
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 16:14:34 +00: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 13:42:09 +00:00
|
|
|
Button {
|
2023-01-06 16:14:34 +00:00
|
|
|
routeurPath.presentedSheet = .addRemoteLocalTimeline
|
2023-01-03 13:42:09 +00:00
|
|
|
} label: {
|
2023-01-06 16:14:34 +00:00
|
|
|
Label("Add a local timeline", systemImage: "badge.plus.radiowaves.right")
|
2023-01-03 13:42:09 +00:00
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-03 13:42:09 +00:00
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
.navigationTitle("Remote Local Timelines")
|
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2022-12-01 08:05:26 +00:00
|
|
|
}
|
|
|
|
}
|