Make AttractorServer setting nil by default

This commit is contained in:
James Magahern
2022-08-22 15:43:06 -07:00
parent 3b42984361
commit 58433bc59d
3 changed files with 39 additions and 5 deletions

View File

@@ -9,10 +9,20 @@ import Foundation
class AttractorServer
{
public enum Error: Swift.Error {
case missingEndpointURL
}
static let shared = AttractorServer()
private var endpointURL: URL {
get { URL(string: Settings.shared.syncServer) ?? URL(string: "http://localhost")! }
private var endpointURL: URL? {
get {
if let syncServer = Settings.shared.syncServer {
return URL(string: syncServer)
}
return nil
}
}
private func getHostname() -> String {
@@ -21,6 +31,8 @@ class AttractorServer
}
public func publishTabInfo(_ tabInfos: [TabInfo]) {
guard let endpointURL else { return }
let hostName = getHostname()
let rpcURL = endpointURL.appendingPathComponent("publishTabInfo")
var components = URLComponents(url: rpcURL, resolvingAgainstBaseURL: false)!
@@ -44,7 +56,12 @@ class AttractorServer
}
}
public func getTabInfos(_ completion: @escaping(Result<[String: [TabInfo]], Error>) -> Void) {
public func getTabInfos(_ completion: @escaping(Result<[String: [TabInfo]], Swift.Error>) -> Void) {
guard let endpointURL else {
completion(.failure(Self.Error.missingEndpointURL))
return
}
let rpcURL = endpointURL.appendingPathComponent("getTabInfos")
let request = URLRequest(url: rpcURL)
let myHostname = getHostname()