Skip to content

Commit

Permalink
Application: Add GSetings support and save night-mode state
Browse files Browse the repository at this point in the history
  • Loading branch information
birros committed Aug 2, 2018
1 parent 4bf6cb5 commit ea9e8b6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
13 changes: 13 additions & 0 deletions build-aux/post_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

import os
import subprocess

prefix = os.environ.get('MESON_INSTALL_PREFIX', '/usr/local')
datadir = os.path.join(prefix, 'share')

# Packaging tools define DESTDIR and this isn't needed for them
if 'DESTDIR' not in os.environ:
print('Compiling gsettings schemas...')
subprocess.call(['glib-compile-schemas',
os.path.join(datadir, 'glib-2.0', 'schemas')])
9 changes: 9 additions & 0 deletions data/gsettings/com.github.birros.WebArchives.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<schemalist gettext-domain="web-archives">
<schema id="com.github.birros.WebArchives" path="/com/github/birros/WebArchives/">
<key name="night-mode" type="b">
<default>false</default>
<summary>Night mode</summary>
<description>Night mode state</description>
</key>
</schema>
</schemalist>
5 changes: 5 additions & 0 deletions data/gsettings/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
schemadir = join_paths(get_option('datadir'), 'glib-2.0', 'schemas')

install_data('com.github.birros.WebArchives.gschema.xml',
install_dir: schemadir
)
1 change: 1 addition & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
subdir('appdata')
subdir('desktop')
subdir('gsettings')
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ handy_dep = dependency('libhandy-0.0', version : '>=0.0.1')
darkreader_sp = subproject('darkreader')
darkreader_dep = darkreader_sp.get_variable('darkreader')

meson.add_install_script (
join_paths('build-aux', 'post_install.py')
)

subdir('src')
subdir('data')
subdir('po')
17 changes: 13 additions & 4 deletions src/app/application.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public class WebArchives.Application : Gtk.Application {
private Context context;
private Persistence persistence;
private GLib.Settings settings;
private const OptionEntry [] option_entries = {
{
"version", 'v', 0,
Expand Down Expand Up @@ -50,6 +51,9 @@ public class WebArchives.Application : Gtk.Application {
protected override void startup () {
base.startup ();

settings = new Settings ("com.github.birros.WebArchives");
settings.changed["night-mode"].connect (on_gsettings_night_mode);

add_action_entries (action_entries, this);
set_accels_for_action ("app.quit", {"<Primary>q"});

Expand All @@ -58,6 +62,7 @@ public class WebArchives.Application : Gtk.Application {

context.tracker.refresh ();
context.night_mode_state.notify["active"].connect (on_night_mode);
context.night_mode_state.active = settings.get_boolean ("night-mode");
info ("server_url: %s\n", context.server.url);

// styles
Expand Down Expand Up @@ -87,10 +92,14 @@ public class WebArchives.Application : Gtk.Application {
}

private void on_night_mode () {
Gtk.Settings settings = Gtk.Settings.get_default ();
settings.set_property (
"gtk-application-prefer-dark-theme",
context.night_mode_state.active
settings.set_boolean ("night-mode", context.night_mode_state.active);
}

private void on_gsettings_night_mode () {
bool night_mode = settings.get_boolean ("night-mode");
Gtk.Settings gtk_settings = Gtk.Settings.get_default ();
gtk_settings.set_property (
"gtk-application-prefer-dark-theme", night_mode
);
}

Expand Down

0 comments on commit ea9e8b6

Please sign in to comment.