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() {
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
@available(iOS 12.0, *)
fileprivate init(style: UIUserInterfaceStyle) {
public init(style: UIUserInterfaceStyle) {
switch style {
case .light, .unspecified:
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
let localizationSettings: LocalizationSettings?
if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings {
@ -249,7 +249,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager) -
var effectiveChatWallpaper: TelegramWallpaper = themeSettings.chatWallpaper
let parameters = AutomaticThemeSwitchParameters(settings: themeSettings.automaticThemeSwitchSetting)
if automaticThemeShouldSwitchNow(parameters, systemUserInterfaceStyle: .light) {
if automaticThemeShouldSwitchNow(parameters, systemUserInterfaceStyle: systemUserInterfaceStyle) {
effectiveTheme = themeSettings.automaticThemeSwitchSetting.theme
} else {
effectiveTheme = themeSettings.theme

View File

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

View File

@ -115,7 +115,7 @@ public final class NotificationViewControllerImpl {
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
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
semaphore.signal()
})

View File

@ -114,7 +114,7 @@ public class ShareRootControllerImpl {
inForeground.set(false)
}
public func viewDidLayoutSubviews(view: UIView) {
public func viewDidLayoutSubviews(view: UIView, traitCollection: UITraitCollection) {
if self.mainWindow == nil {
let mainWindow = Window1(hostView: childWindowHostView(parent: view), statusBarHost: nil)
mainWindow.hostView.eventView.backgroundColor = UIColor.clear
@ -168,7 +168,13 @@ public class ShareRootControllerImpl {
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
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
semaphore.signal()
})