Extension: Load icons from resources
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2022 Romain Vigier <contact AT romainvigier.fr>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
-->
|
||||
<gresources>
|
||||
<gresource prefix="/org/gnome/shell/icons">
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="scalable/status/nightthemeswitcher-ondemand-off-symbolic.svg">icons/ondemand-off-symbolic.svg</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="scalable/status/nightthemeswitcher-ondemand-on-symbolic.svg">icons/ondemand-on-symbolic.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
Before Width: | Height: | Size: 658 B After Width: | Height: | Size: 658 B |
|
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
@@ -1,6 +1,14 @@
|
||||
# SPDX-FileCopyrightText: 2022 Romain Vigier <contact AT romainvigier.fr>
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
gnome.compile_resources(
|
||||
'extension',
|
||||
'extension.gresource.xml',
|
||||
gresource_bundle: true,
|
||||
install: true,
|
||||
install_dir: INSTALL_DIR / 'resources',
|
||||
)
|
||||
|
||||
gnome.compile_resources(
|
||||
'preferences',
|
||||
'preferences.gresource.xml',
|
||||
@@ -22,9 +30,3 @@ custom_target(
|
||||
install: true,
|
||||
install_dir: INSTALL_DIR / 'schemas'
|
||||
)
|
||||
|
||||
icons = [
|
||||
'icons/nightthemeswitcher-ondemand-off-symbolic.svg',
|
||||
'icons/nightthemeswitcher-ondemand-on-symbolic.svg'
|
||||
]
|
||||
install_data(icons, install_dir: INSTALL_DIR / 'icons' / 'hicolor' / 'scalable' / 'status')
|
||||
|
||||
+9
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Gio } = imports.gi;
|
||||
const { Gio, GLib } = imports.gi;
|
||||
const { extensionUtils } = imports.misc;
|
||||
|
||||
const Me = extensionUtils.getCurrentExtension();
|
||||
@@ -16,6 +16,7 @@ const { Timer } = Me.imports.modules.Timer;
|
||||
|
||||
|
||||
class NightThemeSwitcher {
|
||||
#resource = null;
|
||||
#timer = null;
|
||||
#switcherThemeGtk = null;
|
||||
#switcherThemeShell = null;
|
||||
@@ -32,6 +33,10 @@ class NightThemeSwitcher {
|
||||
|
||||
enable() {
|
||||
console.debug('Enabling extension...');
|
||||
|
||||
this.#resource = Gio.Resource.load(GLib.build_filenamev([Me.path, 'resources', 'extension.gresource']));
|
||||
Gio.resources_register(this.#resource);
|
||||
|
||||
this.#timer = new Timer();
|
||||
this.#switcherThemeGtk = new SwitcherThemeGtk({ timer: this.#timer });
|
||||
this.#switcherThemeIcon = new SwitcherThemeIcon({ timer: this.#timer });
|
||||
@@ -80,6 +85,9 @@ class NightThemeSwitcher {
|
||||
this.#timer = null;
|
||||
}
|
||||
|
||||
if (this.#resource)
|
||||
Gio.resources_unregister(this.#resource);
|
||||
|
||||
console.debug('Extension disabled.');
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,6 @@ var NtsPanelMenuButton = GObject.registerClass(
|
||||
|
||||
update() {
|
||||
this.icon.icon_name = _getIconNameForTime(this.#timer.time);
|
||||
this.icon.fallback_gicon = _getGiconForTime(this.#timer.time);
|
||||
this.accessible_name = this.#timer.time === Time.DAY ? _('Turn Night Mode On') : _('Turn Night Mode Off');
|
||||
}
|
||||
}
|
||||
@@ -233,7 +232,6 @@ var NtsPopupSubMenuMenuItem = GObject.registerClass(
|
||||
|
||||
update() {
|
||||
this.icon.icon_name = _getIconNameForTime(this.#timer.time);
|
||||
this.icon.fallback_gicon = _getGiconForTime(this.#timer.time);
|
||||
this.label.text = this.#timer.time === Time.DAY ? _('Night Mode Off') : _('Night Mode On');
|
||||
this._toggleItem.label.text = this.#timer.time === Time.DAY ? _('Turn On') : _('Turn Off');
|
||||
}
|
||||
@@ -243,7 +241,3 @@ var NtsPopupSubMenuMenuItem = GObject.registerClass(
|
||||
var _getIconNameForTime = time => {
|
||||
return time === Time.DAY ? 'nightthemeswitcher-ondemand-off-symbolic' : 'nightthemeswitcher-ondemand-on-symbolic';
|
||||
};
|
||||
|
||||
var _getGiconForTime = time => {
|
||||
return Gio.icon_new_for_string(GLib.build_filenamev([Me.path, 'icons', 'hicolor', 'scalable', 'status', `${this._getIconNameForTime(time)}.svg`]));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user