This commit is contained in:
Thomas Ricouard 2023-01-29 14:48:39 +01:00
commit e33def60a3
2 changed files with 25 additions and 1 deletions

View file

@ -127,7 +127,7 @@
"settings.push.duplicate.title" = "重复推送通知修复器";
"settings.push.duplicate.footer" = "有收到重复的推送通知?试试用这个魔法按钮去修复吧";
"settings.push.duplicate.button.fix" = "🪄 修复";
"settings.other.autoplay-video" = "Auto Play Videos";
"settings.other.autoplay-video" = "自动播放视频";
// MARK: Tabs
"tab.explore" = "探索";

View file

@ -38,6 +38,7 @@ struct ThemeApplier: ViewModifier {
theme.selectedSet = colorScheme == .dark ? sets.dark.name : sets.light.name
}
setWindowTint(theme.tintColor)
setWindowUserInterfaceStyle(from: theme.selectedScheme)
setBarsColor(theme.primaryBackgroundColor)
}
.onChange(of: theme.tintColor) { newValue in
@ -46,6 +47,9 @@ struct ThemeApplier: ViewModifier {
.onChange(of: theme.primaryBackgroundColor) { newValue in
setBarsColor(newValue)
}
.onChange(of: theme.selectedScheme) { newValue in
setWindowUserInterfaceStyle(from: newValue)
}
.onChange(of: colorScheme) { newColorScheme in
if theme.followSystemColorScheme,
let sets = availableColorsSets
@ -58,6 +62,26 @@ struct ThemeApplier: ViewModifier {
}
#if canImport(UIKit)
private func setWindowUserInterfaceStyle(from colorScheme: ColorScheme) {
guard !theme.followSystemColorScheme else {
setWindowUserInterfaceStyle(.unspecified)
return
}
switch colorScheme {
case .dark:
setWindowUserInterfaceStyle(.dark)
case .light:
setWindowUserInterfaceStyle(.light)
}
}
private func setWindowUserInterfaceStyle(_ userInterfaceStyle: UIUserInterfaceStyle) {
allWindows()
.forEach {
$0.overrideUserInterfaceStyle = userInterfaceStyle
}
}
private func setWindowTint(_ color: Color) {
allWindows()
.forEach {