Make AttractorServer setting nil by default
This commit is contained in:
@@ -169,7 +169,7 @@ class GeneralSettingsViewController: UIViewController
|
|||||||
cell.contentConfiguration = ButtonContentConfiguration(menu: menu)
|
cell.contentConfiguration = ButtonContentConfiguration(menu: menu)
|
||||||
} else if identifier == Self.SyncServerItem {
|
} else if identifier == Self.SyncServerItem {
|
||||||
cell.contentConfiguration = TextFieldContentConfiguration(
|
cell.contentConfiguration = TextFieldContentConfiguration(
|
||||||
text: Settings.shared.syncServer,
|
text: Settings.shared.syncServer ?? "",
|
||||||
placeholderText: "https://sync.server.com",
|
placeholderText: "https://sync.server.com",
|
||||||
textChanged: { newString in
|
textChanged: { newString in
|
||||||
Settings.shared.syncServer = newString
|
Settings.shared.syncServer = newString
|
||||||
|
|||||||
@@ -107,5 +107,22 @@ class Settings
|
|||||||
public var userStylesheet: String = ""
|
public var userStylesheet: String = ""
|
||||||
|
|
||||||
@SettingProperty(key: "syncServer")
|
@SettingProperty(key: "syncServer")
|
||||||
public var syncServer: String = "https://attractor.severnaya.net"
|
public var syncServer: Optional<String> = "https://attractor.severnaya.net"
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Optional: RawRepresentable where Wrapped == String
|
||||||
|
{
|
||||||
|
public init?(rawValue: String?) {
|
||||||
|
if let rawValue {
|
||||||
|
self = String(rawValue: rawValue)
|
||||||
|
} else {
|
||||||
|
self = .none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var rawValue: String? {
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
public typealias RawValue = String?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,20 @@ import Foundation
|
|||||||
|
|
||||||
class AttractorServer
|
class AttractorServer
|
||||||
{
|
{
|
||||||
|
public enum Error: Swift.Error {
|
||||||
|
case missingEndpointURL
|
||||||
|
}
|
||||||
|
|
||||||
static let shared = AttractorServer()
|
static let shared = AttractorServer()
|
||||||
|
|
||||||
private var endpointURL: URL {
|
private var endpointURL: URL? {
|
||||||
get { URL(string: Settings.shared.syncServer) ?? URL(string: "http://localhost")! }
|
get {
|
||||||
|
if let syncServer = Settings.shared.syncServer {
|
||||||
|
return URL(string: syncServer)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getHostname() -> String {
|
private func getHostname() -> String {
|
||||||
@@ -21,6 +31,8 @@ class AttractorServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func publishTabInfo(_ tabInfos: [TabInfo]) {
|
public func publishTabInfo(_ tabInfos: [TabInfo]) {
|
||||||
|
guard let endpointURL else { return }
|
||||||
|
|
||||||
let hostName = getHostname()
|
let hostName = getHostname()
|
||||||
let rpcURL = endpointURL.appendingPathComponent("publishTabInfo")
|
let rpcURL = endpointURL.appendingPathComponent("publishTabInfo")
|
||||||
var components = URLComponents(url: rpcURL, resolvingAgainstBaseURL: false)!
|
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 rpcURL = endpointURL.appendingPathComponent("getTabInfos")
|
||||||
let request = URLRequest(url: rpcURL)
|
let request = URLRequest(url: rpcURL)
|
||||||
let myHostname = getHostname()
|
let myHostname = getHostname()
|
||||||
|
|||||||
Reference in New Issue
Block a user