This commit is contained in:
fmodf 2024-10-15 12:17:26 +02:00
parent 0bd2b7d82d
commit c426847700
4 changed files with 23 additions and 10 deletions

View file

@ -100,6 +100,12 @@ extension Client {
_ = try await connection.module(.roster).removeItem(jid: JID(roster.contactBareJid))
}
func setActive(_ active: Bool) {
Task {
try? await credentials.setActive(flag: active)
}
}
func connect() async {
guard credentials.isActive, state == .enabled(.disconnected) else {
return

View file

@ -71,8 +71,16 @@ extension ClientsStore {
Task {
await withTaskGroup(of: Void.self) { taskGroup in
for client in clients {
taskGroup.addTask {
await client.connect()
if client.credentials.isActive && client.state != .enabled(.connected) {
taskGroup.addTask {
await client.connect()
}
}
if !client.credentials.isActive && client.state == .enabled(.connected) {
taskGroup.addTask {
client.disconnect()
}
}
}
}

View file

@ -26,13 +26,12 @@ struct SettingsScreen: View {
SharedListRow(
iconType: .charCircle(client.credentials.bareJid),
text: client.credentials.bareJid,
controlType: .none
// controlType: .switcher(isOn: Binding(
// get: { client.credentials.isActive },
// set: { new in
// client.setActive(new)
// }
// ))
controlType: .switcher(isOn: Binding(
get: { client.credentials.isActive },
set: { new in
client.setActive(new)
}
))
)
.onTapGesture {
print("Tapped account \(client.credentials.bareJid)")

View file

@ -7,7 +7,7 @@ struct RootView: View {
var body: some View {
Group {
if clientsStore.ready {
if clientsStore.clients.isEmpty {
if clientsStore.clients.isEmpty || clientsStore.clients.allSatisfy({ !$0.credentials.isActive }) {
RouterView { _ in
WelcomeScreen()
}