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)
-
@@ -76,6 +80,14 @@ final class ConnectionDataModel {) } 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( serverID: String, host: String,
-
-
-
@@ -105,6 +105,9 @@ struct PlacApp: App {Self.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 @@ struct ConnectionScreen: View {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 @@ struct ConnectionScreen: View {} 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 @@ struct ConnectionScreen: View {} 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 @@ private struct Loading: View {// MARK: - Preview #Preview("Loading") { Loading() Loading(onCancel: { print("cancel") }) }
-