Use GSettings to store variants (Fix #11)

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