Add Away mode and an agent fork tool
This commit is contained in:
@@ -494,12 +494,56 @@ struct ServerPicker: View {
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 3)
|
||||
.help("Add Server")
|
||||
AwayToggle()
|
||||
}
|
||||
.font(Fonts.font(13))
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
|
||||
private struct AwayToggle: View {
|
||||
@ViewState private var hover = false
|
||||
@ViewState private var busy = false
|
||||
|
||||
var body: some View {
|
||||
let stores = Servers.shared.origins.compactMap { Servers.shared.connections[$0]?.store }
|
||||
let away = stores.contains { $0.me?.away == true }
|
||||
if !stores.isEmpty {
|
||||
Button {
|
||||
set(!away, stores)
|
||||
} label: {
|
||||
Text("Away")
|
||||
.foregroundStyle(away ? Palette.accent : hover ? Palette.text : Palette.muted)
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 3)
|
||||
.background(away ? Palette.accentTint : .clear, in: RoundedRectangle(cornerRadius: 6))
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(busy)
|
||||
.padding(.leading, 8)
|
||||
.help(away
|
||||
? "You're away: byre answers your agents' questions at once, telling them to pick the most likely answer. Click when you're back."
|
||||
: "Go away: byre answers your agents' questions at once, telling them to pick the most likely answer, on every server")
|
||||
.onHover { hover = $0 }
|
||||
}
|
||||
}
|
||||
|
||||
private func set(_ away: Bool, _ stores: [Store]) {
|
||||
busy = true
|
||||
Task {
|
||||
for store in stores {
|
||||
do {
|
||||
store.me = try await store.api.client.updateAway(body: .json(.init(away: away))).ok.body.json
|
||||
} catch {
|
||||
log.error("set away: \(errorText(error), privacy: .public)")
|
||||
}
|
||||
}
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct ServerChip: View {
|
||||
let origin: String
|
||||
@ViewState private var hover = false
|
||||
|
||||
Reference in New Issue
Block a user