diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-08 10:04:55 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-08 10:04:55 -0800 |
| commit | 537ed932a4c8d639089f276e322de4e946b0d26b (patch) | |
| tree | 1d3604a5f777be87f2d3d405ddfe5725c687b99f /Hotline/Models | |
| parent | 767eb58da13d83aa321fff12c97fe433cd8fa734 (diff) | |
Starting to move to async/await model so the client code is no longer burdoned by observation and isn't bound to this app.
Diffstat (limited to 'Hotline/Models')
| -rw-r--r-- | Hotline/Models/Hotline.swift | 21 | ||||
| -rw-r--r-- | Hotline/Models/Server.swift | 16 | ||||
| -rw-r--r-- | Hotline/Models/Tracker.swift | 20 |
3 files changed, 57 insertions, 0 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift new file mode 100644 index 0000000..70f68a9 --- /dev/null +++ b/Hotline/Models/Hotline.swift @@ -0,0 +1,21 @@ +import SwiftUI + +@Observable final class Hotline { + let trackerClient: HotlineTrackerClient + + + + init(trackerClient: HotlineTrackerClient) { + self.trackerClient = trackerClient + } + + @MainActor func getServers(address: String, port: Int) async { + let fetchedServers = await withCheckedContinuation { [weak self] continuation in + self?.trackerClient.fetch() { + continuation.resume(returning: []) + } + } + + + } +} diff --git a/Hotline/Models/Server.swift b/Hotline/Models/Server.swift new file mode 100644 index 0000000..c2063ea --- /dev/null +++ b/Hotline/Models/Server.swift @@ -0,0 +1,16 @@ +import SwiftUI + +@Observable final class Server { + let name: String + let description: String? + let users: Int = 0 + let address: String + let port: Int + + init(name: String, description: String?, address: String, port: Int) { + self.name = name + self.description = description + self.address = address + self.port = port + } +} diff --git a/Hotline/Models/Tracker.swift b/Hotline/Models/Tracker.swift new file mode 100644 index 0000000..c9dfb5c --- /dev/null +++ b/Hotline/Models/Tracker.swift @@ -0,0 +1,20 @@ +import SwiftUI + +@Observable final class Tracker { + let service: HotlineTrackerClient + let address: String + let port: Int + var servers: [Server] = [] + + init(address: String, port: Int = 5498, service: HotlineTrackerClient) { + self.address = address + self.port = port + self.service = service + } + + func fetchServers() { + self.service.fetch2(address: self.address, port: self.port) { servers in + self.servers = servers + } + } +} |