[gnome-maps/wip/mlundblad/night-mode: 3/3] application: Add action for toggling night mode



commit 62ef2a3d58f4ebf207381a40f2ff896883f82979
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Jun 2 22:35:06 2020 +0200

    application: Add action for toggling night mode

 src/application.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/src/application.js b/src/application.js
index ab2252e6..ce5cdb07 100644
--- a/src/application.js
+++ b/src/application.js
@@ -225,6 +225,26 @@ var Application = GObject.registerClass({
         }
     }
 
+    _onNightModeChange() {
+        let state = action.get_state();
+        settings.set_value('night-mode', GLib.Variant.new('b', !state.get_boolean()));
+    }
+
+    _nightModeCreateHook(action) {
+        settings.connect('changed::night-mode', () => {
+            let state = settings.get_value('night-mode');
+            if (state.get_boolean() != action.state.get_boolean())
+                action.change_state(state);
+
+            let gtkSettings = Gtk.Settings.get_default();
+            gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
+        });
+
+        let state = settings.get_value('night-mode');
+        let gtkSettings = Gtk.Settings.get_default();
+        gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
+    }
+
     vfunc_startup() {
         super.vfunc_startup();
 
@@ -243,6 +263,11 @@ var Application = GObject.registerClass({
             'osm-account-setup': {
                 onActivate: this._onOsmAccountSetupActivate.bind(this)
             },
+            'night-mode': {
+                onStateChange: this._onNightModeChange.bind(this),
+                createHook:    this._nightModeCreateHook.bind(this),
+                state:         settings.get_value('night-mode')
+            },
             'quit': {
                 onActivate: () => this.quit(),
                 accels: ['<Primary>Q']


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