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))
|
_ = try await connection.module(.roster).removeItem(jid: JID(roster.contactBareJid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setActive(_ active: Bool) {
|
||||||
|
Task {
|
||||||
|
try? await credentials.setActive(flag: active)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func connect() async {
|
func connect() async {
|
||||||
guard credentials.isActive, state == .enabled(.disconnected) else {
|
guard credentials.isActive, state == .enabled(.disconnected) else {
|
||||||
return
|
return
|
||||||
|
|
|
@ -71,10 +71,18 @@ extension ClientsStore {
|
||||||
Task {
|
Task {
|
||||||
await withTaskGroup(of: Void.self) { taskGroup in
|
await withTaskGroup(of: Void.self) { taskGroup in
|
||||||
for client in clients {
|
for client in clients {
|
||||||
|
if client.credentials.isActive && client.state != .enabled(.connected) {
|
||||||
taskGroup.addTask {
|
taskGroup.addTask {
|
||||||
await client.connect()
|
await client.connect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !client.credentials.isActive && client.state == .enabled(.connected) {
|
||||||
|
taskGroup.addTask {
|
||||||
|
client.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,12 @@ struct SettingsScreen: View {
|
||||||
SharedListRow(
|
SharedListRow(
|
||||||
iconType: .charCircle(client.credentials.bareJid),
|
iconType: .charCircle(client.credentials.bareJid),
|
||||||
text: client.credentials.bareJid,
|
text: client.credentials.bareJid,
|
||||||
controlType: .none
|
controlType: .switcher(isOn: Binding(
|
||||||
// controlType: .switcher(isOn: Binding(
|
get: { client.credentials.isActive },
|
||||||
// get: { client.credentials.isActive },
|
set: { new in
|
||||||
// set: { new in
|
client.setActive(new)
|
||||||
// client.setActive(new)
|
}
|
||||||
// }
|
))
|
||||||
// ))
|
|
||||||
)
|
)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
print("Tapped account \(client.credentials.bareJid)")
|
print("Tapped account \(client.credentials.bareJid)")
|
||||||
|
|
|
@ -7,7 +7,7 @@ struct RootView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if clientsStore.ready {
|
if clientsStore.ready {
|
||||||
if clientsStore.clients.isEmpty {
|
if clientsStore.clients.isEmpty || clientsStore.clients.allSatisfy({ !$0.credentials.isActive }) {
|
||||||
RouterView { _ in
|
RouterView { _ in
|
||||||
WelcomeScreen()
|
WelcomeScreen()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue