extensions-tool: Add quick settings template

Extending quick settings has become popular enough to justify a
template.

Add a small indicator+quick-item example that exercises the
previously added API.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2894>
This commit is contained in:
Florian Müllner 2023-08-14 17:51:35 +02:00
parent 93b89ce0c5
commit aaa9cb88b9
7 changed files with 74 additions and 0 deletions

View File

@ -107,5 +107,6 @@ subprojects/extensions-tool/src/command-uninstall.c
subprojects/extensions-tool/src/main.c
subprojects/extensions-tool/src/templates/00-plain.desktop.in
subprojects/extensions-tool/src/templates/indicator.desktop.in
subprojects/extensions-tool/src/templates/quick-settings.desktop.in
# Please do not remove this file from POTFILES.in. Run "git submodule init && git submodule update" to get it.
subprojects/gvc/gvc-mixer-control.c

View File

@ -2,3 +2,4 @@ data/org.gnome.Shell@wayland.service.in
data/org.gnome.Shell@x11.service.in
js/ui/init.js
subprojects/extensions-tool/src/templates/indicator/extension.js
subprojects/extensions-tool/src/templates/quick-settings/extension.js

View File

@ -7,5 +7,8 @@
<file>templates/indicator/stylesheet.css</file>
<file>templates/plain/extension.js</file>
<file>templates/plain/stylesheet.css</file>
<file>templates/quick-settings.desktop</file>
<file>templates/quick-settings/extension.js</file>
<file>templates/quick-settings/stylesheet.css</file>
</gresource>
</gresources>

View File

@ -1,6 +1,7 @@
template_metas = [
'00-plain.desktop',
'indicator.desktop',
'quick-settings.desktop',
]
template_deps = []
foreach template : template_metas

View File

@ -0,0 +1,5 @@
[Desktop Entry]
Type=Application
Name=Quick Settings Item
Comment=Add an item to quick settings
Path=quick-settings

View File

@ -0,0 +1,62 @@
/* extension.js
*
* 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 2 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://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import GObject from 'gi://GObject';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
import {QuickToggle, SystemIndicator} from 'resource:///org/gnome/shell/ui/quickSettings.js';
const ExampleToggle = GObject.registerClass(
class ExampleToggle extends QuickToggle {
constructor() {
super({
title: _('Smile'),
iconName: 'face-smile-symbolic',
toggleMode: true,
});
}
});
const ExampleIndicator = GObject.registerClass(
class ExampleIndicator extends SystemIndicator {
constructor() {
super();
this._indicator = this._addIndicator();
this._indicator.iconName = 'face-smile-symbolic';
const toggle = new ExampleToggle();
toggle.bind_property('checked',
this._indicator, 'visible',
GObject.BindingFlags.SYNC_CREATE);
this.quickSettingsItems.push(toggle);
}
});
export default class QuickSettingsExampleExtension extends Extension {
enable() {
this._indicator = new ExampleIndicator();
Main.panel.statusArea.quickSettings.addExternalIndicator(this._indicator);
}
disable() {
this._indicator.quickSettingsItems.forEach(item => item.destroy());
this._indicator.destroy();
}
}

View File

@ -0,0 +1 @@
/* Add your custom extension styling here */