Icon theme switching

This commit is contained in:
Romain
2020-05-29 15:20:47 +00:00
parent f836cb76c8
commit 849b38e208
10 changed files with 582 additions and 96 deletions
-8
View File
@@ -109,7 +109,6 @@ var CursorThemer = class {
}
_on_cursor_theme_changed(settings, new_theme) {
this._save_original_theme();
switch (e.timer.time) {
case 'day':
e.settingsManager.cursor_variant_day = new_theme;
@@ -125,10 +124,6 @@ var CursorThemer = class {
}
_are_variants_up_to_date() {
return ( e.settingsManager.cursor_theme === e.settingsManager.cursor_variant_day || e.settingsManager.cursor_theme === e.settingsManager.cursor_variant_night );
}
_set_variant(time) {
log_debug(`Setting the cursor ${time} variant...`);
switch (time) {
@@ -145,9 +140,6 @@ var CursorThemer = class {
}
_save_original_theme() {
if ( this._are_variants_up_to_date() ) {
return;
}
e.settingsManager.cursor_variant_original = e.settingsManager.cursor_theme;
}
+155
View File
@@ -0,0 +1,155 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { extensionUtils } = imports.misc;
const { main } = imports.ui;
const Me = extensionUtils.getCurrentExtension();
const e = Me.imports.extension;
const { log_debug } = Me.imports.utils;
/**
* The Icon Themer is responsible for changing the icon theme according to the
* time.
*/
var IconThemer = class {
enable() {
log_debug('Enabling Icon Themer...');
this._watch_status();
this._save_original_theme();
if ( e.settingsManager.icon_variants_enabled ) {
this._connect_settings();
this._connect_timer();
}
log_debug('Icon Themer enabled.');
}
disable() {
log_debug('Disabling Icon Themer...');
this._disconnect_timer();
this._disconnect_settings();
this._reset_original_theme();
this._unwatch_status();
log_debug('Icon Themer disabled.');
}
_watch_status() {
log_debug('Watching icon variants status...');
this._icon_variants_status_changed_connect = e.settingsManager.connect('icon-variants-status-changed', this._on_icon_variants_status_changed.bind(this));
}
_unwatch_status() {
if ( this._icon_variants_status_changed_connect ) {
e.settingsManager.disconnect(this._icon_variants_status_changed_connect);
this._icon_variants_status_changed_connect = null;
}
log_debug('Stopped watching icon variants status.');
}
_connect_settings() {
log_debug('Connecting Icon Themer to settings...');
this._icon_variant_changed_connect = e.settingsManager.connect('icon-variant-changed', this._on_icon_variant_changed.bind(this));
this._icon_theme_changed_connect = e.settingsManager.connect('icon-theme-changed', this._on_icon_theme_changed.bind(this));
}
_disconnect_settings() {
if ( this._icon_variant_changed_connect ) {
e.settingsManager.disconnect(this._icon_variant_changed_connect);
this._icon_variant_changed_connect = null;
}
if ( this._icon_theme_changed_connect ) {
e.settingsManager.disconnect(this._icon_theme_changed_connect);
this._icon_theme_changed_connect = null;
}
log_debug('Disconnected Icon Themer from settings.');
}
_connect_timer() {
log_debug('Connecting Icon Themer to Timer...');
this._time_changed_connect = e.timer.connect('time-changed', this._on_time_changed.bind(this));
}
_disconnect_timer() {
if ( this._time_changed_connect ) {
e.timer.disconnect(this._time_changed_connect);
this._time_changed_connect = null;
}
log_debug('Disconnected Icon Themer from Timer.');
}
_on_icon_variants_status_changed(settings, enabled) {
this.disable();
this.enable();
}
_on_icon_variant_changed(settings, changed_variant_time) {
if ( changed_variant_time === e.timer.time ) {
this._set_variant(changed_variant_time);
}
}
_on_icon_theme_changed(settings, new_theme) {
switch (e.timer.time) {
case 'day':
e.settingsManager.icon_variant_day = new_theme;
break;
case 'night':
e.settingsManager.icon_variant_night = new_theme;
}
this._set_variant(e.timer.time);
}
_on_time_changed(timer, new_time) {
this._set_variant(new_time);
}
_set_variant(time) {
log_debug(`Setting the icon ${time} variant...`);
switch (time) {
case 'day':
e.settingsManager.icon_theme = e.settingsManager.icon_variant_day;
break;
case 'night':
e.settingsManager.icon_theme = e.settingsManager.icon_variant_night;
break;
case 'original':
e.settingsManager.icon_theme = e.settingsManager.icon_variant_original;
break;
}
}
_save_original_theme() {
e.settingsManager.icon_variant_original = e.settingsManager.icon_theme;
}
_reset_original_theme() {
// We don't reset the theme when locking the session to prevent
// flicker on unlocking
if ( !main.screenShield.locked ) {
log_debug('Resetting to the user\'s original icon theme...');
this._set_variant('original');
}
}
}
+97 -3
View File
@@ -57,6 +57,10 @@ var SettingsManager = class {
this._shell_variant_day_changed_connect = this._extensionsSettings.connect('changed::shell-variant-day', this._on_shell_variant_day_changed.bind(this));
this._shell_variant_night_changed_connect = this._extensionsSettings.connect('changed::shell-variant-night', this._on_shell_variant_night_changed.bind(this));
this._shell_variant_original_changed_connect = this._extensionsSettings.connect('changed::shell-variant-original', this._on_shell_variant_original_changed.bind(this));
this._icon_variants_status_connect = this._extensionsSettings.connect('changed::icon-variants-enabled', this._on_icon_variants_status_changed.bind(this));
this._icon_variant_day_changed_connect = this._extensionsSettings.connect('changed::icon-variant-day', this._on_icon_variant_day_changed.bind(this));
this._icon_variant_night_changed_connect = this._extensionsSettings.connect('changed::icon-variant-night', this._on_icon_variant_night_changed.bind(this));
this._icon_variant_original_changed_connect = this._extensionsSettings.connect('changed::icon-variant-original', this._on_icon_variant_original_changed.bind(this));
this._cursor_variants_status_connect = this._extensionsSettings.connect('changed::cursor-variants-enabled', this._on_cursor_variants_status_changed.bind(this));
this._cursor_variant_day_changed_connect = this._extensionsSettings.connect('changed::cursor-variant-day', this._on_cursor_variant_day_changed.bind(this));
this._cursor_variant_night_changed_connect = this._extensionsSettings.connect('changed::cursor-variant-night', this._on_cursor_variant_night_changed.bind(this));
@@ -70,6 +74,7 @@ var SettingsManager = class {
this._nightlight_status_connect = this._colorSettings.connect('changed::night-light-enabled', this._on_nightlight_status_changed.bind(this));
this._location_status_connect = this._locationSettings.connect('changed::enabled', this._on_location_status_changed.bind(this));
this._gtk_theme_changed_connect = this._interfaceSettings.connect('changed::gtk-theme', this._on_gtk_theme_changed.bind(this));
this._icon_theme_changed_connect = this._interfaceSettings.connect('changed::icon-theme', this._on_icon_theme_changed.bind(this));
this._cursor_theme_changed_connect = this._interfaceSettings.connect('changed::cursor-theme', this._on_cursor_theme_changed.bind(this));
this._background_changed_connect = this._backgroundSettings.connect('changed::picture-uri', this._on_background_changed.bind(this));
if ( this._userthemesSettings ) {
@@ -86,6 +91,10 @@ var SettingsManager = class {
this._extensionsSettings.disconnect(this._shell_variant_day_changed_connect);
this._extensionsSettings.disconnect(this._shell_variant_night_changed_connect);
this._extensionsSettings.disconnect(this._shell_variant_original_changed_connect);
this._extensionsSettings.disconnect(this._icon_variants_status_connect);
this._extensionsSettings.disconnect(this._icon_variant_day_changed_connect);
this._extensionsSettings.disconnect(this._icon_variant_night_changed_connect);
this._extensionsSettings.disconnect(this._icon_variant_original_changed_connect);
this._extensionsSettings.disconnect(this._cursor_variants_status_connect);
this._extensionsSettings.disconnect(this._cursor_variant_day_changed_connect);
this._extensionsSettings.disconnect(this._cursor_variant_night_changed_connect);
@@ -99,6 +108,7 @@ var SettingsManager = class {
this._colorSettings.disconnect(this._nightlight_status_connect);
this._locationSettings.disconnect(this._location_status_connect);
this._interfaceSettings.disconnect(this._gtk_theme_changed_connect);
this._interfaceSettings.disconnect(this._icon_theme_changed_connect);
this._interfaceSettings.disconnect(this._cursor_theme_changed_connect);
this._backgroundSettings.disconnect(this._background_changed_connect);
if ( this._userthemesSettings ) {
@@ -229,6 +239,45 @@ var SettingsManager = class {
}
}
/* Icon variants settings */
get icon_variants_enabled() {
return this._extensionsSettings.get_boolean('icon-variants-enabled');
}
get icon_variant_day() {
return this._extensionsSettings.get_string('icon-variant-day') || this.icon_theme;
}
set icon_variant_day(value) {
if ( value !== this.icon_variant_day ) {
this._extensionsSettings.set_string('icon-variant-day', value);
log_debug(`The icon day variant has been set to '${value}'.`);
}
}
get icon_variant_night() {
return this._extensionsSettings.get_string('icon-variant-night') || this.icon_theme;
}
set icon_variant_night(value) {
if ( value !== this.icon_variant_night ) {
this._extensionsSettings.set_string('icon-variant-night', value);
log_debug(`The icon night variant has been set to '${value}'.`);
}
}
get icon_variant_original() {
return this._extensionsSettings.get_string('icon-variant-original');
}
set icon_variant_original(value) {
if ( value !== this.icon_variant_original ) {
this._extensionsSettings.set_string('icon-variant-original', value);
log_debug(`The icon original variant has been set to '${value}'.`);
}
}
/* Time source settings */
@@ -317,7 +366,7 @@ var SettingsManager = class {
set gtk_theme(value) {
if ( value !== this.gtk_theme ) {
this._interfaceSettings.set_string('gtk-theme', value);
log_debug(`GTK theme has been set to '${value}.'`);
log_debug(`GTK theme has been set to '${value}'.`);
}
}
@@ -341,6 +390,20 @@ var SettingsManager = class {
}
/* Icon theme settings */
get icon_theme() {
return this._interfaceSettings.get_string('icon-theme');
}
set icon_theme(value) {
if ( value !== this.icon_theme ) {
this._interfaceSettings.set_string('icon-theme', value);
log_debug(`Icon theme has been set to '${value}'.`);
}
}
/* Cursor theme settings */
get cursor_theme() {
@@ -350,7 +413,7 @@ var SettingsManager = class {
set cursor_theme(value) {
if ( value !== this.cursor_theme ) {
this._interfaceSettings.set_string('cursor-theme', value);
log_debug(`Cursor theme has been set to '${value}.'`);
log_debug(`Cursor theme has been set to '${value}'.`);
}
}
@@ -412,7 +475,7 @@ var SettingsManager = class {
_on_cursor_variants_status_changed(settings, changed_key) {
log_debug('Cursor variants have been ' + (this.cursor_variants_enabled ? 'ena' : 'disa') + 'bled.');
this.emit('cursor-variants-status-changed', this.curso_variants_enabled);
this.emit('cursor-variants-status-changed', this.cursor_variants_enabled);
}
_on_cursor_variant_day_changed(settings, changed_key) {
@@ -431,6 +494,29 @@ var SettingsManager = class {
}
/* Icon variants */
_on_icon_variants_status_changed(settings, changed_key) {
log_debug('Icon variants have been ' + (this.icon_variants_enabled ? 'ena' : 'disa') + 'bled.');
this.emit('icon-variants-status-changed', this.icon_variants_enabled);
}
_on_icon_variant_day_changed(settings, changed_key) {
log_debug(`Icon day variant has changed to '${this.icon_variant_day}'.`);
this.emit('icon-variant-changed', 'day');
}
_on_icon_variant_night_changed(settings, changed_key) {
log_debug(`Icon night variant has changed to '${this.icon_variant_night}'.`);
this.emit('icon-variant-changed', 'night');
}
_on_icon_variant_original_changed(settings, changed_key) {
log_debug(`Icon original variant has changed to '${this.icon_variant_original}'.`);
this.emit('icon-variant-changed', 'original');
}
/* Time source */
_on_time_source_changed(settings, changed_key) {
@@ -494,6 +580,14 @@ var SettingsManager = class {
}
/* Icon theme */
_on_icon_theme_changed(settings, changed_key) {
log_debug(`Cursor theme has changed to '${this.icon_theme}'.`);
this.emit('icon-theme-changed', this.icon_theme);
}
/* Cursor theme */
_on_cursor_theme_changed(settings, changed_key) {