mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
46 lines
1.6 KiB
Swift
46 lines
1.6 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
|
|
public struct ExperimentalUISettings: Equatable, PreferencesEntry {
|
|
public var keepChatNavigationStack: Bool
|
|
|
|
public static var defaultSettings: ExperimentalUISettings {
|
|
return ExperimentalUISettings(keepChatNavigationStack: false)
|
|
}
|
|
|
|
public init(keepChatNavigationStack: Bool) {
|
|
self.keepChatNavigationStack = keepChatNavigationStack
|
|
}
|
|
|
|
public init(decoder: PostboxDecoder) {
|
|
self.keepChatNavigationStack = decoder.decodeInt32ForKey("keepChatNavigationStack", orElse: 0) != 0
|
|
}
|
|
|
|
public func encode(_ encoder: PostboxEncoder) {
|
|
encoder.encodeInt32(self.keepChatNavigationStack ? 1 : 0, forKey: "keepChatNavigationStack")
|
|
}
|
|
|
|
public func isEqual(to: PreferencesEntry) -> Bool {
|
|
if let to = to as? ExperimentalUISettings {
|
|
return self == to
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
func updateExperimentalUISettingsInteractively(postbox: Postbox, _ f: @escaping (ExperimentalUISettings) -> ExperimentalUISettings) -> Signal<Void, NoError> {
|
|
return postbox.transaction { transaction -> Void in
|
|
transaction.updatePreferencesEntry(key: ApplicationSpecificPreferencesKeys.experimentalUISettings, { entry in
|
|
let currentSettings: ExperimentalUISettings
|
|
if let entry = entry as? ExperimentalUISettings {
|
|
currentSettings = entry
|
|
} else {
|
|
currentSettings = .defaultSettings
|
|
}
|
|
return f(currentSettings)
|
|
})
|
|
}
|
|
}
|