Fix Share auto theme

This commit is contained in:
Peter 2019-10-29 02:05:49 +04:00
parent 85c564ad70
commit 7d86ef5c4c
6 changed files with 16 additions and 10 deletions

View File

@ -55,6 +55,6 @@ class ShareRootController: UIViewController {
override func viewDidLayoutSubviews() { override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews() super.viewDidLayoutSubviews()
self.impl?.viewDidLayoutSubviews(view: self.view) self.impl?.viewDidLayoutSubviews(view: self.view, traitCollection: self.traitCollection)
} }
} }

View File

@ -17,7 +17,7 @@ public enum WindowUserInterfaceStyle {
case dark case dark
@available(iOS 12.0, *) @available(iOS 12.0, *)
fileprivate init(style: UIUserInterfaceStyle) { public init(style: UIUserInterfaceStyle) {
switch style { switch style {
case .light, .unspecified: case .light, .unspecified:
self = .light self = .light

View File

@ -195,7 +195,7 @@ public final class InitialPresentationDataAndSettings {
} }
} }
public func currentPresentationDataAndSettings(accountManager: AccountManager) -> Signal<InitialPresentationDataAndSettings, NoError> { public func currentPresentationDataAndSettings(accountManager: AccountManager, systemUserInterfaceStyle: WindowUserInterfaceStyle) -> Signal<InitialPresentationDataAndSettings, NoError> {
return accountManager.transaction { transaction -> InitialPresentationDataAndSettings in return accountManager.transaction { transaction -> InitialPresentationDataAndSettings in
let localizationSettings: LocalizationSettings? let localizationSettings: LocalizationSettings?
if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings { if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings {
@ -249,7 +249,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager) -
var effectiveChatWallpaper: TelegramWallpaper = themeSettings.chatWallpaper var effectiveChatWallpaper: TelegramWallpaper = themeSettings.chatWallpaper
let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting) let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting)
if automaticThemeShouldSwitchNow(parameters, systemUserInterfaceStyle: .light) { if automaticThemeShouldSwitchNow(parameters, systemUserInterfaceStyle: systemUserInterfaceStyle) {
effectiveTheme = themeSettings.automaticThemeSwitchSetting.theme effectiveTheme = themeSettings.automaticThemeSwitchSetting.theme
} else { } else {
effectiveTheme = themeSettings.theme effectiveTheme = themeSettings.theme

View File

@ -715,7 +715,7 @@ final class SharedApplicationContext {
|> deliverOnMainQueue |> deliverOnMainQueue
|> take(1) |> take(1)
|> mapToSignal { accountManager -> Signal<(AccountManager, InitialPresentationDataAndSettings), NoError> in |> mapToSignal { accountManager -> Signal<(AccountManager, InitialPresentationDataAndSettings), NoError> in
return currentPresentationDataAndSettings(accountManager: accountManager) return currentPresentationDataAndSettings(accountManager: accountManager, systemUserInterfaceStyle: .light)
|> map { initialPresentationDataAndSettings -> (AccountManager, InitialPresentationDataAndSettings) in |> map { initialPresentationDataAndSettings -> (AccountManager, InitialPresentationDataAndSettings) in
return (accountManager, initialPresentationDataAndSettings) return (accountManager, initialPresentationDataAndSettings)
} }

View File

@ -115,7 +115,7 @@ public final class NotificationViewControllerImpl {
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings? var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
let semaphore = DispatchSemaphore(value: 0) let semaphore = DispatchSemaphore(value: 0)
let _ = currentPresentationDataAndSettings(accountManager: accountManager).start(next: { value in let _ = currentPresentationDataAndSettings(accountManager: accountManager, systemUserInterfaceStyle: .light).start(next: { value in
initialPresentationDataAndSettings = value initialPresentationDataAndSettings = value
semaphore.signal() semaphore.signal()
}) })

View File

@ -114,7 +114,7 @@ public class ShareRootControllerImpl {
inForeground.set(false) inForeground.set(false)
} }
public func viewDidLayoutSubviews(view: UIView) { public func viewDidLayoutSubviews(view: UIView, traitCollection: UITraitCollection) {
if self.mainWindow == nil { if self.mainWindow == nil {
let mainWindow = Window1(hostView: childWindowHostView(parent: view), statusBarHost: nil) let mainWindow = Window1(hostView: childWindowHostView(parent: view), statusBarHost: nil)
mainWindow.hostView.eventView.backgroundColor = UIColor.clear mainWindow.hostView.eventView.backgroundColor = UIColor.clear
@ -168,7 +168,13 @@ public class ShareRootControllerImpl {
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata") let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings? var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
let semaphore = DispatchSemaphore(value: 0) let semaphore = DispatchSemaphore(value: 0)
let _ = currentPresentationDataAndSettings(accountManager: accountManager).start(next: { value in let systemUserInterfaceStyle: WindowUserInterfaceStyle
if #available(iOSApplicationExtension 12.0, iOS 12.0, *) {
systemUserInterfaceStyle = WindowUserInterfaceStyle(style: traitCollection.userInterfaceStyle)
} else {
systemUserInterfaceStyle = .light
}
let _ = currentPresentationDataAndSettings(accountManager: accountManager, systemUserInterfaceStyle: systemUserInterfaceStyle).start(next: { value in
initialPresentationDataAndSettings = value initialPresentationDataAndSettings = value
semaphore.signal() semaphore.signal()
}) })