Signal-iOS/SignalUI/ViewControllers/OWSWindow.swift
Evan Hahn 29c0ddf60e Fix violations of SwiftLint's attributes rule
_I recommend reviewing this with whitespace changes disabled._

Most of these were `@objc` being on the same line, which I fixed with [a
silly script][1]—probably could've used `sed` if I were wiser. The rest
were manual fixes.

See [the SwiftLint documentation for this rule][0].

[0]: https://realm.github.io/SwiftLint/attributes.html
[1]: https://gist.github.com/EvanHahn-Signal/d353c93fa269c82b96baca0a1086521f
2022-05-14 09:07:42 -05:00

55 lines
1.4 KiB
Swift

//
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
public class OWSWindow: UIWindow {
public override init(frame: CGRect) {
super.init(frame: frame)
NotificationCenter.default.addObserver(
self,
selector: #selector(themeDidChange),
name: .ThemeDidChange,
object: nil
)
applyTheme()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc
private func themeDidChange() {
applyTheme()
}
private func applyTheme() {
guard #available(iOS 13, *) else { return }
// Ensure system UI elements use the appropriate styling for the selected theme.
switch Theme.getOrFetchCurrentTheme() {
case .light:
overrideUserInterfaceStyle = .light
case .dark:
overrideUserInterfaceStyle = .dark
case .system:
overrideUserInterfaceStyle = .unspecified
}
}
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard #available(iOS 13, *) else { return }
if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle {
Theme.systemThemeChanged()
}
}
}