[epiphany/wip/exalm/dark: 3/3] Follow the system dark preference for reader mode
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/dark: 3/3] Follow the system dark preference for reader mode
- Date: Sun, 21 Nov 2021 16:17:19 +0000 (UTC)
commit 96413d0943f3111f0820f93919170d45f68fd349
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Nov 21 18:13:11 2021 +0500
Follow the system dark preference for reader mode
When it's available, hide the reader color scheme preference and follow the
system.
Fixes https://gitlab.gnome.org/GNOME/epiphany/-/issues/1546
embed/ephy-reader-handler.c | 13 ++++++++++---
embed/ephy-web-view.c | 33 ++++++++++++++++++++++++---------
src/preferences/prefs-appearance-page.c | 4 ++++
3 files changed, 38 insertions(+), 12 deletions(-)
---
diff --git a/embed/ephy-reader-handler.c b/embed/ephy-reader-handler.c
index 707497bdb..fb53436e6 100644
--- a/embed/ephy-reader-handler.c
+++ b/embed/ephy-reader-handler.c
@@ -163,6 +163,7 @@ readability_js_finish_cb (GObject *object,
const gchar *title;
const gchar *font_style;
const gchar *color_scheme;
+ HdyStyleManager *style_manager;
js_result = webkit_web_view_run_javascript_finish (web_view, result, &error);
if (!js_result) {
@@ -181,9 +182,15 @@ readability_js_finish_cb (GObject *object,
font_style = enum_nick (EPHY_TYPE_PREFS_READER_FONT_STYLE,
g_settings_get_enum (EPHY_SETTINGS_READER,
EPHY_PREFS_READER_FONT_STYLE));
- color_scheme = enum_nick (EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
- g_settings_get_enum (EPHY_SETTINGS_READER,
- EPHY_PREFS_READER_COLOR_SCHEME));
+
+ style_manager = hdy_style_manager_get_default ();
+
+ if (hdy_style_manager_get_system_supports_color_schemes (style_manager))
+ color_scheme = hdy_style_manager_get_dark (style_manager) ? "dark" : "light";
+ else
+ color_scheme = enum_nick (EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
+ g_settings_get_enum (EPHY_SETTINGS_READER,
+ EPHY_PREFS_READER_COLOR_SCHEME));
g_string_append_printf (html, "<style>%s</style>"
"<title>%s</title>"
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 27bff9a12..b40c05157 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2576,10 +2576,9 @@ enum_nick (GType enum_type,
}
static void
-reader_setting_changed_cb (GSettings *settings,
- gchar *key,
- EphyWebView *web_view)
+reader_setting_changed_cb (EphyWebView *web_view)
{
+ HdyStyleManager *style_manager;
const gchar *font_style;
const gchar *color_scheme;
gchar *js_snippet;
@@ -2588,11 +2587,17 @@ reader_setting_changed_cb (GSettings *settings,
return;
font_style = enum_nick (EPHY_TYPE_PREFS_READER_FONT_STYLE,
- g_settings_get_enum (settings,
+ g_settings_get_enum (EPHY_SETTINGS_READER,
EPHY_PREFS_READER_FONT_STYLE));
- color_scheme = enum_nick (EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
- g_settings_get_enum (settings,
- EPHY_PREFS_READER_COLOR_SCHEME));
+
+ style_manager = hdy_style_manager_get_default ();
+
+ if (hdy_style_manager_get_system_supports_color_schemes (style_manager))
+ color_scheme = hdy_style_manager_get_dark (style_manager) ? "dark" : "light";
+ else
+ color_scheme = enum_nick (EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
+ g_settings_get_enum (EPHY_SETTINGS_READER,
+ EPHY_PREFS_READER_COLOR_SCHEME));
js_snippet = g_strdup_printf ("document.body.className = '%s %s'",
font_style,
@@ -3979,11 +3984,21 @@ ephy_web_view_init (EphyWebView *web_view)
g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_FONT_STYLE,
G_CALLBACK (reader_setting_changed_cb),
- web_view, 0);
+ web_view, G_CONNECT_SWAPPED);
g_signal_connect_object (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_COLOR_SCHEME,
G_CALLBACK (reader_setting_changed_cb),
- web_view, 0);
+ web_view, G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (hdy_style_manager_get_default (),
+ "notify::system-supports-color-schemes",
+ G_CALLBACK (reader_setting_changed_cb),
+ web_view, G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (hdy_style_manager_get_default (),
+ "notify::dark",
+ G_CALLBACK (reader_setting_changed_cb),
+ web_view, G_CONNECT_SWAPPED);
g_signal_connect (web_view, "decide-policy",
G_CALLBACK (decide_policy_cb),
diff --git a/src/preferences/prefs-appearance-page.c b/src/preferences/prefs-appearance-page.c
index 7b65ee54f..42193af00 100644
--- a/src/preferences/prefs-appearance-page.c
+++ b/src/preferences/prefs-appearance-page.c
@@ -348,6 +348,10 @@ setup_appearance_page (PrefsAppearancePage *appearance_page)
reader_font_style_set_mapping,
NULL, NULL);
+ g_object_bind_property (hdy_style_manager_get_default (), "system-supports-color-schemes",
+ appearance_page->reader_mode_color_scheme, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
hdy_combo_row_set_for_enum (HDY_COMBO_ROW (appearance_page->reader_mode_color_scheme),
EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
reader_color_scheme_get_name, NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]