Tag v0.1.0
This commit is contained in:
@@ -86,6 +86,46 @@ final class Connection {
|
||||
await start(origin)
|
||||
}
|
||||
|
||||
func installHere() async {
|
||||
connecting = true
|
||||
problem = nil
|
||||
let gen = generation
|
||||
do {
|
||||
let origin = try await Server.turnOn()
|
||||
serverText = origin.absoluteString
|
||||
try await waitForServer(origin)
|
||||
} catch {
|
||||
if gen == generation {
|
||||
connecting = false
|
||||
problem = errorText(error)
|
||||
}
|
||||
return
|
||||
}
|
||||
guard gen == generation else {
|
||||
return
|
||||
}
|
||||
await connect()
|
||||
}
|
||||
|
||||
private func waitForServer(_ origin: URL) async throws {
|
||||
let api = API(origin: origin)
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
group.addTask {
|
||||
while (try? await api.client.getStatus().ok) == nil {
|
||||
try await Task.sleep(for: .milliseconds(500))
|
||||
}
|
||||
}
|
||||
group.addTask {
|
||||
try await Task.sleep(for: .seconds(10))
|
||||
throw ProcessFailure(errorDescription: "byre was installed but \(origin.absoluteString) didn't answer within 10 s.")
|
||||
}
|
||||
defer {
|
||||
group.cancelAll()
|
||||
}
|
||||
try await group.next()
|
||||
}
|
||||
}
|
||||
|
||||
func changeServer() {
|
||||
generation += 1
|
||||
if let store {
|
||||
@@ -175,8 +215,11 @@ struct ConnectView: View {
|
||||
TextField("https://byre.example.ts.net", text: $connection.serverText)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.onSubmit(connect)
|
||||
Button("Connect", action: connect)
|
||||
.disabled(connection.connecting)
|
||||
HStack(spacing: 10) {
|
||||
Button("Connect", action: connect)
|
||||
Button("Run byre on this Mac", action: installHere)
|
||||
}
|
||||
.disabled(connection.connecting)
|
||||
if let problem = connection.problem {
|
||||
Text(problem)
|
||||
.foregroundStyle(Palette.danger)
|
||||
@@ -193,6 +236,12 @@ struct ConnectView: View {
|
||||
await connection.connect()
|
||||
}
|
||||
}
|
||||
|
||||
private func installHere() {
|
||||
Task {
|
||||
await connection.installHere()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FatalView: View {
|
||||
|
||||
Reference in New Issue
Block a user