Changes
3 changed files (+25/-4)
-
-
@@ -64,8 +64,8 @@ class Connection {var ptr: UnsafeMutablePointer<PlacKit.plac_connection> init(server: CoreServer) { self.ptr = PlacKit.plac_connection_make(server.ptr, nil) init(server: CoreServer, token: String? = nil) { self.ptr = PlacKit.plac_connection_make(server.ptr, token) } init(ptr: UnsafeMutablePointer<PlacKit.plac_connection>) {
-
-
-
@@ -31,6 +31,8 @@ struct MainView: View {@State private var state: MainViewState = .loading @AppStorage("PlacApp.token") private var savedToken: String? private let logger = Logger() private let queue = DispatchQueue(label: "plac.server-find")
-
@@ -41,6 +43,9 @@ struct MainView: View {ProgressView() case .found(let conn): ConnectedView(conn: conn) .onAuthorize { token in savedToken = token } case .findError(_): ContentUnavailableView { Label(
-
@@ -102,7 +107,9 @@ struct MainView: View {} DispatchQueue.main.async { state = .found(Connection(server: result.entries[0])) state = .found( Connection(server: result.entries[0], token: savedToken) ) } } }
-
@@ -123,6 +130,8 @@ struct ConnectedView: View {private let queue = DispatchQueue(label: "plac.event-loop") var onAuthorizeAction: ((_ token: String) -> Void)? var body: some View { let state: Binding<ConnectionState<CoreZone>> = .init( get: {
-
@@ -166,7 +175,8 @@ struct ConnectedView: View {} switch event { case .connected(_): case .connected(let ev): onAuthorizeAction?(ev.token) conn.subscribeZoneChanges() break case .connectionError(let ev):
-
@@ -197,7 +207,14 @@ struct ConnectedView: View {} } } } } extension ConnectedView { func onAuthorize(_ handler: @escaping (String) -> Void) -> ConnectedView { var new = self new.onAuthorizeAction = handler return new } }
-
-
-
@@ -49,6 +49,8 @@ struct placApp: App {@AppStorage("PlacApp.connectedServerId") private var connectedServerId: String? @AppStorage("PlacApp.token") private var savedToken: String? var body: some Scene { WindowGroup("Plac", id: "main-window") { if let connectedServerId = connectedServerId {
-
@@ -57,12 +59,14 @@ struct placApp: App {ServerDiscovery() .onConnect { server in connectedServerId = server.id savedToken = nil } } } .commands { ConnectionCommands(onDisconnect: { connectedServerId = nil savedToken = nil }) } .defaultSize(width: 800, height: 600)
-