From ac27c364f3d1c04ff279a981886642b132fa56c2 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 20 Nov 2020 17:37:41 +0100 Subject: [PATCH] Add dark theme support #13 --- clapper_src/app.js | 24 +++++++++++++++++--- clapper_src/prefs.js | 3 +++ data/com.github.rafostar.Clapper.gschema.xml | 4 ++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index ac03060e..fceb5c73 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -21,6 +21,8 @@ class ClapperApp extends Gtk.Application playlist: [], }; Object.assign(this, defaults, opts); + + this.doneFirstActivate = false; } vfunc_startup() @@ -70,9 +72,9 @@ class ClapperApp extends Gtk.Application { super.vfunc_activate(); - this.windowShowSignal = this.active_window.connect( - 'show', this._onWindowShow.bind(this) - ); + if(!this.doneFirstActivate) + this._onFirstActivate(); + this.active_window.present(); } @@ -81,6 +83,22 @@ class ClapperApp extends Gtk.Application super.run(arr || []); } + _onFirstActivate() + { + let gtkSettings = Gtk.Settings.get_default(); + settings.bind( + 'dark-theme', gtkSettings, + 'gtk_application_prefer_dark_theme', + Gio.SettingsBindFlags.GET + ); + + this.windowShowSignal = this.active_window.connect( + 'show', this._onWindowShow.bind(this) + ); + + this.doneFirstActivate = true; + } + _onWindowShow(window) { window.disconnect(this.windowShowSignal); diff --git a/clapper_src/prefs.js b/clapper_src/prefs.js index 926674e0..b2865a4d 100644 --- a/clapper_src/prefs.js +++ b/clapper_src/prefs.js @@ -22,6 +22,9 @@ class ClapperGeneralPage extends PrefsBase.Grid let spinButton = this.addSpinButton('Value (percentage)', 0, 200, 'volume-value'); this._onVolumeInitialChanged(spinButton, comboBox); comboBox.connect('changed', this._onVolumeInitialChanged.bind(this, spinButton)); + + this.addTitle('Appearance'); + this.addCheckButton('Enable dark theme', 'dark-theme'); } _onVolumeInitialChanged(spinButton, comboBox) diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml index 073911e0..5deace13 100644 --- a/data/com.github.rafostar.Clapper.gschema.xml +++ b/data/com.github.rafostar.Clapper.gschema.xml @@ -14,6 +14,10 @@ 100 Custom initial volume value after startup + + false + Enable to force the app to use dark theme variant +