Merge branch 'check-nightlight' into 'master'
Check if Night Light is enabled See merge request rmnvgr/nightthemeswitcher-gnome-shell-extension!5
This commit is contained in:
@@ -72,7 +72,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
|
||||||
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
|
||||||
|
|||||||
+5
-2
@@ -19,5 +19,8 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
|||||||
var EXT_NAME = 'Night Theme Switcher';
|
var EXT_NAME = 'Night Theme Switcher';
|
||||||
var EXT_UUID = 'nightthemeswitcher@romainvigier.fr';
|
var EXT_UUID = 'nightthemeswitcher@romainvigier.fr';
|
||||||
|
|
||||||
var GSETTINGS_SCHEMA = 'org.gnome.desktop.interface';
|
var THEME_GSETTINGS_SCHEMA = 'org.gnome.desktop.interface';
|
||||||
var GSETTINGS_PROPERTY = 'gtk-theme';
|
var THEME_GSETTINGS_PROPERTY = 'gtk-theme';
|
||||||
|
|
||||||
|
var NIGHTLIGHT_GSETTINGS_SCHEMA = 'org.gnome.settings-daemon.plugins.color';
|
||||||
|
var NIGHTLIGHT_GSETTINGS_PROPERTY = 'night-light-enabled';
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
const { extensionUtils } = imports.misc;
|
const { extensionUtils } = imports.misc;
|
||||||
const { Gio } = imports.gi;
|
const { Gio } = imports.gi;
|
||||||
|
const { main } = imports.ui;
|
||||||
|
|
||||||
const Me = extensionUtils.getCurrentExtension();
|
const Me = extensionUtils.getCurrentExtension();
|
||||||
const config = Me.imports.config;
|
const config = Me.imports.config;
|
||||||
@@ -29,39 +30,86 @@ const _ = Gettext.gettext;
|
|||||||
/*
|
/*
|
||||||
The Nightlighter establishes a connection with the session bus to get the
|
The Nightlighter establishes a connection with the session bus to get the
|
||||||
current Night Light status. It can also be asked to listen to status changes.
|
current Night Light status. It can also be asked to listen to status changes.
|
||||||
|
|
||||||
|
As Night Light is essential for the extension to work, it continuously checks
|
||||||
|
if it is enabled and warns the user if that's not the case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Nightlighter = class {
|
var Nightlighter = class {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.nightlight_gsettings = new Gio.Settings({ schema: config.NIGHTLIGHT_GSETTINGS_SCHEMA });
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
// As Night Light must be enabled for the extension to work, we have to monitor any change of that setting.
|
||||||
|
this._listen_to_nightlight_status();
|
||||||
try {
|
try {
|
||||||
|
this._check_nightlight_status();
|
||||||
this._connect_to_dbus();
|
this._connect_to_dbus();
|
||||||
|
this._listen_to_nightlight_changes();
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
throw e; // Let's pass the error up.
|
main.notifyError(config.EXT_NAME, e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
this._stop_listening_to_nightlight_status();
|
||||||
|
this._stop_listening_to_nightlight_changes();
|
||||||
|
}
|
||||||
|
|
||||||
get status() {
|
get status() {
|
||||||
|
if ( !this.proxy ) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return this.proxy.get_cached_property('NightLightActive').get_boolean();
|
return this.proxy.get_cached_property('NightLightActive').get_boolean();
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
return false; // If Night Light is disabled, we consider it is inactive.
|
return false; // Sometimes when Night Light hasn't changed colors yet it returns an error, we consider it is inactive.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(callback) {
|
subscribe(callback) {
|
||||||
this.connect = this.proxy.connect('g-properties-changed', callback);
|
this.nightlight_change_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_listening() {
|
emit() {
|
||||||
if ( this.proxy && this.connect ) {
|
if ( !this.nightlight_change_callback ) return;
|
||||||
this.proxy.disconnect(this.connect);
|
this.nightlight_change_callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
_is_nightlight_enabled() {
|
||||||
|
return this.nightlight_gsettings.get_boolean(config.NIGHTLIGHT_GSETTINGS_PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
_check_nightlight_status() {
|
||||||
|
if ( !this._is_nightlight_enabled() ) {
|
||||||
|
const message = _('Night Light must be enabled to use this extension. Please enable it in your system settings.');
|
||||||
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_listen_to_nightlight_status() {
|
||||||
|
if ( this.nightlight_status_connect ) return;
|
||||||
|
this.nightlight_status_connect = this.nightlight_gsettings.connect('changed::' + config.NIGHTLIGHT_GSETTINGS_PROPERTY, this._on_nightlight_status_change.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
_stop_listening_to_nightlight_status() {
|
||||||
|
if ( this.nightlight_gsettings && this.nightlight_status_connect ) {
|
||||||
|
this.nightlight_gsettings.disconnect(this.nightlight_status_connect);
|
||||||
|
this.nightlight_status_connect = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_on_nightlight_status_change() {
|
||||||
|
this.enable();
|
||||||
|
this.emit();
|
||||||
|
}
|
||||||
|
|
||||||
_connect_to_dbus() {
|
_connect_to_dbus() {
|
||||||
|
if ( this.proxy ) return;
|
||||||
const connection = Gio.bus_get_sync(Gio.BusType.SESSION, null);
|
const connection = Gio.bus_get_sync(Gio.BusType.SESSION, null);
|
||||||
if ( connection === null ) {
|
if ( connection === null ) {
|
||||||
const message = _('Unable to connect to the session bus.');
|
const message = _('Unable to connect to the session bus.');
|
||||||
@@ -82,4 +130,16 @@ var Nightlighter = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_listen_to_nightlight_changes() {
|
||||||
|
if ( this.connect ) return;
|
||||||
|
this.connect = this.proxy.connect('g-properties-changed', this.emit.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
_stop_listening_to_nightlight_changes() {
|
||||||
|
if ( this.proxy && this.connect ) {
|
||||||
|
this.proxy.disconnect(this.connect);
|
||||||
|
this.connect == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ var Switcher = class {
|
|||||||
this.theme.listen(this._on_theme_change.bind(this));
|
this.theme.listen(this._on_theme_change.bind(this));
|
||||||
|
|
||||||
this.nightlight = new Nightlighter();
|
this.nightlight = new Nightlighter();
|
||||||
this.nightlight.listen(this._apply_theme_variant.bind(this));
|
this.nightlight.enable();
|
||||||
|
this.nightlight.subscribe(this._apply_theme_variant.bind(this));
|
||||||
|
|
||||||
this._apply_theme_variant();
|
this._apply_theme_variant();
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ var Switcher = class {
|
|||||||
try {
|
try {
|
||||||
this.theme.current = this.variants.original;
|
this.theme.current = this.variants.original;
|
||||||
this.theme.stop_listening();
|
this.theme.stop_listening();
|
||||||
this.nightlight.stop_listening();
|
this.nightlight.disable();
|
||||||
}
|
}
|
||||||
catch(e) {} // Since we're disabling, we'll just ignore errors.
|
catch(e) {} // Since we're disabling, we'll just ignore errors.
|
||||||
finally {
|
finally {
|
||||||
@@ -78,7 +79,12 @@ var Switcher = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_apply_theme_variant() {
|
_apply_theme_variant() {
|
||||||
this.theme.current = this.nightlight.status ? this.variants.night : this.variants.day;
|
try {
|
||||||
|
this.theme.current = this.nightlight.status ? this.variants.night : this.variants.day;
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
this.theme.current = this.variants.original;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_on_theme_change() {
|
_on_theme_change() {
|
||||||
|
|||||||
@@ -31,20 +31,20 @@ one. It can also be asked to listen to theme changes.
|
|||||||
var Themer = class {
|
var Themer = class {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.gsettings = new Gio.Settings({ schema: config.GSETTINGS_SCHEMA });
|
this.gsettings = new Gio.Settings({ schema: config.THEME_GSETTINGS_SCHEMA });
|
||||||
}
|
}
|
||||||
|
|
||||||
get current() {
|
get current() {
|
||||||
return this.gsettings.get_string(config.GSETTINGS_PROPERTY);
|
return this.gsettings.get_string(config.THEME_GSETTINGS_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
set current(theme) {
|
set current(theme) {
|
||||||
if ( theme === this.current ) return;
|
if ( theme === this.current ) return;
|
||||||
this.gsettings.set_string(config.GSETTINGS_PROPERTY, theme);
|
this.gsettings.set_string(config.THEME_GSETTINGS_PROPERTY, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(callback) {
|
listen(callback) {
|
||||||
this.connect = this.gsettings.connect('changed::' + config.GSETTINGS_PROPERTY, callback);
|
this.connect = this.gsettings.connect('changed::' + config.THEME_GSETTINGS_PROPERTY, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_listening() {
|
stop_listening() {
|
||||||
|
|||||||
+13
-5
@@ -1,14 +1,14 @@
|
|||||||
# Night Theme Switcher
|
# Night Theme Switcher
|
||||||
# Copyright (C) 2019 Romain Vigier
|
# Copyright (C) 2019 Romain Vigier
|
||||||
# This file is distributed under the same license as the Night Theme Switcher package.
|
# This file is distributed under the same license as the Night Theme Switcher package.
|
||||||
# Romain Vigier <>, 2019.
|
# Romain Vigier <>, 2019-2020.
|
||||||
#
|
#
|
||||||
msgid ""
|
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-08 23:18+0100\n"
|
"POT-Creation-Date: 2020-02-25 20:28+0100\n"
|
||||||
"PO-Revision-Date: 2019-11-25 00:28+0100\n"
|
"PO-Revision-Date: 2020-02-25 20:31+0100\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,11 +18,19 @@ 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/extension.js:150
|
#: src/modules/Nightlighter.js:86
|
||||||
|
msgid ""
|
||||||
|
"Night Light must be enabled to use this extension. Please enable it in your "
|
||||||
|
"system settings."
|
||||||
|
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:112
|
||||||
msgid "Unable to connect to the session bus."
|
msgid "Unable to connect to the session bus."
|
||||||
msgstr "Impossible de se connecter au bus de la session."
|
msgstr "Impossible de se connecter au bus de la session."
|
||||||
|
|
||||||
#: src/extension.js:163
|
#: src/modules/Nightlighter.js:125
|
||||||
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."
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
# Night Theme Switcher
|
# Night Theme Switcher
|
||||||
# Copyright (C) 2019 Romain Vigier
|
# Copyright (C) 2019, 2020 Romain Vigier
|
||||||
# This file is distributed under the same license as the Night Theme Switcher package.
|
# This file is distributed under the same license as the Night Theme Switcher package.
|
||||||
# Romain Vigier <>, 2019.
|
# Romain Vigier <>, 2019, 2020.
|
||||||
#
|
#
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Night Theme Switcher 12\n"
|
"Project-Id-Version: Night Theme Switcher 17\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-02-08 23:18+0100\n"
|
"POT-Creation-Date: 2020-02-25 20:28+0100\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,10 +17,16 @@ 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/extension.js:150
|
#: src/modules/Nightlighter.js:86
|
||||||
|
msgid ""
|
||||||
|
"Night Light must be enabled to use this extension. Please enable it in your "
|
||||||
|
"system settings."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/Nightlighter.js:112
|
||||||
msgid "Unable to connect to the session bus."
|
msgid "Unable to connect to the session bus."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/extension.js:163
|
#: src/modules/Nightlighter.js:125
|
||||||
msgid "Unable to create proxy to the session bus."
|
msgid "Unable to create proxy to the session bus."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user