wip
This commit is contained in:
parent
0bd2b7d82d
commit
c426847700
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)")
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue