Use GSettings to store variants (Fix #11)
This commit is contained in:
@@ -31,6 +31,7 @@ build: build-clean
|
||||
--extra-source=./config.js \
|
||||
--extra-source=./utils.js \
|
||||
--extra-source=./modules/ \
|
||||
--extra-source=./schemas/ \
|
||||
--podir=./po/ \
|
||||
--gettext-domain=$(UUID) \
|
||||
--out-dir=./build \
|
||||
@@ -73,7 +74,7 @@ pot:
|
||||
--package-name="$(NAME)" \
|
||||
--package-version="$(VERSION)" \
|
||||
--output=./src/po/$(UUID).pot \
|
||||
./src/**/*.js
|
||||
./src/**/*.js ./src/**/*.xml
|
||||
sed -i '1,4s/SOME DESCRIPTIVE TITLE./$(NAME)/g' ./src/po/$(UUID).pot
|
||||
sed -i '1,4s/YEAR/$(COPYRIGHT_YEAR)/' ./src/po/$(UUID).pot
|
||||
sed -i "1,4s/THE PACKAGE'S COPYRIGHT HOLDER/$(AUTHOR_NAME)/" ./src/po/$(UUID).pot
|
||||
|
||||
+3
-2
@@ -2,8 +2,9 @@
|
||||
"name": "Night Theme Switcher",
|
||||
"description": "Automatically toggle between your light and dark GTK theme variants when Night Light activates.",
|
||||
"uuid": "nightthemeswitcher@romainvigier.fr",
|
||||
"gettext-domain": "nightthemeswitcher@romainvigier.fr",
|
||||
"settings-schema": "org.gnome.shell.extensions.nightthemeswitcher",
|
||||
"url": "https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/",
|
||||
"version": 22,
|
||||
"shell-version": ["3.32", "3.34", "3.36"],
|
||||
"gettext-domain": "nightthemeswitcher@romainvigier.fr"
|
||||
"version": 22
|
||||
}
|
||||
|
||||
+32
-31
@@ -27,8 +27,6 @@ const { log_debug } = Me.imports.utils;
|
||||
|
||||
const { Variants } = Me.imports.modules.Variants;
|
||||
|
||||
const State = new Map();
|
||||
|
||||
|
||||
/*
|
||||
The Themer communicates with the system to get the current theme or set a new
|
||||
@@ -40,14 +38,17 @@ var Themer = class {
|
||||
|
||||
constructor() {
|
||||
log_debug('Initializing Themer...');
|
||||
this.gsettings = new Gio.Settings({ schema: config.THEME_GSETTINGS_SCHEMA });
|
||||
this.settings = extensionUtils.getSettings();
|
||||
this.theme_gsettings = new Gio.Settings({ schema: config.THEME_GSETTINGS_SCHEMA });
|
||||
log_debug('Themer initialized.');
|
||||
}
|
||||
|
||||
enable() {
|
||||
log_debug('Enabling Themer...');
|
||||
this.ready = false;
|
||||
this._listen_to_theme_changes();
|
||||
this._update_variants();
|
||||
this.update_variants();
|
||||
this.ready = true;
|
||||
this.emit();
|
||||
log_debug('Themer enabled.');
|
||||
}
|
||||
@@ -55,22 +56,22 @@ var Themer = class {
|
||||
disable() {
|
||||
log_debug('Disabling Themer...');
|
||||
this._stop_listening_to_theme_changes();
|
||||
// GNOME Shell disables extensions when locking the screen. We'll only reset the theme if the user disables the extension.
|
||||
State.set('last_disabled_on_screen_lock', main.screenShield.locked);
|
||||
if ( !State.get('last_disabled_on_screen_lock') ) {
|
||||
log_debug('Resetting the user\'s original theme...')
|
||||
// GNOME Shell disables extensions when locking the screen. We'll only
|
||||
// reset the theme if the user disables the extension to prevent
|
||||
// flickering when unlocking.
|
||||
if ( !main.screenShield.locked ) {
|
||||
this.reset_theme();
|
||||
}
|
||||
log_debug('Themer disabled.');
|
||||
}
|
||||
|
||||
get current() {
|
||||
return this.gsettings.get_string(config.THEME_GSETTINGS_PROPERTY);
|
||||
get current_theme() {
|
||||
return this.theme_gsettings.get_string(config.THEME_GSETTINGS_PROPERTY);
|
||||
}
|
||||
|
||||
set current(theme) {
|
||||
if ( theme !== this.current ) {
|
||||
this.gsettings.set_string(config.THEME_GSETTINGS_PROPERTY, theme);
|
||||
set current_theme(theme) {
|
||||
if ( theme !== this.current_theme ) {
|
||||
this.theme_gsettings.set_string(config.THEME_GSETTINGS_PROPERTY, theme);
|
||||
log_debug(`Theme has been set to "${theme}".`);
|
||||
}
|
||||
}
|
||||
@@ -86,38 +87,38 @@ var Themer = class {
|
||||
}
|
||||
|
||||
set_variant(variant) {
|
||||
if ( variant && this.variants ) {
|
||||
this.current = this.variants.get(variant);
|
||||
if ( this.ready ) {
|
||||
log_debug(`Setting theme to the "${variant}" variant...`);
|
||||
this.current_theme = this.settings.get_string(`theme-${variant}`);
|
||||
}
|
||||
}
|
||||
|
||||
reset_theme() {
|
||||
this.current = State.get('original_theme');
|
||||
this.set_variant('original');
|
||||
log_debug('Theme has been reset to the user\'s original variant.')
|
||||
}
|
||||
|
||||
update_variants() {
|
||||
if ( this.variants ) {
|
||||
const new_theme = this.current;
|
||||
if ( new_theme && new_theme !== this.variants.get('day') && new_theme !== this.variants.get('night') ) {
|
||||
this._update_variants();
|
||||
}
|
||||
if ( !this._are_variants_up_to_date() ) {
|
||||
this._update_variants();
|
||||
}
|
||||
}
|
||||
|
||||
_update_variants() {
|
||||
if ( this.current ) {
|
||||
this.variants = Variants.guess_from(this.current);
|
||||
if ( !State.get('last_disabled_on_screen_lock') ) {
|
||||
State.set('original_theme', this.variants.get('original'));
|
||||
}
|
||||
log_debug(`Variants updated: {day: "${this.variants.get('day')}", night: "${this.variants.get('night')}"}`);
|
||||
if ( this.current_theme ) {
|
||||
const variants = Variants.guess_from(this.current_theme);
|
||||
variants.forEach( (theme, variant) => this.settings.set_string(`theme-${variant}`, theme) );
|
||||
log_debug(`Variants updated: {day: "${variants.get('day')}", night: "${variants.get('night')}"}`);
|
||||
}
|
||||
}
|
||||
|
||||
_are_variants_up_to_date() {
|
||||
return ( this.current_theme === this.settings.get_string('theme-day') || this.current_theme === this.settings.get_string('theme-night') );
|
||||
}
|
||||
|
||||
_listen_to_theme_changes() {
|
||||
if ( !this.theme_change_connect ) {
|
||||
this.theme_change_connect = this.gsettings.connect(
|
||||
this.theme_change_connect = this.theme_gsettings.connect(
|
||||
'changed::' + config.THEME_GSETTINGS_PROPERTY,
|
||||
this._on_theme_change.bind(this)
|
||||
);
|
||||
@@ -126,15 +127,15 @@ var Themer = class {
|
||||
}
|
||||
|
||||
_stop_listening_to_theme_changes() {
|
||||
if ( this.gsettings && this.theme_change_connect ){
|
||||
this.gsettings.disconnect(this.theme_change_connect);
|
||||
if ( this.theme_gsettings && this.theme_change_connect ){
|
||||
this.theme_gsettings.disconnect(this.theme_change_connect);
|
||||
this.theme_change_connect = null;
|
||||
log_debug('Stopped listening for theme changes.');
|
||||
}
|
||||
}
|
||||
|
||||
_on_theme_change() {
|
||||
log_debug(`Theme has changed to "${this.current}".`);
|
||||
log_debug(`Theme has changed to "${this.current_theme}".`);
|
||||
this.emit();
|
||||
}
|
||||
|
||||
|
||||
+31
-8
@@ -7,8 +7,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Night Theme Switcher 7\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-02-26 17:37+0100\n"
|
||||
"PO-Revision-Date: 2020-02-25 20:31+0100\n"
|
||||
"POT-Creation-Date: 2020-04-12 14:18+0200\n"
|
||||
"PO-Revision-Date: 2020-04-12 14:21+0200\n"
|
||||
"Last-Translator: Romain Vigier <>\n"
|
||||
"Language-Team: French <none>\n"
|
||||
"Language: fr\n"
|
||||
@@ -18,7 +18,7 @@ msgstr ""
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
|
||||
"X-Generator: Gtranslator 3.34.0\n"
|
||||
|
||||
#: src/modules/Nightlighter.js:99
|
||||
#: src/modules/Nightlighter.js:101
|
||||
msgid ""
|
||||
"Night Light must be enabled to use this extension. Please enable it in your "
|
||||
"system settings."
|
||||
@@ -26,14 +26,37 @@ msgstr ""
|
||||
"Le mode nuit doit être activé pour utiliser l’extension. Veuillez l’activer "
|
||||
"dans les réglages du système."
|
||||
|
||||
#: src/modules/Nightlighter.js:132
|
||||
msgid "Unable to connect to the session bus."
|
||||
msgstr "Impossible de se connecter au bus de la session."
|
||||
|
||||
#: src/modules/Nightlighter.js:145
|
||||
#: src/modules/Nightlighter.js:144
|
||||
msgid "Unable to create proxy to the session bus."
|
||||
msgstr "Impossible de créer une passerelle vers le bus de la session."
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:6
|
||||
msgid "Original theme"
|
||||
msgstr "Thème original"
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:7
|
||||
msgid "The theme to restore if the extension is disabled"
|
||||
msgstr "Thème à restaurer si l’extension est désactivée"
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:11
|
||||
msgid "Day theme"
|
||||
msgstr "Thème diurne"
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:12
|
||||
msgid "The theme to use during daytime"
|
||||
msgstr "Thème à utiliser pendant la journée"
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:16
|
||||
msgid "Night theme"
|
||||
msgstr "Thème nocturne"
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:17
|
||||
msgid "The theme to use during nighttime"
|
||||
msgstr "Thème à utiliser pendant la nuit"
|
||||
|
||||
#~ msgid "Unable to connect to the session bus."
|
||||
#~ msgstr "Impossible de se connecter au bus de la session."
|
||||
|
||||
#~ msgid "Errors occured while disabling the extension, try removing it."
|
||||
#~ msgstr ""
|
||||
#~ "Des erreurs sont survenues en désactivant l’extension, essayez de la "
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Night Theme Switcher 18\n"
|
||||
"Project-Id-Version: Night Theme Switcher 22\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-02-26 17:37+0100\n"
|
||||
"POT-Creation-Date: 2020-04-12 14:18+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -17,16 +17,36 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: src/modules/Nightlighter.js:99
|
||||
#: src/modules/Nightlighter.js:101
|
||||
msgid ""
|
||||
"Night Light must be enabled to use this extension. Please enable it in your "
|
||||
"system settings."
|
||||
msgstr ""
|
||||
|
||||
#: src/modules/Nightlighter.js:132
|
||||
msgid "Unable to connect to the session bus."
|
||||
msgstr ""
|
||||
|
||||
#: src/modules/Nightlighter.js:145
|
||||
#: src/modules/Nightlighter.js:144
|
||||
msgid "Unable to create proxy to the session bus."
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:6
|
||||
msgid "Original theme"
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:7
|
||||
msgid "The theme to restore if the extension is disabled"
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:11
|
||||
msgid "Day theme"
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:12
|
||||
msgid "The theme to use during daytime"
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:16
|
||||
msgid "Night theme"
|
||||
msgstr ""
|
||||
|
||||
#: src/schemas/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml:17
|
||||
msgid "The theme to use during nighttime"
|
||||
msgstr ""
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schemalist gettext-domain="nightthemeswitcher@romainvigier.fr">
|
||||
<schema id="org.gnome.shell.extensions.nightthemeswitcher" path="/org/gnome/shell/extensions/nightthemeswitcher/">
|
||||
<key name="theme-original" type="s">
|
||||
<default>""</default>
|
||||
<summary>Original theme</summary>
|
||||
<description>The theme to restore if the extension is disabled</description>
|
||||
</key>
|
||||
<key name="theme-day" type="s">
|
||||
<default>""</default>
|
||||
<summary>Day theme</summary>
|
||||
<description>The theme to use during daytime</description>
|
||||
</key>
|
||||
<key name="theme-night" type="s">
|
||||
<default>""</default>
|
||||
<summary>Night theme</summary>
|
||||
<description>The theme to use during nighttime</description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
Reference in New Issue
Block a user