mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
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
|
|
}
|