ios: choose accent color (#956)
This commit is contained in:
committed by
GitHub
parent
9f94c6f98a
commit
2cffe91e0b
@@ -80,6 +80,16 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
terminateChat()
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication,
|
||||
configurationForConnecting connectingSceneSession: UISceneSession,
|
||||
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
|
||||
let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
|
||||
if connectingSceneSession.role == .windowApplication {
|
||||
configuration.delegateClass = SceneDelegate.self
|
||||
}
|
||||
return configuration
|
||||
}
|
||||
|
||||
private func receiveMessages(_ completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
let complete = BGManager.shared.completionHandler {
|
||||
logger.debug("AppDelegate: completed BGManager.receiveMessages")
|
||||
@@ -89,3 +99,13 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
BGManager.shared.receiveMessages(complete)
|
||||
}
|
||||
}
|
||||
|
||||
class SceneDelegate: NSObject, ObservableObject, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
guard let windowScene = scene as? UIWindowScene else { return }
|
||||
window = windowScene.keyWindow
|
||||
window?.tintColor = UIColor(cgColor: getUIAccentColorDefault())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
let defaultAccentColor = CGColor.init(red: 0, green: 0.533, blue: 1, alpha: 1)
|
||||
|
||||
struct AppearanceSettings: View {
|
||||
@EnvironmentObject var sceneDelegate: SceneDelegate
|
||||
@State private var iconLightTapped = false
|
||||
@State private var iconDarkTapped = false
|
||||
@State private var uiTintColor = getUIAccentColorDefault()
|
||||
|
||||
var body: some View {
|
||||
VStack{
|
||||
@@ -22,6 +26,23 @@ struct AppearanceSettings: View {
|
||||
updateAppIcon(image: "icon-dark", icon: "DarkAppIcon", tapped: $iconDarkTapped)
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
ColorPicker("Accent color", selection: $uiTintColor, supportsOpacity: false)
|
||||
} header: {
|
||||
Text("Colors")
|
||||
} footer: {
|
||||
Button {
|
||||
uiTintColor = defaultAccentColor
|
||||
setUIAccentColorDefault(defaultAccentColor)
|
||||
} label: {
|
||||
Text("Reset colors").font(.callout)
|
||||
}
|
||||
}
|
||||
.onChange(of: uiTintColor) { _ in
|
||||
sceneDelegate.window?.tintColor = UIColor(cgColor: uiTintColor)
|
||||
setUIAccentColorDefault(uiTintColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +65,25 @@ struct AppearanceSettings: View {
|
||||
}
|
||||
}
|
||||
|
||||
func getUIAccentColorDefault() -> CGColor {
|
||||
let defs = UserDefaults.standard
|
||||
return CGColor(
|
||||
red: defs.double(forKey: DEFAULT_ACCENT_COLOR_RED),
|
||||
green: defs.double(forKey: DEFAULT_ACCENT_COLOR_GREEN),
|
||||
blue: defs.double(forKey: DEFAULT_ACCENT_COLOR_BLUE),
|
||||
alpha: 1
|
||||
)
|
||||
}
|
||||
|
||||
func setUIAccentColorDefault(_ color: CGColor) {
|
||||
if let cs = color.components {
|
||||
let defs = UserDefaults.standard
|
||||
defs.set(cs[0], forKey: DEFAULT_ACCENT_COLOR_RED)
|
||||
defs.set(cs[1], forKey: DEFAULT_ACCENT_COLOR_GREEN)
|
||||
defs.set(cs[2], forKey: DEFAULT_ACCENT_COLOR_BLUE)
|
||||
}
|
||||
}
|
||||
|
||||
struct AppearanceSettings_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AppearanceSettings()
|
||||
|
||||
@@ -26,6 +26,9 @@ let DEFAULT_CHAT_ARCHIVE_NAME = "chatArchiveName"
|
||||
let DEFAULT_CHAT_ARCHIVE_TIME = "chatArchiveTime"
|
||||
let DEFAULT_CHAT_V3_DB_MIGRATION = "chatV3DBMigration"
|
||||
let DEFAULT_DEVELOPER_TOOLS = "developerTools"
|
||||
let DEFAULT_ACCENT_COLOR_RED = "accentColorRed"
|
||||
let DEFAULT_ACCENT_COLOR_GREEN = "accentColorGreen"
|
||||
let DEFAULT_ACCENT_COLOR_BLUE = "accentColorBlue"
|
||||
|
||||
let appDefaults: [String: Any] = [
|
||||
DEFAULT_SHOW_LA_NOTICE: false,
|
||||
@@ -36,7 +39,10 @@ let appDefaults: [String: Any] = [
|
||||
DEFAULT_PRIVACY_LINK_PREVIEWS: true,
|
||||
DEFAULT_EXPERIMENTAL_CALLS: false,
|
||||
DEFAULT_CHAT_V3_DB_MIGRATION: "offer",
|
||||
DEFAULT_DEVELOPER_TOOLS: false
|
||||
DEFAULT_DEVELOPER_TOOLS: false,
|
||||
DEFAULT_ACCENT_COLOR_RED: 0.000,
|
||||
DEFAULT_ACCENT_COLOR_GREEN: 0.533,
|
||||
DEFAULT_ACCENT_COLOR_BLUE: 1.000
|
||||
]
|
||||
|
||||
private var indent: CGFloat = 36
|
||||
|
||||
Reference in New Issue
Block a user