Use ESLint and reformat code

This commit is contained in:
Romain
2020-08-01 07:31:53 +00:00
parent 35c6b8fa33
commit 728ae6ef40
77 changed files with 4129 additions and 3302 deletions
+126 -125
View File
@@ -22,7 +22,7 @@ const Signals = imports.signals;
const Me = extensionUtils.getCurrentExtension();
const e = Me.imports.extension;
const { log_debug } = Me.imports.utils;
const { logDebug } = Me.imports.utils;
const { TimerNightlight } = Me.imports.modules.TimerNightlight;
const { TimerLocation } = Me.imports.modules.TimerLocation;
const { TimerSchedule } = Me.imports.modules.TimerSchedule;
@@ -37,156 +37,157 @@ const { TimerOndemand } = Me.imports.modules.TimerOndemand;
*
* It will try to use one of this three different time sources, in this order of
* preference:
* - Night Light
* - Location Services
* - Manual schedule
* - Night Light
* - Location Services
* - Manual schedule
*
* The user can manually force a specific time source and set the manual
* schedule in the extensions's preferences.
*/
var Timer = class {
constructor() {
this._source = null;
this._previous_time = null;
}
constructor() {
this._source = null;
this._previousTime = null;
this._nightlightStatusChangedConnect = null;
this._locationStatusChangedConnect = null;
this._manualTimeSourceChangedConnect = null;
this._timeSourceChangedConnect = null;
this._timeChangedConnect = null;
}
enable() {
log_debug('Enabling Timer...');
this._connect_settings();
this._create_source();
this._connect_source();
this._enable_source();
log_debug('Timer enabled.');
}
enable() {
logDebug('Enabling Timer...');
this._connectSettings();
this._createSource();
this._connectSource();
this._enableSource();
logDebug('Timer enabled.');
}
disable() {
log_debug('Disabling Timer...');
this._disconnect_source();
this._disable_source();
this._disconnect_settings();
log_debug('Timer disabled.');
}
disable() {
logDebug('Disabling Timer...');
this._disconnectSource();
this._disableSource();
this._disconnectSettings();
logDebug('Timer disabled.');
}
get time() {
return this._source.time;
}
get time() {
return this._source.time;
}
_connect_settings() {
log_debug('Connecting Timer to settings...');
this._nightlight_status_changed_connect = e.settingsManager.connect('nightlight-status-changed', this._on_source_changed.bind(this));
this._location_status_changed_connect = e.settingsManager.connect('location-status-changed', this._on_source_changed.bind(this));
this._manual_time_source_changed_connect = e.settingsManager.connect('manual-time-source-changed', this._on_source_changed.bind(this));
this._time_source_changed_connect = e.settingsManager.connect('time-source-changed', this._on_time_source_changed.bind(this));
}
_connectSettings() {
logDebug('Connecting Timer to settings...');
this._nightlightStatusChangedConnect = e.settingsManager.connect('nightlight-status-changed', this._onSourceChanged.bind(this));
this._locationStatusChangedConnect = e.settingsManager.connect('location-status-changed', this._onSourceChanged.bind(this));
this._manualTimeSourceChangedConnect = e.settingsManager.connect('manual-time-source-changed', this._onSourceChanged.bind(this));
this._timeSourceChangedConnect = e.settingsManager.connect('time-source-changed', this._onTimeSourceChanged.bind(this));
}
_disconnect_settings() {
if ( this._nightlight_status_changed_connect ) {
e.settingsManager.disconnect(this._nightlight_status_changed_connect);
this._nightlight_status_changed_connect = null;
}
if ( this._location_status_changed_connect ) {
e.settingsManager.disconnect(this._location_status_changed_connect);
this._location_status_changed_connect = null;
}
if ( this._manual_time_source_changed_connect ) {
e.settingsManager.disconnect(this._manual_time_source_changed_connect);
this._manual_time_source_changed_connect = null;
}
if ( this._time_source_changed_connect ) {
e.settingsManager.disconnect(this._time_source_changed_connect);
this._time_source_changed_connect = null;
}
log_debug('Disconnected Timer from settings.');
}
_disconnectSettings() {
if (this._nightlightStatusChangedConnect) {
e.settingsManager.disconnect(this._nightlightStatusChangedConnect);
this._nightlightStatusChangedConnect = null;
}
if (this._locationStatusChangedConnect) {
e.settingsManager.disconnect(this._locationStatusChangedConnect);
this._locationStatusChangedConnect = null;
}
if (this._manualTimeSourceChangedConnect) {
e.settingsManager.disconnect(this._manualTimeSourceChangedConnect);
this._manualTimeSourceChangedConnect = null;
}
if (this._timeSourceChangedConnect) {
e.settingsManager.disconnect(this._timeSourceChangedConnect);
this._timeSourceChangedConnect = null;
}
logDebug('Disconnected Timer from settings.');
}
_create_source() {
switch ( this._get_source() ) {
case 'nightlight':
this._source = new TimerNightlight();
break;
case 'location':
this._source = new TimerLocation();
break;
case 'schedule':
this._source = new TimerSchedule();
break;
case 'ondemand':
this._source = new TimerOndemand();
break;
}
}
_createSource() {
switch (this._getSource()) {
case 'nightlight':
this._source = new TimerNightlight();
break;
case 'location':
this._source = new TimerLocation();
break;
case 'schedule':
this._source = new TimerSchedule();
break;
case 'ondemand':
this._source = new TimerOndemand();
break;
}
}
_enable_source() {
this._source.enable();
}
_enableSource() {
this._source.enable();
}
_disable_source() {
if ( this._source ) {
this._source.disable();
this._source = null;
}
}
_disableSource() {
if (this._source) {
this._source.disable();
this._source = null;
}
}
_connect_source() {
log_debug('Connecting to time source...');
this._time_changed_connect = this._source.connect('time-changed', this._on_time_changed.bind(this));
}
_connectSource() {
logDebug('Connecting to time source...');
this._timeChangedConnect = this._source.connect('time-changed', this._onTimeChanged.bind(this));
}
_disconnect_source() {
if ( this._time_changed_connect ) {
this._source.disconnect(this._time_changed_connect);
this._time_changed_connect = null;
}
log_debug('Disconnected from time source.');
}
_disconnectSource() {
if (this._timeChangedConnect) {
this._source.disconnect(this._timeChangedConnect);
this._timeChangedConnect = null;
}
logDebug('Disconnected from time source.');
}
_on_source_changed() {
this.disable();
this.enable();
}
_onSourceChanged() {
this.disable();
this.enable();
}
_on_time_source_changed(settings, new_source) {
if ( e.settingsManager.manual_time_source ) {
this._on_source_changed();
}
}
_onTimeSourceChanged(_settings, _newSource) {
if (e.settingsManager.manualTimeSource)
this._onSourceChanged();
}
_on_time_changed(source, new_time) {
if ( new_time !== this._previous_time) {
log_debug(`Time has changed to ${new_time}.`);
this.emit('time-changed', new_time);
this._previous_time = new_time;
}
}
_onTimeChanged(_source, newTime) {
if (newTime !== this._previousTime) {
logDebug(`Time has changed to ${newTime}.`);
this.emit('time-changed', newTime);
this._previousTime = newTime;
}
}
_get_source() {
log_debug('Getting time source...');
_getSource() {
logDebug('Getting time source...');
if ( e.settingsManager.manual_time_source ) {
log_debug(`Time source is forced to ${e.settingsManager.time_source}.`);
return e.settingsManager.time_source;
}
if (e.settingsManager.manualTimeSource) {
logDebug(`Time source is forced to ${e.settingsManager.timeSource}.`);
return e.settingsManager.timeSource;
}
let source;
if ( e.settingsManager.nightlight_enabled ) {
source = 'nightlight';
}
else if ( e.settingsManager.location_enabled ) {
source = 'location';
}
else {
source = 'schedule';
}
let source;
if (e.settingsManager.nightlightEnabled)
source = 'nightlight';
else if (e.settingsManager.locationEnabled)
source = 'location';
else
source = 'schedule';
log_debug(`Time source is ${source}.`);
e.settingsManager.time_source = source;
return source;
}
logDebug(`Time source is ${source}.`);
e.settingsManager.timeSource = source;
return source;
}
}
};
Signals.addSignalMethods(Timer.prototype);