Refactoring

This commit is contained in:
Ali
2021-04-18 03:10:18 +04:00
parent 4637ed672e
commit 60d959bff8
93 changed files with 221 additions and 191 deletions

View File

@@ -0,0 +1,33 @@
import Foundation
import Postbox
import SwiftSignalKit
import MtProtoKit
import SyncCore
public func updateProxySettingsInteractively(accountManager: AccountManager, _ f: @escaping (ProxySettings) -> ProxySettings) -> Signal<Bool, NoError> {
return accountManager.transaction { transaction -> Bool in
return updateProxySettingsInteractively(transaction: transaction, f)
}
}
extension ProxyServerSettings {
var mtProxySettings: MTSocksProxySettings {
switch self.connection {
case let .socks5(username, password):
return MTSocksProxySettings(ip: self.host, port: UInt16(clamping: self.port), username: username, password: password, secret: nil)
case let .mtp(secret):
return MTSocksProxySettings(ip: self.host, port: UInt16(clamping: self.port), username: nil, password: nil, secret: secret)
}
}
}
public func updateProxySettingsInteractively(transaction: AccountManagerModifier, _ f: @escaping (ProxySettings) -> ProxySettings) -> Bool {
var hasChanges = false
transaction.updateSharedData(SharedDataKeys.proxySettings, { current in
let previous = (current as? ProxySettings) ?? ProxySettings.defaultSettings
let updated = f(previous)
hasChanges = previous != updated
return updated
})
return hasChanges
}