[gnome-maps/wip/cdavis/dark-style-preference] Use libhandy's dark style infrastructure




commit 9f70140a49bba04cbe6b7ac9193f088e91a72dbd
Author: Christopher Davis <christopherdavis gnome org>
Date:   Sat Sep 25 22:32:35 2021 -0700

    Use libhandy's dark style infrastructure
    
    Instead of having our own explicit setting for dark
    mode, we can use libhandy's infrastructure for dark
    styling, which is hooked into the new global dark style
    preference.

 data/org.gnome.Maps.gschema.xml |  5 -----
 data/ui/main-window.ui          |  4 ----
 src/application.js              | 17 ++---------------
 src/layersPopover.js            | 11 ++++++-----
 src/mainWindow.js               |  2 +-
 src/mapView.js                  | 11 ++++++-----
 6 files changed, 15 insertions(+), 35 deletions(-)
---
diff --git a/data/org.gnome.Maps.gschema.xml b/data/org.gnome.Maps.gschema.xml
index cc32f780..f9239066 100644
--- a/data/org.gnome.Maps.gschema.xml
+++ b/data/org.gnome.Maps.gschema.xml
@@ -75,11 +75,6 @@
       <default>'pedestrian'</default>
       <summary>Last used transportation type for routing</summary>
     </key>
-    <key name="night-mode" type="b">
-      <default>false</default>
-      <summary>Night mode</summary>
-      <description>Whether the application is in night mode.</description>
-    </key>
     <key name="hybrid-aerial" type="b">
       <default>false</default>
       <summary>Use hybrid aerial tiles</summary>
diff --git a/data/ui/main-window.ui b/data/ui/main-window.ui
index a21db6aa..c87b6321 100644
--- a/data/ui/main-window.ui
+++ b/data/ui/main-window.ui
@@ -3,10 +3,6 @@
   <!-- interface-requires gtk+ 3.0 -->
   <menu id="hamburgerMenu">
     <section>
-      <item>
-        <attribute name="action">app.night-mode</attribute>
-        <attribute name="label" translatable="yes">Night Mode</attribute>
-      </item>
       <item>
         <attribute name="action">app.osm-account-setup</attribute>
         <attribute name="label" translatable="yes">Set up OpenStreetMap Account</attribute>
diff --git a/src/application.js b/src/application.js
index 573bceef..32d309b0 100644
--- a/src/application.js
+++ b/src/application.js
@@ -227,12 +227,6 @@ var Application = GObject.registerClass({
         }
     }
 
-    _onNightModeChange(action) {
-        let state = action.get_state();
-        let gtkSettings = Gtk.Settings.get_default();
-        gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
-    }
-
     vfunc_startup() {
         super.vfunc_startup();
 
@@ -252,22 +246,15 @@ var Application = GObject.registerClass({
             'osm-account-setup': {
                 onActivate: this._onOsmAccountSetupActivate.bind(this)
             },
-            'night-mode': {
-                paramType:     'b',
-                onChangeState: this._onNightModeChange.bind(this),
-                setting:       'night-mode'
-            },
             'quit': {
                 onActivate: () => this.quit(),
                 accels: ['<Primary>Q']
             }
         }, settings);
 
-        // set dark theme when night-mode is enabled
-        let gtkSettings = Gtk.Settings.get_default();
 
-        gtkSettings.gtk_application_prefer_dark_theme =
-            settings.get('night-mode');
+        this._styleManager = Hdy.StyleManager.get_default();
+        this._styleManager.set_color_scheme(Hdy.ColorScheme.PREFER_LIGHT);
 
         Gtk.IconTheme.get_default().append_search_path(GLib.build_filenamev([pkg.pkgdatadir,
                                                                              'icons']));
diff --git a/src/layersPopover.js b/src/layersPopover.js
index 70f25657..d421b71f 100644
--- a/src/layersPopover.js
+++ b/src/layersPopover.js
@@ -21,6 +21,7 @@ const Champlain = imports.gi.Champlain;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Gdk = imports.gi.Gdk;
+const Hdy = imports.gi.Handy;
 
 const Application = imports.application;
 const MapSource = imports.mapSource;
@@ -144,8 +145,8 @@ var LayersPopover = GObject.registerClass({
                                        this._setLayerPreviews.bind(this));
             this._mapView.view.connect("notify::longitude",
                                        this._setLayerPreviews.bind(this));
-            Application.settings.connect("changed::night-mode",
-                                         this._onNightModeChanged.bind(this));
+            Hdy.StyleManager.get_default().connect("notify::dark",
+                                                    this._onDarkChanged.bind(this));
             Application.settings.connect("changed::hybrid-aerial",
                                          this._onHybridAerialChanged.bind(this));
 
@@ -160,9 +161,9 @@ var LayersPopover = GObject.registerClass({
         });
     }
 
-    _onNightModeChanged() {
+    _onDarkChanged() {
         if (Service.getService().tiles.streetDark &&
-            Application.settings.get('night-mode')) {
+            Hdy.StyleManager.get_default().dark) {
             this._setLayerPreviewImage('streetDark', true);
         } else {
             this._setLayerPreviewImage('street', true);
@@ -180,7 +181,7 @@ var LayersPopover = GObject.registerClass({
 
     _setLayerPreviews() {
         if (Service.getService().tiles.streetDark &&
-            Application.settings.get('night-mode')) {
+            Hdy.StyleManager.get_default().dark) {
             this._setLayerPreviewImage('streetDark');
         } else {
             this._setLayerPreviewImage('street');
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 9abceb46..08446e36 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -86,7 +86,7 @@ var MainWindow = GObject.registerClass({
                         'noNetworkView',
                         'actionBar',
                         'actionBarRevealer',
-                        'placeBarContainer' ]
+                        'placeBarContainer']
 }, class MainWindow extends Gtk.ApplicationWindow {
 
     get mapView() {
diff --git a/src/mapView.js b/src/mapView.js
index 10e6d5a3..fef736c2 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -26,6 +26,7 @@ const Geocode = imports.gi.GeocodeGlib;
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const GtkChamplain = imports.gi.GtkChamplain;
+const Hdy = imports.gi.Handy;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
@@ -210,8 +211,8 @@ var MapView = GObject.registerClass({
 
         // if dark tiles is available, setup handler to switch style
         if (Service.getService().tiles.streetDark) {
-            Application.settings.connect('changed::night-mode',
-                                         this._onNightModeChanged.bind(this));
+            Hdy.StyleManager.get_default().connect('notify::dark',
+                                                    this._onDarkChanged.bind(this));
         }
 
         // if hybrid aerial tiles are available, setup handler to toggle
@@ -272,11 +273,11 @@ var MapView = GObject.registerClass({
         this._setBackgroundPatternIfNeeded();
     }
 
-    _onNightModeChanged() {
+    _onDarkChanged() {
         if (this._mapType === MapType.STREET) {
             let overlay_sources = this.view.get_overlay_sources();
 
-            if (Application.settings.get('night-mode'))
+            if (Hdy.StyleManager.get_default().dark)
                 this.view.map_source = MapSource.createStreetDarkSource();
             else
                 this.view.map_source = MapSource.createStreetSource();
@@ -428,7 +429,7 @@ var MapView = GObject.registerClass({
                 }
             } else {
                 if (tiles.streetDark &&
-                    Application.settings.get('night-mode')) {
+                    Hdy.StyleManager.get_default().dark) {
                     this.view.map_source = MapSource.createStreetDarkSource();
                 } else {
                     this.view.map_source = MapSource.createStreetSource();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]