Changes
3 changed files (+65/-11)
-
-
@@ -20,6 +20,10 @@ import OSLogimport RoonKit import SwiftUI enum CancelError: Error { case cancelled } enum ConnectionState { case connecting case connected(Communicatable & Connectable)
-
@@ -74,6 +78,14 @@ port: other.port,token: other.token, onConnect: onConnect ) } init(cancelling: ConnectionDataModel) { self.serverID = cancelling.serverID self.host = cancelling.host self.port = cancelling.port self.token = cancelling.token self.state = .failed(CancelError.cancelled) } init(
-
-
-
@@ -105,6 +105,9 @@ onConnect: { token inSelf.saveToken(token) } ) }, onCancel: { self.model.model = ConnectionDataModel(cancelling: model) } ) .focusedSceneValue(self.model)
-
-
-
@@ -21,29 +21,27 @@ struct ConnectionScreen: View {private let conn: ConnectionDataModel private var onDisconnect: (() -> Void) private var onReconnect: (() -> Void) private var onCancel: (() -> Void) init( model: ConnectionDataModel, onDisconnect: (@escaping () -> Void), onReconnect: (@escaping () -> Void) onReconnect: (@escaping () -> Void), onCancel: (@escaping () -> Void) ) { self.conn = model self.onDisconnect = onDisconnect self.onReconnect = onReconnect self.onCancel = onCancel } var body: some View { VStack { switch conn.state { case .connecting, .waitingToReconnect: VStack { Loading() Button(role: .cancel) { onDisconnect() } label: { Text("Cancel") } } Loading(onCancel: { onCancel() }) case .connected(let conn): ConnectedScreen(conn: conn) .environment(
-
@@ -70,6 +68,27 @@ } label: {Text("Retry") } } case .failed(CancelError.cancelled): ContentUnavailableView { Label( "Connection cancelled", systemImage: "exclamationmark.magnifyingglass" ) } description: { Text("Cancelled connection to Roon server.") } actions: { Button(role: .cancel) { onDisconnect() } label: { Text("Close") } Button { onReconnect() } label: { Text("Connect") } } case .failed(_): ContentUnavailableView { Label(
-
@@ -79,6 +98,12 @@ )} description: { Text("Unable to connect to server due to error.") } actions: { Button(role: .cancel) { onDisconnect() } label: { Text("Cancel") } Button { onReconnect() } label: {
-
@@ -91,14 +116,26 @@ }} private struct Loading: View { private var onCancel: (() -> Void)? init(onCancel: (() -> Void)? = nil) { self.onCancel = onCancel } var body: some View { VStack { VStack(spacing: 8) { ProgressView { Text( "Connecting to Roon Server.\nMake sure you granted access at Settings > Extension page in official Roon client." ) .multilineTextAlignment(.center) } Button(role: .cancel) { onCancel?() } label: { Text("Cancel") } } } }
-
@@ -106,5 +143,7 @@// MARK: - Preview #Preview("Loading") { Loading() Loading(onCancel: { print("cancel") }) }
-