GSettings
via GLib.Settings
. GSettings allows your app to save certain stateful information in the form of booleans, strings, arrays, and more. It's a great solution for window size and position as well as whether certain modes are enabled or not. Note that GSettings is ideal for small amounts of configuration or stateful data, but user data (i.e. documents) should be stored on the disk.data/
folder, create a new file named gschema.xml
. Inside it, let's define a key for the switch:path
and id
attributes are your app's ID (path
in a /
format while id
is the standard dot-separated format). Note the key's name
and type
attributes: the name is a string to reference the setting, while in this case type="b"
defines the setting as a boolean. The key's summary and description are developer-facing and are exposed in developer tools like dconf Editor.GLib.Settings.bind ()
on Valadoc, but for now this will bind the active
property of the switch to the value of useless-setting
in GSettings. When one changes, the other will stay in sync to reflect it.data/meson.build
and type the following:meson/post_install.py
that contains the following:ninja install
to avoid crashes from not-yet-installed settings.useless-setting
update in real time when you toggle your switch.