2020-03-30 10:45:26 +02:00
|
|
|
/* 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 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://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Based on https://stackoverflow.com/questions/33001192/how-to-send-a-string-to-a-gnome-shell-extension */
|
2020-11-18 16:17:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Some useful documentation :
|
|
|
|
|
|
|
|
https://github.com/bananenfisch/RecentItems/blob/master/extension.js
|
|
|
|
https://github.com/julio641742/gnome-shell-extension-reference/blob/master/tutorials/POPUPMENU-EXTENSION.md
|
|
|
|
https://gjs-docs.gnome.org/st10~1.0_api/st.widget
|
2022-10-27 17:54:37 +02:00
|
|
|
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panelMenu.js
|
|
|
|
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/popupMenu.js
|
|
|
|
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panel.js
|
2020-11-18 16:17:58 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-30 10:45:26 +02:00
|
|
|
const St = imports.gi.St;
|
|
|
|
const Gio = imports.gi.Gio;
|
2020-05-04 10:08:39 +02:00
|
|
|
const GLib = imports.gi.GLib
|
2020-03-30 10:45:26 +02:00
|
|
|
const Main = imports.ui.main;
|
2020-05-04 10:08:39 +02:00
|
|
|
const Mainloop = imports.mainloop;
|
2020-11-03 16:59:27 +01:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2020-11-02 17:03:34 +01:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Pixbuf = imports.gi.GdkPixbuf;
|
|
|
|
const Cogl = imports.gi.Cogl;
|
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
|
|
|
|
function hashGet(hash, key, defaultValue) {
|
2020-11-03 16:59:27 +01:00
|
|
|
if (hash.hasOwnProperty(key))
|
2020-11-19 11:20:03 +01:00
|
|
|
return hash[key];
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return defaultValue;
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-05 15:36:14 +01:00
|
|
|
function log(message) {
|
|
|
|
global.log('[GenericMontior]', message);
|
|
|
|
}
|
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
class SignalMgt {
|
|
|
|
|
2022-10-27 17:54:37 +02:00
|
|
|
constructor(item, name, group, dbus, buttonMenu) {
|
2021-01-18 15:52:58 +01:00
|
|
|
this.name = name;
|
|
|
|
this.group = group;
|
|
|
|
this.fullname = this.name + '@' + this.group;
|
|
|
|
this.dbus = dbus;
|
2022-10-27 17:54:37 +02:00
|
|
|
this.buttonMenu = buttonMenu;
|
2022-01-06 09:51:13 +01:00
|
|
|
this.signals = new WeakMap();
|
|
|
|
this.widgets = new Array();
|
|
|
|
this.timeouts = new Array();
|
2021-01-18 15:52:58 +01:00
|
|
|
|
2022-10-27 17:54:37 +02:00
|
|
|
this.menuOpen = false;
|
2021-01-18 15:52:58 +01:00
|
|
|
this.nbClicks = 0;
|
|
|
|
this.button = -1;
|
|
|
|
|
|
|
|
this.onClick = hashGet(item, 'on-click', '');
|
|
|
|
this.onDblClick = hashGet(item, 'on-dblclick', '');
|
|
|
|
this.onRightClick = hashGet(item, 'on-rightclick', '');
|
|
|
|
this.onRightDblClick = hashGet(item, 'on-rightdblclick', '');
|
|
|
|
this.onEnter = hashGet(item, 'on-enter', '');
|
|
|
|
this.onLeave = hashGet(item, 'on-leave', '');
|
|
|
|
this.onScroll = hashGet(item, 'on-scroll', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
destructor() {
|
2021-09-30 16:32:26 +02:00
|
|
|
for(let widgetIdx in this.widgets)
|
|
|
|
this.disconnectWidgetSignals(this.widgets[widgetIdx]);
|
2022-01-06 09:51:13 +01:00
|
|
|
for(let timeoutIdx in this.timeouts)
|
|
|
|
GLib.Source.remove(this.timeouts[timeoutIdx]);
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateSignals(item) {
|
|
|
|
this.onClick = hashGet(item, 'on-click', this.onClick);
|
|
|
|
this.onDblClick = hashGet(item, 'on-dblclick', this.onDblClick);
|
|
|
|
this.onRightClick = hashGet(item, 'on-rightclick', this.onRightClick);
|
|
|
|
this.onRightDblClick = hashGet(item, 'on-rightdblclick', this.onRightDblClick);
|
|
|
|
this.onEnter = hashGet(item, 'on-enter', this.onEnter);
|
|
|
|
this.onLeave = hashGet(item, 'on-leave', this.onLeave);
|
|
|
|
this.onScroll = hashGet(item, 'on-scroll', this.onScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
connectWidgetSignals(widget) {
|
2021-09-30 16:32:26 +02:00
|
|
|
this.widgets.push(widget);
|
|
|
|
let array = new Array();
|
|
|
|
this.signals.set(widget, array);
|
2021-01-18 15:52:58 +01:00
|
|
|
let id;
|
|
|
|
id = widget.connect('enter-event', this._onEnter.bind(this));
|
2021-09-30 16:32:26 +02:00
|
|
|
array.push(id);
|
2021-01-18 15:52:58 +01:00
|
|
|
id = widget.connect('leave-event', this._onLeave.bind(this));
|
2021-09-30 16:32:26 +02:00
|
|
|
array.push(id);
|
2021-01-18 15:52:58 +01:00
|
|
|
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
2021-09-30 16:32:26 +02:00
|
|
|
array.push(id);
|
2021-01-18 15:52:58 +01:00
|
|
|
widget.set_reactive(true);
|
2021-10-01 09:02:34 +02:00
|
|
|
id = widget.connect('button-release-event', this._clicked.bind(this));
|
2021-09-30 16:32:26 +02:00
|
|
|
array.push(id);
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnectWidgetSignals(widget) {
|
2021-09-30 16:32:26 +02:00
|
|
|
let array = this.signals.get(widget);
|
|
|
|
for(let idx in array)
|
|
|
|
widget.disconnect(array[idx]);
|
|
|
|
this.signals.set(widget, null);
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
|
|
|
|
2022-10-27 17:54:37 +02:00
|
|
|
toggleMenu() {
|
|
|
|
if (this.menuOpen)
|
|
|
|
{
|
|
|
|
this.buttonMenu.menu.close();
|
|
|
|
this.menuOpen = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.buttonMenu.menu.open(true);
|
|
|
|
this.menuOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
_manageEventAction(action, signalName) {
|
|
|
|
if (action === 'open-popup')
|
2022-10-27 17:54:37 +02:00
|
|
|
{
|
|
|
|
this.buttonMenu.menu.open(true);
|
|
|
|
this.menuOpen = true;
|
|
|
|
}
|
2021-01-18 15:52:58 +01:00
|
|
|
else if (action === 'close-popup')
|
2022-10-27 17:54:37 +02:00
|
|
|
{
|
|
|
|
this.buttonMenu.menu.close();
|
|
|
|
this.menuOpen = false;
|
|
|
|
}
|
2021-01-18 15:52:58 +01:00
|
|
|
else if (action === 'toggle-popup')
|
2022-10-27 17:54:37 +02:00
|
|
|
{
|
|
|
|
this.toggleMenu();
|
|
|
|
}
|
|
|
|
else if (action === 'delete')
|
2021-01-18 15:52:58 +01:00
|
|
|
this.dbus.deleteItem(this, this.group);
|
|
|
|
else if (action === 'signal')
|
|
|
|
this.dbus.emitSignal(signalName, this.fullname);
|
|
|
|
|
2022-10-27 17:54:37 +02:00
|
|
|
return Clutter.EVENT_STOP;
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
2022-10-27 17:54:37 +02:00
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
_doClickCallback() {
|
|
|
|
let right = '';
|
|
|
|
let nbClicks = '';
|
2021-01-29 09:15:40 +01:00
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
if (this.button == 3)
|
|
|
|
right = 'Right';
|
|
|
|
if (this.nbClicks > 1)
|
|
|
|
nbClicks = 'Dbl';
|
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const signalName = 'on' + right + nbClicks + 'Click';
|
2021-01-18 15:52:58 +01:00
|
|
|
|
|
|
|
let action = 'signal';
|
|
|
|
switch(signalName) {
|
|
|
|
case 'onClick': action = this.onClick; break;
|
|
|
|
case 'onDblClick': action = this.onDblClick; break;
|
|
|
|
case 'onRightClick': action = this.onRightClick; break;
|
|
|
|
case 'onRightDblClick': action = this.onRightDblClick; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._manageEventAction(action, signalName);
|
|
|
|
|
|
|
|
this.nbClicks = 0;
|
|
|
|
this.button = -1;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_clicked(actor, event) {
|
|
|
|
if (event.get_button() == this.button) {
|
|
|
|
this.nbClicks++;
|
|
|
|
} else {
|
|
|
|
this.button = event.get_button();
|
|
|
|
this.nbClicks = 1;
|
|
|
|
|
2022-01-06 09:51:13 +01:00
|
|
|
let sourceId = Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
|
|
|
this._doClickCallback.bind(this));
|
|
|
|
this.timeouts.push(sourceId);
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onEnter(/*actor, event*/) {
|
|
|
|
return this._manageEventAction(this.onEnter, 'onEnter');
|
|
|
|
}
|
|
|
|
|
|
|
|
_onLeave(/*actor, event*/) {
|
|
|
|
return this._manageEventAction(this.onLeave, 'onLeave');
|
|
|
|
}
|
|
|
|
|
|
|
|
_onScroll(actor, event) {
|
2021-01-29 09:15:40 +01:00
|
|
|
let signalName = '';
|
|
|
|
const direction = event.get_scroll_direction ();
|
2021-01-18 15:52:58 +01:00
|
|
|
if (direction == Clutter.ScrollDirection.UP)
|
|
|
|
signalName = 'onScrollUp';
|
|
|
|
else if (direction == Clutter.ScrollDirection.DOWN)
|
|
|
|
signalName = 'onScrollDown';
|
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
return this._manageEventAction(this.onScroll, signalName);
|
2021-01-18 15:52:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
var MyPopupMenuItem = GObject.registerClass({
|
2021-01-29 09:15:40 +01:00
|
|
|
GTypeName: 'MyPopupMenuItem'
|
2020-11-02 17:03:34 +01:00
|
|
|
},
|
|
|
|
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
2020-11-03 16:59:27 +01:00
|
|
|
_init(widgets, params) {
|
2020-11-19 11:20:03 +01:00
|
|
|
super._init(params);
|
2020-11-02 17:03:34 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
|
|
|
this.box.set_vertical(true);
|
2020-11-02 17:03:34 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
for (let widgetIndex in widgets)
|
|
|
|
this.box.add(widgets[widgetIndex]);
|
|
|
|
|
|
|
|
this.add_child(this.box);
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
2020-11-02 17:03:34 +01:00
|
|
|
});
|
|
|
|
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
var MonitorWidget = GObject.registerClass({
|
2021-01-29 09:15:40 +01:00
|
|
|
GTypeName: 'MonitorWidget'
|
2020-11-02 17:03:34 +01:00
|
|
|
},
|
|
|
|
class MonitorWidget extends PanelMenu.Button {
|
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
_init(item, group, dbus, position) {
|
|
|
|
super._init(0.0);
|
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
this.name = item['name'];
|
2020-04-01 09:36:51 +02:00
|
|
|
this.group = group;
|
2020-11-19 11:20:03 +01:00
|
|
|
this.fullname = this.name + '@' + this.group;
|
|
|
|
this.dbus = dbus;
|
2022-10-27 17:54:37 +02:00
|
|
|
this.menuItem = null;
|
|
|
|
this.signalManager = new SignalMgt(item, this.name, group, dbus, this);
|
2021-09-30 16:32:26 +02:00
|
|
|
this.popup_signals = null;
|
|
|
|
this.popup_widgets = null;
|
2021-01-29 09:15:40 +01:00
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
if (item.hasOwnProperty('icon'))
|
2020-11-19 11:20:03 +01:00
|
|
|
{
|
2021-01-29 09:15:40 +01:00
|
|
|
if (typeof(item['icon']) === 'string')
|
2020-11-19 11:20:03 +01:00
|
|
|
this.icon = this._createIconOld(item);
|
|
|
|
else
|
|
|
|
this.icon = this._createIcon(item['icon']);
|
|
|
|
if (this.icon !== null) {
|
2021-09-30 16:32:26 +02:00
|
|
|
this.signalManager.connectWidgetSignals(this.icon);
|
2020-11-19 11:20:03 +01:00
|
|
|
this.add_child(this.icon);
|
|
|
|
}
|
2021-01-29 09:15:40 +01:00
|
|
|
} else
|
2020-11-19 11:20:03 +01:00
|
|
|
this.icon = null;
|
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
if (item.hasOwnProperty('text'))
|
2020-11-19 11:20:03 +01:00
|
|
|
{
|
2021-01-29 09:15:40 +01:00
|
|
|
if (typeof(item['text']) === 'string')
|
2020-11-19 11:20:03 +01:00
|
|
|
this.widget = this._createTextOld(item);
|
|
|
|
else
|
|
|
|
this.widget = this._createText(item['text']);
|
|
|
|
|
|
|
|
if (this.widget !== null) {
|
2021-09-30 16:32:26 +02:00
|
|
|
this.signalManager.connectWidgetSignals(this.widget);
|
2020-11-19 11:20:03 +01:00
|
|
|
this.add_child(this.widget);
|
|
|
|
}
|
2021-01-29 09:15:40 +01:00
|
|
|
} else
|
2020-11-19 11:20:03 +01:00
|
|
|
this.widget = null;
|
|
|
|
|
2020-11-02 17:03:34 +01:00
|
|
|
if (item.hasOwnProperty('popup'))
|
|
|
|
this._createPopup(item['popup']);
|
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const box = hashGet(item, 'box', 'center');
|
2020-05-05 09:56:59 +02:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
if (box === 'right' && position == -1)
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
|
|
|
|
|
|
|
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
2020-11-04 14:52:43 +01:00
|
|
|
}
|
2020-11-02 17:03:34 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
update(item) {
|
|
|
|
const prevWidget = this.widget;
|
|
|
|
const prevIcon = this.icon;
|
|
|
|
|
|
|
|
if (item.hasOwnProperty('text'))
|
|
|
|
{
|
|
|
|
let text = '';
|
|
|
|
let style = '';
|
|
|
|
if (typeof(item['text']) === 'string') {
|
|
|
|
text = hashGet(item, 'text', '');
|
|
|
|
style = hashGet(item, 'style', '');
|
|
|
|
} else {
|
|
|
|
const textValues = item['text'];
|
|
|
|
text = hashGet(textValues, 'text', '');
|
|
|
|
style = hashGet(textValues, 'style', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text !== '') {
|
|
|
|
if (!this.widget) {
|
|
|
|
if (typeof(item['text']) === 'string')
|
|
|
|
this.widget = this._createTextOld(item);
|
|
|
|
else
|
|
|
|
this.widget = this._createText(item['text']);
|
|
|
|
this.insert_child_above(this.widget, this.icon);
|
|
|
|
} else {
|
|
|
|
this.widget.label = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style !== '' && this.widget) {
|
|
|
|
this.widget.set_style(style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.hasOwnProperty('icon'))
|
|
|
|
{
|
|
|
|
let icon = '';
|
|
|
|
let style = '';
|
|
|
|
if (typeof(item['icon']) === 'string') {
|
|
|
|
icon = hashGet(item, 'icon', '');
|
|
|
|
style = hashGet(item, 'iconStyle', '');
|
|
|
|
} else {
|
|
|
|
const iconValues = item['icon'];
|
|
|
|
icon = hashGet(iconValues, 'path', '');
|
|
|
|
style = hashGet(iconValues, 'style', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon !== '') {
|
|
|
|
if (typeof(item['icon']) === 'string')
|
|
|
|
this.icon = this._createIconOld(item);
|
|
|
|
else
|
|
|
|
this.icon = this._createIcon(item['icon']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prevIcon) {
|
2021-09-30 16:32:26 +02:00
|
|
|
this.signalManager.disconnectWidgetSignals(prevIcon);
|
2021-01-29 09:15:40 +01:00
|
|
|
this.insert_child_above(this.icon, prevIcon);
|
|
|
|
this.remove_child(prevIcon);
|
|
|
|
//delete prevIcon;
|
|
|
|
} else
|
|
|
|
this.insert_child_before(this.icon, prevWidget);
|
|
|
|
|
|
|
|
if (style !== '' && this.icon) {
|
|
|
|
this.icon.set_style(style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.hasOwnProperty('popup'))
|
|
|
|
{
|
|
|
|
const menuOpen = this.menu.isOpen;
|
|
|
|
if (this.menuItem) {
|
|
|
|
if (menuOpen)
|
|
|
|
this.menu.close();
|
2021-09-30 16:32:26 +02:00
|
|
|
for(let widgetIdx in this.popup_widgets)
|
|
|
|
this.signalManager.disconnectWidgetSignals(this.popup_widgets[widgetIdx]);
|
2021-01-29 09:15:40 +01:00
|
|
|
this.menu.removeAll();
|
|
|
|
//delete this.menuItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
const popup = this._createPopup(item['popup']);
|
|
|
|
if (popup !== null && menuOpen)
|
|
|
|
this.menu.open(true);
|
|
|
|
}
|
|
|
|
|
2021-09-30 16:32:26 +02:00
|
|
|
this.signalManager.updateSignals(item);
|
2021-01-29 09:15:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
openPopup() {
|
|
|
|
this.menu.open(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
closePopup() {
|
|
|
|
this.menu.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePopup() {
|
|
|
|
this.menu.toggle();
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.menu.close();
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
_onStyleChanged() {
|
|
|
|
// Force these values to avoid big spaces between each widgets
|
2020-11-04 14:52:43 +01:00
|
|
|
this._minHPadding = 1;
|
|
|
|
this._natHPadding = 1;
|
2020-11-02 17:03:34 +01:00
|
|
|
}
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2020-11-03 16:59:27 +01:00
|
|
|
_createPopup(item) {
|
|
|
|
if (!item.hasOwnProperty('items')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
let widgets = [];
|
2021-09-30 16:32:26 +02:00
|
|
|
this.popup_signals = new WeakMap();
|
|
|
|
this.popup_widgets = new Array();
|
2020-11-19 11:20:03 +01:00
|
|
|
for (let itemIndex in item['items']) {
|
|
|
|
let widget = null;
|
|
|
|
let widgetDict = item['items'][itemIndex];
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
let nestedItem = null;
|
2021-01-18 15:52:58 +01:00
|
|
|
if (widgetDict.hasOwnProperty('text')) {
|
2021-01-29 09:15:40 +01:00
|
|
|
nestedItem = widgetDict['text'];
|
2021-01-31 20:18:11 +01:00
|
|
|
widget = this._createLabel(nestedItem);
|
2021-01-29 09:15:40 +01:00
|
|
|
} else if (widgetDict.hasOwnProperty('picture')) {
|
|
|
|
nestedItem = widgetDict['picture'];
|
2021-01-18 15:52:58 +01:00
|
|
|
widget = this._createPicture(nestedItem);
|
2021-01-29 09:15:40 +01:00
|
|
|
} else {
|
|
|
|
log('No known widget defined in popup');
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
if (nestedItem === null) {
|
2021-01-29 09:15:40 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:52:58 +01:00
|
|
|
widgets.push(widget);
|
2021-01-29 09:15:40 +01:00
|
|
|
const name = hashGet(nestedItem, 'name', '');
|
|
|
|
this.popup_signals[widget] = new SignalMgt(nestedItem, name,
|
|
|
|
this.fullname, this.dbus,
|
2022-10-27 17:54:37 +02:00
|
|
|
this);
|
2021-01-29 09:15:40 +01:00
|
|
|
this.popup_signals[widget].connectWidgetSignals(widget);
|
2021-09-30 16:32:26 +02:00
|
|
|
this.popup_widgets.push(widget);
|
2020-11-19 11:20:03 +01:00
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
if (widgets.length > 0) {
|
|
|
|
this.menuItem = new MyPopupMenuItem(widgets, {});
|
2020-11-03 16:59:27 +01:00
|
|
|
this.menu.addMenuItem(this.menuItem);
|
2020-11-19 11:20:03 +01:00
|
|
|
this.menu.setSensitive(false);
|
|
|
|
return this.menuItem;
|
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_createTextOld(item) {
|
2020-11-19 11:20:03 +01:00
|
|
|
var itemValues = {};
|
|
|
|
itemValues = { 'text':item['text'] };
|
2020-11-03 16:59:27 +01:00
|
|
|
if (item.hasOwnProperty('style'))
|
2020-11-19 11:20:03 +01:00
|
|
|
itemValues['style'] = item['style'];
|
|
|
|
return this._createText(itemValues);
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 20:18:11 +01:00
|
|
|
__createText(item, isLabel) {
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!item.hasOwnProperty('text')) {
|
2021-01-29 09:15:40 +01:00
|
|
|
log('Text must have a \'text\' value');
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const style = hashGet(item, 'style', '');
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
this.textProperties = item;
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
if (item['text'] === '') {
|
2020-11-02 17:03:34 +01:00
|
|
|
return null;
|
2020-04-01 09:36:51 +02:00
|
|
|
} else {
|
2021-01-31 20:18:11 +01:00
|
|
|
let widget = null;
|
|
|
|
if (isLabel)
|
|
|
|
widget = new St.Label({ text: item['text'] });
|
|
|
|
else
|
|
|
|
widget = new St.Button({ label: item['text'] });
|
2020-11-03 16:59:27 +01:00
|
|
|
widget.set_style(style);
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return widget;
|
|
|
|
}
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
|
2021-01-31 20:18:11 +01:00
|
|
|
_createText(item) {
|
|
|
|
return this.__createText(item, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
_createLabel(item) {
|
|
|
|
return this.__createText(item, true);
|
|
|
|
}
|
|
|
|
|
2020-11-03 16:59:27 +01:00
|
|
|
_createIconOld(item) {
|
2020-11-19 11:20:03 +01:00
|
|
|
var itemValues = {};
|
|
|
|
itemValues = { 'path':item['icon'] };
|
2020-11-03 16:59:27 +01:00
|
|
|
if (item.hasOwnProperty('iconStyle'))
|
2020-11-19 11:20:03 +01:00
|
|
|
itemValues['style'] = item['iconStyle'];
|
|
|
|
return this._createIcon(itemValues);
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_createIcon(item) {
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!item.hasOwnProperty('path')) {
|
2021-01-29 09:15:40 +01:00
|
|
|
log('Icon must have a \'path\' value');
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const style = hashGet(item, 'style', '');
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
this.iconProperties = item;
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
if (item['path'] === '') {
|
2020-11-02 17:03:34 +01:00
|
|
|
return null;
|
2020-04-01 09:36:51 +02:00
|
|
|
} else {
|
2020-11-03 16:59:27 +01:00
|
|
|
let gicon = Gio.icon_new_for_string(item['path']);
|
2020-11-02 17:03:34 +01:00
|
|
|
gicon = new St.Icon({ gicon });
|
2020-11-03 16:59:27 +01:00
|
|
|
gicon.set_style(style);
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return gicon;
|
2020-05-05 09:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 16:59:27 +01:00
|
|
|
_createPicture(item) {
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!item.hasOwnProperty('path')) {
|
2021-01-29 09:15:40 +01:00
|
|
|
log('Picture must have a \'path\' value');
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
|
|
|
}
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
let width = hashGet(item, 'width', -1);
|
|
|
|
let height = hashGet(item, 'height', -1);
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
if (typeof(width) === 'string')
|
2020-11-19 11:20:03 +01:00
|
|
|
width = parseInt(width, 10);
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
if (typeof(height) === 'string')
|
2020-11-19 11:20:03 +01:00
|
|
|
height = parseInt(height, 10);
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const img = new Clutter.Image();
|
|
|
|
const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
2020-11-19 11:20:03 +01:00
|
|
|
img.set_data(initialPixbuf.get_pixels(),
|
|
|
|
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
|
|
|
: Cogl.PixelFormat.RGB_888,
|
|
|
|
initialPixbuf.get_width(),
|
|
|
|
initialPixbuf.get_height(),
|
|
|
|
initialPixbuf.get_rowstride());
|
2021-01-29 09:15:40 +01:00
|
|
|
const picture = new Clutter.Actor();
|
2020-11-19 11:20:03 +01:00
|
|
|
picture.set_content(img);
|
|
|
|
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
|
|
|
|
(height != -1)?height:initialPixbuf.get_height());
|
2020-11-03 16:59:27 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
// Pack it in a box to avoid picture resize
|
2021-01-29 09:15:40 +01:00
|
|
|
const box = new St.BoxLayout({});
|
2020-11-19 11:20:03 +01:00
|
|
|
box.add_child(picture);
|
2020-11-18 16:17:13 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return box;
|
2020-11-03 16:59:27 +01:00
|
|
|
}
|
2020-11-02 17:03:34 +01:00
|
|
|
});
|
2020-03-30 10:45:26 +02:00
|
|
|
|
|
|
|
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
|
|
|
// loads a xml file into an in-memory string
|
|
|
|
function loadInterfaceXml(filename) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const extension = imports.misc.extensionUtils.getCurrentExtension();
|
2020-03-30 10:45:26 +02:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const interfacesDir = extension.dir.get_child('.');
|
2020-03-30 10:45:26 +02:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const file = interfacesDir.get_child(filename);
|
2020-03-30 10:45:26 +02:00
|
|
|
|
2020-04-01 09:36:51 +02:00
|
|
|
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
2020-03-30 10:45:26 +02:00
|
|
|
|
|
|
|
if (result) {
|
2020-04-01 09:36:51 +02:00
|
|
|
// HACK: The "" + trick is important as hell because file_get_contents returns
|
2020-03-30 10:45:26 +02:00
|
|
|
// an object (WTF?) but Gio.makeProxyWrapper requires `typeof() == "string"`
|
|
|
|
// Otherwise, it will try to check `instanceof XML` and fail miserably because there
|
|
|
|
// is no `XML` on very recent SpiderMonkey releases (or, if SpiderMonkey is old enough,
|
|
|
|
// will spit out a TypeError soon).
|
|
|
|
if (contents instanceof Uint8Array)
|
2020-04-01 09:36:51 +02:00
|
|
|
contents = imports.byteArray.toString(contents);
|
2021-01-29 09:15:40 +01:00
|
|
|
const res = `<node>${contents}</node>`;
|
2020-04-01 09:36:51 +02:00
|
|
|
return res;
|
2020-03-30 10:45:26 +02:00
|
|
|
} else {
|
2020-04-01 09:36:51 +02:00
|
|
|
throw new Error(`Generic monitor: Could not load file: ${filename}`);
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 09:36:51 +02:00
|
|
|
class GenericMonitorDBUS {
|
|
|
|
constructor() {
|
|
|
|
this.monitor_groups = {};
|
2020-05-04 10:08:39 +02:00
|
|
|
this.actor_clicked = {};
|
2020-11-03 16:59:27 +01:00
|
|
|
this.ClutterSettings = Clutter.Settings.get_default();
|
2020-03-30 10:45:26 +02:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
2020-05-07 08:39:13 +02:00
|
|
|
this._dbusImpl.emit_signal('onActivate', null);
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
2020-03-30 10:45:26 +02:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
emitSignal(name, value) {
|
2020-11-05 15:36:14 +01:00
|
|
|
this._dbusImpl.emit_signal(name, GLib.Variant.new('(s)',[value]));
|
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
|
2020-11-05 15:36:14 +01:00
|
|
|
_checkParameters(parameters) {
|
|
|
|
if (!parameters.hasOwnProperty('group')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log('No group defined');
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
if (!parameters.hasOwnProperty('items')) {
|
|
|
|
log('No items defined');
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
|
|
|
|
for (let itemIndex in parameters['items']) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const item = parameters['items'][itemIndex];
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!item.hasOwnProperty('name')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log('No name defined for item');
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
2020-11-05 15:36:14 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return true;
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_getItemFromGroup(group, name) {
|
|
|
|
for (let groupItemIndex in group) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const groupItem = group[groupItemIndex];
|
2020-04-01 09:36:51 +02:00
|
|
|
if (groupItem.name === name)
|
|
|
|
return groupItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 10:42:11 +01:00
|
|
|
_getItemFromFullName(fullname) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const splitName = fullname.split('@');
|
2020-11-12 10:42:11 +01:00
|
|
|
if (splitName.length !== 2) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log(`Invalid name ${fullname}`);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
|
|
|
return null;
|
|
|
|
return this._getItemFromGroup(this.monitor_groups[splitName[1]], splitName[0]);
|
2020-11-12 10:42:11 +01:00
|
|
|
}
|
|
|
|
|
2020-05-04 10:08:39 +02:00
|
|
|
_removeFromArray(array, value) {
|
|
|
|
for(let i=0; i<array.length; i++) {
|
|
|
|
if (array[i] === value) {
|
|
|
|
array.splice(i, 1);
|
|
|
|
if (array === null)
|
|
|
|
array = [];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2020-04-01 09:36:51 +02:00
|
|
|
notify(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const parameters = JSON.parse(str);
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!this._checkParameters(parameters))
|
2020-11-19 11:20:03 +01:00
|
|
|
return;
|
2020-04-01 09:36:51 +02:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const groupName = parameters['group'];
|
2020-04-01 09:36:51 +02:00
|
|
|
let group;
|
|
|
|
if (!this.monitor_groups.hasOwnProperty(groupName)) {
|
|
|
|
group = [];
|
|
|
|
this.monitor_groups[groupName] = group;
|
|
|
|
} else {
|
|
|
|
group = this.monitor_groups[groupName];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let itemIndex in parameters['items']) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const item = parameters['items'][itemIndex];
|
2020-04-01 09:36:51 +02:00
|
|
|
let monitorWidget = this._getItemFromGroup(group, item['name']);
|
|
|
|
|
|
|
|
// New widget
|
|
|
|
if (monitorWidget === null) {
|
2020-11-19 11:20:03 +01:00
|
|
|
let position = group.length - 1;
|
|
|
|
// Find real position
|
|
|
|
if (position != -1) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const lastWidget = group[position].container;
|
|
|
|
const childrens = lastWidget.get_parent().get_children();
|
2020-11-19 11:20:03 +01:00
|
|
|
for(;position < childrens.length; position++)
|
|
|
|
{
|
|
|
|
if (childrens[position] == lastWidget) {
|
|
|
|
position++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (position >= childrens.length)
|
|
|
|
position = -1;
|
|
|
|
}
|
2020-11-05 15:36:14 +01:00
|
|
|
monitorWidget = new MonitorWidget(item, groupName, this, position);
|
2020-04-01 09:36:51 +02:00
|
|
|
group.push(monitorWidget);
|
|
|
|
} else {
|
2020-11-03 16:59:27 +01:00
|
|
|
monitorWidget.update(item);
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 10:08:39 +02:00
|
|
|
deleteItem(item, groupName) {
|
|
|
|
let group = this.monitor_groups[groupName];
|
|
|
|
group = this._removeFromArray(group, item);
|
2020-11-19 11:20:03 +01:00
|
|
|
item.destroy();
|
2020-05-04 10:08:39 +02:00
|
|
|
if (group.length === 0)
|
|
|
|
delete this.monitor_groups[groupName];
|
|
|
|
else
|
|
|
|
this.monitor_groups = group;
|
|
|
|
}
|
|
|
|
|
2020-04-01 09:36:51 +02:00
|
|
|
deleteItems(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const parameters = JSON.parse(str);
|
2020-04-01 09:36:51 +02:00
|
|
|
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!parameters.hasOwnProperty('items')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log('No items defined');
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
|
|
|
|
for (let itemIndex in parameters['items']) {
|
|
|
|
let itemName = parameters['items'][itemIndex];
|
2021-01-29 09:15:40 +01:00
|
|
|
const splitName = itemName.split('@');
|
2020-11-12 10:42:11 +01:00
|
|
|
if (splitName.length !== 2) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log(`Invalid name ${itemName}`);
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-12 10:42:11 +01:00
|
|
|
itemName = splitName[0];
|
|
|
|
let groupName = splitName[1];
|
2020-04-01 09:36:51 +02:00
|
|
|
if (!this.monitor_groups.hasOwnProperty(groupName))
|
|
|
|
continue;
|
|
|
|
let group = this.monitor_groups[groupName];
|
|
|
|
let item = this._getItemFromGroup(group, itemName);
|
|
|
|
if (item !== null) {
|
2020-05-04 10:08:39 +02:00
|
|
|
this.deleteItem(item, groupName);
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteGroups(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const parameters = JSON.parse(str);
|
2020-04-01 09:36:51 +02:00
|
|
|
|
2020-11-05 15:36:14 +01:00
|
|
|
if (!parameters.hasOwnProperty('groups')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log('No groups defined');
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-01 09:36:51 +02:00
|
|
|
|
|
|
|
let groupsToDelete = [];
|
|
|
|
for (let groupIndex in parameters['groups']) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const groupName = parameters['groups'][groupIndex];
|
2020-04-01 09:36:51 +02:00
|
|
|
if (!this.monitor_groups.hasOwnProperty(groupName))
|
|
|
|
continue;
|
2021-01-29 09:15:40 +01:00
|
|
|
const group = this.monitor_groups[groupName];
|
2020-04-01 09:36:51 +02:00
|
|
|
for (let itemIndex in group)
|
2020-11-19 11:20:03 +01:00
|
|
|
group[itemIndex].destroy();
|
2020-04-01 09:36:51 +02:00
|
|
|
groupsToDelete.push(groupName);
|
|
|
|
}
|
|
|
|
for (let groupDeleteIndex in groupsToDelete) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const groupName = groupsToDelete[groupDeleteIndex];
|
2020-04-01 09:36:51 +02:00
|
|
|
delete this.monitor_groups[groupName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 10:42:11 +01:00
|
|
|
_popupFunction(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const parameters = JSON.parse(str);
|
2020-11-12 10:42:11 +01:00
|
|
|
|
|
|
|
if (!parameters.hasOwnProperty('item')) {
|
2020-11-19 11:20:03 +01:00
|
|
|
log('No item defined');
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-12 10:42:11 +01:00
|
|
|
|
2021-01-29 09:15:40 +01:00
|
|
|
const monitorWidget = this._getItemFromFullName(parameters['item']);
|
2020-11-19 11:20:03 +01:00
|
|
|
if (monitorWidget !== null)
|
|
|
|
return monitorWidget;
|
|
|
|
else
|
|
|
|
log(`Item ${str} not found`);
|
2020-11-12 10:42:11 +01:00
|
|
|
|
2020-11-19 11:20:03 +01:00
|
|
|
return null;
|
2020-11-12 10:42:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
openPopup(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const monitorWidget = this._popupFunction(str)
|
2020-11-19 11:20:03 +01:00
|
|
|
if (monitorWidget !== null)
|
|
|
|
monitorWidget.openPopup();
|
2020-11-12 10:42:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
closePopup(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const monitorWidget = this._popupFunction(str)
|
2020-11-19 11:20:03 +01:00
|
|
|
if (monitorWidget !== null)
|
|
|
|
monitorWidget.closePopup();
|
2020-11-12 10:42:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
togglePopup(str) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const monitorWidget = this._popupFunction(str)
|
2020-11-19 11:20:03 +01:00
|
|
|
if (monitorWidget !== null)
|
|
|
|
monitorWidget.togglePopup();
|
2020-11-12 10:42:11 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 09:36:51 +02:00
|
|
|
destructor() {
|
2020-05-07 08:39:13 +02:00
|
|
|
this._dbusImpl.emit_signal('onDeactivate', null);
|
2020-04-01 09:36:51 +02:00
|
|
|
for (let groupIndex in this.monitor_groups) {
|
2021-01-29 09:15:40 +01:00
|
|
|
const group = this.monitor_groups[groupIndex];
|
2020-04-01 09:36:51 +02:00
|
|
|
for (let itemIndex in group)
|
2020-11-19 11:20:03 +01:00
|
|
|
group[itemIndex].destroy();
|
2020-04-01 09:36:51 +02:00
|
|
|
}
|
|
|
|
this.monitor_groups = {};
|
|
|
|
this._dbusImpl.unexport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Extension {
|
2020-03-30 10:45:26 +02:00
|
|
|
enable() {
|
2020-04-01 09:36:51 +02:00
|
|
|
this.textDBusService = new GenericMonitorDBUS();
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
2020-04-01 09:36:51 +02:00
|
|
|
this.textDBusService.destructor();
|
|
|
|
delete this.textDBusService;
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-27 17:54:37 +02:00
|
|
|
let extension = null;
|
2020-03-30 10:45:26 +02:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function enable() {
|
2022-10-27 17:54:37 +02:00
|
|
|
extension = new Extension();
|
2020-03-30 10:45:26 +02:00
|
|
|
extension.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
function disable() {
|
2022-10-27 17:54:37 +02:00
|
|
|
if (extension) {
|
|
|
|
extension.disable();
|
|
|
|
extension = null;
|
|
|
|
}
|
2020-03-30 10:45:26 +02:00
|
|
|
}
|