Use custom icons for on-demand status
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m8 0c-4.4127 0-8 3.5873-8 8-2.3442e-7 4.4127 3.5873 8 8 8 3.103-3.44e-4 5.9283-1.7973 7.2441-4.6074 0.18773-0.39849-0.22592-0.81344-0.625-0.62695-0.7467 0.34767-1.5611 0.52936-2.3848 0.5293-3.1244 0-5.6465-2.5241-5.6465-5.6484 3.18e-4 -1.9086 0.96387-3.6859 2.5625-4.7285 0.3679-0.24025 0.23509-0.8089-0.20117-0.86133-0.315-0.037685-0.63197-0.056598-0.94922-0.056641z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#999" image-rendering="auto" opacity=".35" shape-rendering="auto" solid-color="#000000" stop-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;font-variation-settings:normal;inline-size:0;isolation:auto;mix-blend-mode:normal;shape-margin:0;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m8 0c-4.4127 0-8 3.5873-8 8-2.3442e-7 4.4127 3.5873 8 8 8 3.103-3.44e-4 5.9283-1.7973 7.2441-4.6074 0.18773-0.39849-0.22592-0.81344-0.625-0.62695-0.7467 0.34767-1.5611 0.52936-2.3848 0.5293-3.1244 0-5.6465-2.5241-5.6465-5.6484 3.18e-4 -1.9086 0.96387-3.6859 2.5625-4.7285 0.3679-0.24025 0.23509-0.8089-0.20117-0.86133-0.315-0.037685-0.63197-0.056598-0.94922-0.056641z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#999" image-rendering="auto" shape-rendering="auto" solid-color="#000000" stop-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;font-variation-settings:normal;inline-size:0;isolation:auto;mix-blend-mode:normal;shape-margin:0;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -16,11 +16,14 @@ 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 { Shell, St } = imports.gi;
|
||||
const { Gio, GLib, Shell, St } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
const Signals = imports.signals;
|
||||
|
||||
const { main, panelMenu: PanelMenu, popupMenu: PopupMenu } = imports.ui;
|
||||
const { main } = imports.ui;
|
||||
|
||||
const { Button: PanelMenuButton } = imports.ui.panelMenu;
|
||||
const { PopupImageMenuItem } = imports.ui.popupMenu;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
|
||||
@@ -144,17 +147,16 @@ var TimerOndemand = class {
|
||||
|
||||
_addButtonToPanel() {
|
||||
logDebug('Adding On-demand Timer button to the panel...');
|
||||
const getIconNameForCurrentTime = () => e.timer.time === 'day' ? 'weather-clear-symbolic' : 'weather-clear-night-symbolic';
|
||||
const icon = new St.Icon({
|
||||
icon_name: getIconNameForCurrentTime(),
|
||||
gicon: this._getIconForTime(e.timer.time),
|
||||
style_class: 'system-status-icon',
|
||||
});
|
||||
this._button = new PanelMenu.Button(0.0);
|
||||
this._button = new PanelMenuButton(0.0);
|
||||
const buttonActor = getActor(this._button);
|
||||
buttonActor.add_actor(icon);
|
||||
buttonActor.connect('button-press-event', () => {
|
||||
this._toggleTime();
|
||||
icon.icon_name = getIconNameForCurrentTime();
|
||||
icon.gicon = this._getIconForTime(e.timer.time);
|
||||
});
|
||||
main.panel.addToStatusArea('NightThemeSwitcherButton', this._button);
|
||||
logDebug('Added On-demand Timer button to the panel.');
|
||||
@@ -164,18 +166,25 @@ var TimerOndemand = class {
|
||||
logDebug('Adding On-demand Timer button to the menu...');
|
||||
const aggregateMenu = main.panel.statusArea.aggregateMenu;
|
||||
const position = findShellAggregateMenuItemPosition(aggregateMenu._system.menu) - 1;
|
||||
const getLabelForCurrentTime = () => e.timer.time === 'day' ? _('Switch to night theme') : _('Switch to day theme');
|
||||
const getIconNameForCurrentTime = () => e.timer.time === 'day' ? 'weather-clear-night-symbolic' : 'weather-clear-symbolic';
|
||||
this._button = new PopupMenu.PopupImageMenuItem(getLabelForCurrentTime(), getIconNameForCurrentTime());
|
||||
this._button = new PopupImageMenuItem(this._getLabelForTime(e.timer.time), this._getIconForTime(e.timer.time));
|
||||
this._button.connect('activate', () => {
|
||||
this._toggleTime();
|
||||
this._button.label.text = getLabelForCurrentTime();
|
||||
this._button.setIcon(getIconNameForCurrentTime());
|
||||
this._button.label.text = this._getLabelForTime(e.timer.time);
|
||||
this._button.setIcon(this._getIconForTime(e.timer.time));
|
||||
});
|
||||
aggregateMenu.menu.addMenuItem(this._button, position);
|
||||
logDebug('Added On-demand Timer button to the menu.');
|
||||
}
|
||||
|
||||
_getIconForTime(time) {
|
||||
const name = time === 'day' ? 'nightthemeswitcher-ondemand-off-symbolic' : 'nightthemeswitcher-ondemand-on-symbolic';
|
||||
return Gio.icon_new_for_string(GLib.build_filenamev([Me.path, 'icons', 'hicolor', 'scalable', 'status', `${name}.svg`]));
|
||||
}
|
||||
|
||||
_getLabelForTime(time) {
|
||||
return time === 'day' ? _('Switch to night theme') : _('Switch to day theme');
|
||||
}
|
||||
|
||||
_toggleTime() {
|
||||
e.settings.time.ondemandTime = e.timer.time === 'day' ? 'night' : 'day';
|
||||
this.emit('time-changed', this.time);
|
||||
|
||||
Reference in New Issue
Block a user