2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] Only set the engine's theme when it is instantiated

This commit is contained in:
ekager 2019-04-18 21:40:07 -07:00 committed by Jeff Boek
parent b1cc487f14
commit 6d50cc22a0
3 changed files with 7 additions and 4 deletions

View File

@ -65,7 +65,6 @@ open class HomeActivity : AppCompatActivity() {
DefaultThemeManager.applyStatusBarTheme(window, themeManager, this)
browsingModeManager = DefaultBrowsingModeManager(this)
components.core.setEnginePreferredColorScheme()
setContentView(R.layout.activity_home)
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.libraryFragment)).build()

View File

@ -62,7 +62,8 @@ class Core(private val context: Context) {
remoteDebuggingEnabled = Settings.getInstance(context).isRemoteDebuggingEnabled,
testingModeEnabled = false,
trackingProtectionPolicy = createTrackingProtectionPolicy(),
historyTrackingDelegate = HistoryDelegate(historyStorage)
historyTrackingDelegate = HistoryDelegate(historyStorage),
preferredColorScheme = getPreferredColorScheme()
)
GeckoEngine(context, defaultSettings, runtime)
@ -153,11 +154,11 @@ class Core(private val context: Context) {
/**
* Sets Preferred Color scheme based on Dark/Light Theme Settings or Current Configuration
*/
fun setEnginePreferredColorScheme() {
fun getPreferredColorScheme(): PreferredColorScheme {
val inDark =
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES
engine.settings.preferredColorScheme = when {
return when {
Settings.getInstance(context).shouldUseDarkTheme -> PreferredColorScheme.Dark
Settings.getInstance(context).shouldUseLightTheme -> PreferredColorScheme.Light
inDark -> PreferredColorScheme.Dark

View File

@ -100,6 +100,9 @@ class ThemeFragment : PreferenceFragmentCompat() {
private fun setNewTheme(mode: Int) {
AppCompatDelegate.setDefaultNightMode(mode)
activity?.recreate()
with(requireComponents.core) {
engine.settings.preferredColorScheme = getPreferredColorScheme()
}
requireComponents.useCases.sessionUseCases.reload.invoke()
}
}