Only warn user once when Night Light is disabled

This commit is contained in:
Romain Vigier
2020-02-27 14:25:13 +01:00
parent 199470bd84
commit 769b3dc00a
+12 -2
View File
@@ -34,20 +34,22 @@ The Nightlighter establishes a connection with the session bus to get the
current Night Light status. It listens to changes and reports them.
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.
if it is enabled and warns the user if that's not the case. To not overwhelm
the user with notifications, it only warns once and then only listens to Night
Light changes to reactivate itself automatically.
*/
var Nightlighter = class {
constructor() {
log_debug('Initializing Nightlighter...');
this.first_nightlight_not_enabled_warning = true;
this.nightlight_gsettings = new Gio.Settings({ schema: config.NIGHTLIGHT_GSETTINGS_SCHEMA });
log_debug('Nightlighter initialized.');
}
enable() {
log_debug('Enabling NightLighter...');
// As Night Light must be enabled for the extension to work, we have to monitor any change of that setting.
try {
this._listen_to_nightlight_status();
this._check_nightlight_status();
@@ -57,9 +59,11 @@ var Nightlighter = class {
log_debug('Nightlighter enabled.');
}
catch(e) {
if ( e.message ) {
main.notifyError(config.EXT_NAME, e.message);
}
}
}
disable() {
log_debug('Disabling Nightlighter...');
@@ -96,9 +100,15 @@ var Nightlighter = class {
_check_nightlight_status() {
if ( !this._is_nightlight_enabled() ) {
if ( this.first_nightlight_not_enabled_warning ) {
this.first_nightlight_not_enabled_warning = false;
const message = _('Night Light must be enabled to use this extension. Please enable it in your system settings.');
throw new Error(message);
}
else {
throw new Error();
}
}
}
_listen_to_nightlight_status() {