This commit is contained in:
fmodf 2024-10-15 18:03:16 +02:00
parent acf2807056
commit bec095e8de
5 changed files with 35 additions and 71 deletions

View file

@ -1,32 +0,0 @@
import Combine
import Foundation
import GRDB
import Photos
import SwiftUI
@MainActor
final class GlobalSettingsStore: ObservableObject {
static let shared = GlobalSettingsStore()
@Published var credentials: [Credentials] = []
private var credentialsCancellable: AnyCancellable?
init() {
subscribe()
}
}
private extension GlobalSettingsStore {
func subscribe() {
credentialsCancellable = ValueObservation.tracking(Credentials
.fetchAll
)
.publisher(in: Database.shared.dbQueue, scheduling: .immediate)
.receive(on: DispatchQueue.main)
.sink { _ in
} receiveValue: { [weak self] credentials in
self?.credentials = credentials
}
}
}

View file

@ -5,7 +5,6 @@ import SwiftUI
@MainActor
struct ConversationsClassic: App {
private let clientsStore = ClientsStore.shared
private let globalSettingsStore = GlobalSettingsStore.shared
init() {
// There's a bug on iOS 17 where sheet may not load with large title, even if modifiers are set, which causes some tests to fail
@ -17,7 +16,6 @@ struct ConversationsClassic: App {
WindowGroup {
RootView()
.environmentObject(clientsStore)
.environmentObject(globalSettingsStore)
}
}
}

View file

@ -1,7 +1,7 @@
import SwiftUI
struct WelcomeScreen: View {
@EnvironmentObject var globalSettingsStore: GlobalSettingsStore
@EnvironmentObject var clientsStore: ClientsStore
@Environment(\.router) var router
var body: some View {
@ -10,22 +10,22 @@ struct WelcomeScreen: View {
Color.Material.Background.light
.ignoresSafeArea()
if !globalSettingsStore.credentials.isEmpty && globalSettingsStore.credentials.allSatisfy({ !$0.isActive }) {
VStack {
HStack {
Spacer()
Image(systemName: "gear")
.foregroundColor(.Material.Elements.active)
.tappablePadding(.symmetric(10)) {
router.showScreen(.push) { _ in
SettingsScreen()
}
}
}
.padding()
Spacer()
}
}
// if !clientsStore.clients.isEmpty && clientsStore.clients.allSatisfy({ $0.state != .enabled(.connected) }) {
// VStack {
// HStack {
// Spacer()
// Image(systemName: "gear")
// .foregroundColor(.Material.Elements.active)
// .tappablePadding(.symmetric(10)) {
// router.showScreen(.push) { _ in
// SettingsScreen()
// }
// }
// }
// .padding()
// Spacer()
// }
// }
// content
VStack(spacing: 32) {

View file

@ -2,7 +2,6 @@ import SwiftUI
struct SettingsScreen: View {
@EnvironmentObject var clientsStore: ClientsStore
@EnvironmentObject var settingsStore: GlobalSettingsStore
@Environment(\.router) var router
var body: some View {
@ -23,23 +22,23 @@ struct SettingsScreen: View {
// Accounts section
SharedSectionTitle(text: L10n.Settings.Section.Accounts.title)
ForEach(settingsStore.credentials) { creds in
SharedListRow(
iconType: .charCircle(creds.bareJid),
text: creds.bareJid,
controlType: .switcher(isOn: Binding(
get: { creds.isActive },
set: { new in
Task {
try? await creds.setActive(flag: new)
}
}
))
)
.onTapGesture {
print("Tapped account \(creds.bareJid)")
}
}
// ForEach(settingsStore.credentials) { creds in
// SharedListRow(
// iconType: .charCircle(creds.bareJid),
// text: creds.bareJid,
// controlType: .switcher(isOn: Binding(
// get: { creds.isActive },
// set: { new in
// Task {
// try? await creds.setActive(flag: new)
// }
// }
// ))
// )
// .onTapGesture {
// print("Tapped account \(creds.bareJid)")
// }
// }
SharedListRow(
iconType: .image(Image(systemName: "plus"), .Material.Elements.active),

View file

@ -3,12 +3,11 @@ import SwiftUI
struct RootView: View {
@EnvironmentObject var clientsStore: ClientsStore
@EnvironmentObject var globalSettingsStore: GlobalSettingsStore
var body: some View {
Group {
if clientsStore.ready {
if clientsStore.clients.isEmpty || globalSettingsStore.credentials.allSatisfy({ !$0.isActive }) {
if clientsStore.clients.isEmpty {
RouterView { _ in
WelcomeScreen()
}