Add macOS support (#23)

* Add macOS support

* Update README

* Update to v0.2.0

* Document breaking changes

* Delete widget tests
This commit is contained in:
Ben Hagen
2025-05-13 16:24:58 +02:00
committed by GitHub
parent c391cc5f26
commit abe519dae7
103 changed files with 3444 additions and 169 deletions
@@ -0,0 +1,59 @@
//
// NearbyDevicesStore.swift
// nearby_service
//
// Created by Kseniia Nikitina on 16/1/24.
//
import Foundation
import MultipeerConnectivity
class NearbyDevicesStore : NSObject {
static let instance = NearbyDevicesStore()
private var devices : [NearbyDevice] = []
func getDevices() -> [NearbyDevice] {
return devices
}
func find(for deviceId: String) -> NearbyDevice? {
return devices.first { device in
return device.peerID.displayName == deviceId
}
}
func add(for peerID: MCPeerID, discoveryInfo: [String: String]? = nil) -> NearbyDevice? {
devices = devices.filter{$0.peerID.displayName != peerID.displayName}
let device = NearbyDevice.fromDictionary(for: discoveryInfo, with: peerID)
self.devices.append(device)
return device
}
func remove(for peerID: MCPeerID) {
self.devices = devices.filter{$0.peerID.displayName != peerID.displayName}
}
func clear() {
self.devices = []
}
func toDartFormat() -> String {
let devicesObject = devices.map { device in
return device.toDictionary()
}
do {
let jsonData = try JSONSerialization.data(withJSONObject: devicesObject)
if let jsonString = String(data: jsonData, encoding: .utf8) {
return jsonString
}
} catch {
return "[]"
}
return "[]"
}
}