Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b4af852a0f | |||
6aa9f15d70 | |||
ca11b0e175 | |||
d0e8f0cde5 | |||
66d79cc804 |
57
README.md
57
README.md
@ -13,8 +13,11 @@ OR
|
||||
|
||||
Create a symbolic link from your _.local_ directory and enable extension
|
||||
|
||||
ln -s $PWD/generic-monitor@gnome-shell-extensions/ ~/.local/share/gnome-shell/extensions/
|
||||
gnome-extensions enable generic-monitor@gnome-shell-extensions
|
||||
```bash
|
||||
ln -s $PWD/generic-monitor@gnome-shell-extensions/ ~/.local/share/gnome-shell/extensions/
|
||||
|
||||
gnome-extensions enable generic-monitor@gnome-shell-extensions
|
||||
```
|
||||
|
||||
Restart GNOME
|
||||
|
||||
@ -24,6 +27,7 @@ DBUS protocol
|
||||
|
||||
All functions read JSON formatted parameters
|
||||
|
||||
```js
|
||||
notify():
|
||||
{
|
||||
"group": "groupname",
|
||||
@ -64,26 +68,32 @@ All functions read JSON formatted parameters
|
||||
{
|
||||
"item": "<itemName>@<groupName>"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
DBUS object
|
||||
===========
|
||||
|
||||
<text_object> is defined as :
|
||||
<text_object> is defined as:
|
||||
```js
|
||||
"text" : {
|
||||
"name" : "" // Optional, used with popup nested element
|
||||
<signals_description>, // Optional, used with popup nested element
|
||||
"text" : "Text to be displayed",
|
||||
"style" : "CSS style to be applied", // Optional
|
||||
}
|
||||
```
|
||||
|
||||
<icon_object> is defined as :
|
||||
<icon_object> is defined as:
|
||||
```js
|
||||
"icon" : {
|
||||
"path" : "Icon path",
|
||||
"style" : "CSS style to be applied", // Optional
|
||||
}
|
||||
```
|
||||
|
||||
<picture_object> is defined as :
|
||||
<picture_object> is defined as:
|
||||
```js
|
||||
"picture" : {
|
||||
"name" : "" // Optional, used with popup nested element
|
||||
<signals_description>, // Optional, used with popup nested element
|
||||
@ -91,18 +101,21 @@ DBUS object
|
||||
"width" : XXX, // Optional : Force width in pixels, can be -1 for defaut value
|
||||
"height" : XXX, // Optional : Force height in pixels, can be -1 for defaut value
|
||||
}
|
||||
```
|
||||
|
||||
<popup_object is defuned as :
|
||||
<popup_object> is defined as:
|
||||
```js
|
||||
"popup" : {
|
||||
"items": [<text_objects> and/or <picture_objects>]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Signals description
|
||||
===================
|
||||
|
||||
Signals can be :
|
||||
|
||||
```js
|
||||
"on-click" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
"on-dblclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
"on-rightclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
@ -110,6 +123,7 @@ Signals can be :
|
||||
"on-enter" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
"on-leave" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
"on-scroll" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
|
||||
```
|
||||
|
||||
Targets :
|
||||
|
||||
@ -118,9 +132,9 @@ Targets :
|
||||
* open-popup : Open the popup if there is one
|
||||
* close-popup : Close the popup if there is one
|
||||
* toggle-popup : Toggle (open/close) the popup if there is one
|
||||
|
||||
|
||||
Signal names emit when action "signal" is specified :
|
||||
|
||||
Signal names emit when action "signal" is specified:
|
||||
|
||||
* onClick
|
||||
* onDblClick
|
||||
@ -131,11 +145,11 @@ Signal names emit when action "signal" is specified :
|
||||
* onScrollUp
|
||||
* onScrollDown
|
||||
|
||||
Each signal is sent with one parameter : "<itemName>@<groupName>"
|
||||
Each signal is sent with one parameter: "<itemName>@<groupName>"
|
||||
For popup nested elements, parameter is "<nestedName>@<itemName>@<groupName>"
|
||||
where nestedName can be empty if not defined by user
|
||||
|
||||
Other signals are available when extension is activated/deactivated :
|
||||
Other signals are available when extension is activated/deactivated:
|
||||
|
||||
* onActivate
|
||||
* onDeactivate
|
||||
@ -144,11 +158,15 @@ Other signals are available when extension is activated/deactivated :
|
||||
Example
|
||||
-------
|
||||
|
||||
You can test it with command line :
|
||||
You can test it with command line:
|
||||
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":{"text":"Hello","style":"color:green"},"popup":{"items":[{"picture":{"path":"/tmp/cat.jpg"}}]}}]}'
|
||||
```bash
|
||||
# Create new group and add items
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":{"text":"Hello","style":"color:green"},"popup":{"items":[{"picture":{"path":"/tmp/cat.jpg"}}]}}]}'
|
||||
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.deleteGroups '{"groups":["new"]}'
|
||||
# Delete group
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.deleteGroups '{"groups":["new"]}'
|
||||
```
|
||||
|
||||
Python examples are available @ https://indefero.soutade.fr/p/genericmonitor/source/tree/master/examples
|
||||
|
||||
@ -158,12 +176,15 @@ Development
|
||||
|
||||
After doing code update, you can test it within a nested window. In other cases you have to restart GNOME.
|
||||
|
||||
dbus-run-session -- gnome-shell --nested [--wayland]
|
||||
```bash
|
||||
dbus-run-session -- gnome-shell --nested [--wayland]
|
||||
```
|
||||
|
||||
To see log & errors :
|
||||
|
||||
journalctl /usr/bin/gnome-shell
|
||||
To see log & errors:
|
||||
|
||||
```bash
|
||||
journalctl /usr/bin/gnome-shell
|
||||
```
|
||||
|
||||
Licence
|
||||
-------
|
||||
|
@ -23,6 +23,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os.path
|
||||
import json
|
||||
|
||||
from google.auth.transport.requests import Request
|
||||
from google.oauth2.credentials import Credentials
|
||||
@ -37,7 +38,7 @@ creds = None
|
||||
def _initCreds():
|
||||
global creds
|
||||
if creds: return
|
||||
|
||||
|
||||
# The file token.json stores the user's access and refresh tokens, and is
|
||||
# created automatically when the authorization flow completes for the first
|
||||
# time.
|
||||
@ -53,15 +54,21 @@ def _initCreds():
|
||||
creds = flow.run_local_server(port=0)
|
||||
# Save the credentials for the next run
|
||||
with open('token.json', 'w') as token:
|
||||
token.write(creds.to_json())
|
||||
|
||||
data = {}
|
||||
data['refresh_token'] = creds.refresh_token
|
||||
data['client_id'] = creds.client_id
|
||||
data['client_secret'] = creds.client_secret
|
||||
data['token_uri'] = creds.token_uri
|
||||
data['id_token'] = creds.id_token
|
||||
token.write(json.dumps(data))
|
||||
|
||||
def getUnreadMails():
|
||||
"""
|
||||
Get number of unread threads (that may contain multiple messages)
|
||||
"""
|
||||
|
||||
_initCreds()
|
||||
|
||||
|
||||
service = build('gmail', 'v1', credentials=creds)
|
||||
pageToken = ''
|
||||
threads = set()
|
||||
@ -69,6 +76,7 @@ def getUnreadMails():
|
||||
results = service.users().messages().list(userId='me', labelIds=['UNREAD'],\
|
||||
includeSpamTrash=False, pageToken=pageToken)\
|
||||
.execute()
|
||||
if not 'messages' in results.keys(): continue
|
||||
threads = threads.union(set([k['threadId'] for k in results['messages']]))
|
||||
# Loop over all result pages (100 results per page by default)
|
||||
pageToken = results.get('nextPageToken', '')
|
||||
|
@ -43,15 +43,12 @@ class PicturePopup(GenericMonitor):
|
||||
self.runMainLoop()
|
||||
|
||||
def display_next_img(self):
|
||||
filedata = urllib.request.urlopen('https://source.unsplash.com/random')
|
||||
# Get redirected URL without parameters
|
||||
url = filedata.url.split('?')[0]
|
||||
filedata = urllib.request.urlopen(url + '?fit=max&width=500&height=500')
|
||||
filedata = urllib.request.urlopen('https://picsum.photos/500/500')
|
||||
datatowrite = filedata.read()
|
||||
with open('/tmp/cat2.jpg', 'wb') as f:
|
||||
f.write(datatowrite)
|
||||
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
||||
url_widget = GenericMonitorTextWidget(url, 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
||||
url_widget = GenericMonitorTextWidget('random_pic', 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
||||
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg', name='NestedWidget', signals={'on-click':'signal'})
|
||||
popup = GenericMonitorPopup([url_widget, picture_widget])
|
||||
signals = {
|
||||
|
183
extension.js
183
extension.js
@ -29,17 +29,17 @@
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panel.js
|
||||
*/
|
||||
|
||||
const St = imports.gi.St;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib
|
||||
const Main = imports.ui.main;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Clutter = imports.gi.Clutter;
|
||||
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;
|
||||
import * as Extension from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||
import St from 'gi://St';
|
||||
import Gio from 'gi://Gio';
|
||||
import GLib from 'gi://GLib';
|
||||
import Clutter from 'gi://Clutter';
|
||||
import GObject from 'gi://GObject';
|
||||
import Pixbuf from 'gi://GdkPixbuf';
|
||||
import Cogl from 'gi://Cogl';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
|
||||
|
||||
|
||||
function hashGet(hash, key, defaultValue) {
|
||||
@ -49,18 +49,14 @@ function hashGet(hash, key, defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
global.log('[GenericMontior]', message);
|
||||
}
|
||||
|
||||
|
||||
class SignalMgt {
|
||||
|
||||
constructor(item, name, group, dbus, buttonMenu) {
|
||||
constructor(item, name, group, dbus, logger, buttonMenu) {
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.logger = logger;
|
||||
this.buttonMenu = buttonMenu;
|
||||
this.signals = new WeakMap();
|
||||
this.widgets = new Array();
|
||||
@ -79,7 +75,7 @@ class SignalMgt {
|
||||
this.onScroll = hashGet(item, 'on-scroll', '');
|
||||
}
|
||||
|
||||
destructor() {
|
||||
destroy() {
|
||||
for(let widgetIdx in this.widgets)
|
||||
this.disconnectWidgetSignals(this.widgets[widgetIdx]);
|
||||
for(let timeoutIdx in this.timeouts)
|
||||
@ -100,6 +96,7 @@ class SignalMgt {
|
||||
this.widgets.push(widget);
|
||||
let array = new Array();
|
||||
this.signals.set(widget, array);
|
||||
widget.set_reactive(true);
|
||||
let id;
|
||||
id = widget.connect('enter-event', this._onEnter.bind(this));
|
||||
array.push(id);
|
||||
@ -107,7 +104,6 @@ class SignalMgt {
|
||||
array.push(id);
|
||||
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
||||
array.push(id);
|
||||
widget.set_reactive(true);
|
||||
id = widget.connect('button-release-event', this._clicked.bind(this));
|
||||
array.push(id);
|
||||
}
|
||||
@ -119,38 +115,34 @@ class SignalMgt {
|
||||
this.signals.set(widget, null);
|
||||
}
|
||||
|
||||
toggleMenu() {
|
||||
if (this.menuOpen)
|
||||
{
|
||||
this.buttonMenu.menu.close();
|
||||
this.menuOpen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.buttonMenu.menu.open(true);
|
||||
this.menuOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
_manageEventAction(action, signalName) {
|
||||
/*
|
||||
GNOME 48 : onEnter && this.buttonMenu.menuOpen == close popup without onClick event
|
||||
*/
|
||||
if (signalName == "onEnter" && this.buttonMenu.menuOpen)
|
||||
{
|
||||
this.buttonMenu.menuOpen = false;
|
||||
return Clutter.EVENT_STOP;
|
||||
}
|
||||
|
||||
if (action === 'open-popup')
|
||||
{
|
||||
this.buttonMenu.menu.open(true);
|
||||
this.menuOpen = true;
|
||||
this.buttonMenu.openPopup();
|
||||
}
|
||||
else if (action === 'close-popup')
|
||||
{
|
||||
this.buttonMenu.menu.close();
|
||||
this.menuOpen = false;
|
||||
this.buttonMenu.closePopup();
|
||||
}
|
||||
else if (action === 'toggle-popup')
|
||||
{
|
||||
this.toggleMenu();
|
||||
this.buttonMenu.togglePopup();
|
||||
}
|
||||
else if (action === 'delete')
|
||||
this.dbus.deleteItem(this, this.group);
|
||||
else if (action === 'signal')
|
||||
this.dbus.emitSignal(signalName, this.fullname);
|
||||
else
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
|
||||
return Clutter.EVENT_STOP;
|
||||
}
|
||||
@ -165,7 +157,7 @@ class SignalMgt {
|
||||
nbClicks = 'Dbl';
|
||||
|
||||
const signalName = 'on' + right + nbClicks + 'Click';
|
||||
|
||||
|
||||
let action = 'signal';
|
||||
switch(signalName) {
|
||||
case 'onClick': action = this.onClick; break;
|
||||
@ -174,11 +166,11 @@ class SignalMgt {
|
||||
case 'onRightDblClick': action = this.onRightDblClick; break;
|
||||
}
|
||||
|
||||
this._manageEventAction(action, signalName);
|
||||
|
||||
this.nbClicks = 0;
|
||||
this.button = -1;
|
||||
|
||||
this._manageEventAction(action, signalName);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -189,12 +181,13 @@ class SignalMgt {
|
||||
this.button = event.get_button();
|
||||
this.nbClicks = 1;
|
||||
|
||||
let sourceId = Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
||||
this._doClickCallback.bind(this));
|
||||
let sourceId = GLib.timeout_add(GLib.G_PRIORITY_DEFAULT,
|
||||
this.dbus.ClutterSettings['double-click-time'],
|
||||
this._doClickCallback.bind(this));
|
||||
this.timeouts.push(sourceId);
|
||||
}
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
return Clutter.EVENT_STOP;
|
||||
}
|
||||
|
||||
_onEnter(/*actor, event*/) {
|
||||
@ -225,10 +218,10 @@ class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||
super._init(params);
|
||||
|
||||
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
||||
this.box.set_vertical(true);
|
||||
this.box.set_orientation(Clutter.Orientation.VERTICAL);
|
||||
|
||||
for (let widgetIndex in widgets)
|
||||
this.box.add(widgets[widgetIndex]);
|
||||
this.box.add_child(widgets[widgetIndex]);
|
||||
|
||||
this.add_child(this.box);
|
||||
}
|
||||
@ -240,15 +233,16 @@ var MonitorWidget = GObject.registerClass({
|
||||
},
|
||||
class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
_init(item, group, dbus, position) {
|
||||
_init(item, group, dbus, logger, position) {
|
||||
super._init(0.0);
|
||||
|
||||
this.name = item['name'];
|
||||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.logger = logger;
|
||||
this.menuItem = null;
|
||||
this.signalManager = new SignalMgt(item, this.name, group, dbus, this);
|
||||
this.signalManager = new SignalMgt(item, this.name, group, dbus, logger, this);
|
||||
this.popup_signals = null;
|
||||
this.popup_widgets = null;
|
||||
|
||||
@ -381,18 +375,24 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
openPopup() {
|
||||
this.menu.open(true);
|
||||
this.menuOpen = this.menu.isOpen = true;
|
||||
}
|
||||
|
||||
closePopup() {
|
||||
this.menu.close();
|
||||
this.menuOpen = this.menu.isOpen = false;
|
||||
}
|
||||
|
||||
togglePopup() {
|
||||
this.menu.toggle();
|
||||
if (this.menuOpen)
|
||||
this.closePopup();
|
||||
else
|
||||
this.openPopup();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.menu.close();
|
||||
this.signalManager.destroy();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
nestedItem = widgetDict['picture'];
|
||||
widget = this._createPicture(nestedItem);
|
||||
} else {
|
||||
log('No known widget defined in popup');
|
||||
this.logger.error('No known widget defined in popup');
|
||||
}
|
||||
|
||||
if (nestedItem === null) {
|
||||
@ -433,7 +433,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
const name = hashGet(nestedItem, 'name', '');
|
||||
this.popup_signals[widget] = new SignalMgt(nestedItem, name,
|
||||
this.fullname, this.dbus,
|
||||
this);
|
||||
this.logger, this);
|
||||
this.popup_signals[widget].connectWidgetSignals(widget);
|
||||
this.popup_widgets.push(widget);
|
||||
}
|
||||
@ -458,7 +458,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
__createText(item, isLabel) {
|
||||
if (!item.hasOwnProperty('text')) {
|
||||
log('Text must have a \'text\' value');
|
||||
this.logger.error('Text must have a \'text\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -498,7 +498,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
_createIcon(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log('Icon must have a \'path\' value');
|
||||
this.logger.error('Icon must have a \'path\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -519,7 +519,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
_createPicture(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log('Picture must have a \'path\' value');
|
||||
this.logger.error('Picture must have a \'path\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -532,9 +532,11 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
if (typeof(height) === 'string')
|
||||
height = parseInt(height, 10);
|
||||
|
||||
const img = new Clutter.Image();
|
||||
const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||
img.set_data(initialPixbuf.get_pixels(),
|
||||
const img = St.ImageContent.new_with_preferred_size(initialPixbuf.get_width(),
|
||||
initialPixbuf.get_height());
|
||||
img.set_data(global.stage.context.get_backend().get_cogl_context(),
|
||||
initialPixbuf.get_pixels(),
|
||||
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||
: Cogl.PixelFormat.RGB_888,
|
||||
initialPixbuf.get_width(),
|
||||
@ -555,14 +557,12 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
// 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) {
|
||||
const extension = imports.misc.extensionUtils.getCurrentExtension();
|
||||
|
||||
function loadInterfaceXml(extension, filename) {
|
||||
const interfacesDir = extension.dir.get_child('.');
|
||||
|
||||
const file = interfacesDir.get_child(filename);
|
||||
|
||||
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
||||
let [result, contents] = GLib.file_get_contents(file.get_path());
|
||||
|
||||
if (result) {
|
||||
// HACK: The "" + trick is important as hell because file_get_contents returns
|
||||
@ -571,7 +571,10 @@ function loadInterfaceXml(filename) {
|
||||
// is no `XML` on very recent SpiderMonkey releases (or, if SpiderMonkey is old enough,
|
||||
// will spit out a TypeError soon).
|
||||
if (contents instanceof Uint8Array)
|
||||
contents = imports.byteArray.toString(contents);
|
||||
{
|
||||
const decoder = new TextDecoder();
|
||||
contents = decoder.decode(contents);
|
||||
}
|
||||
const res = `<node>${contents}</node>`;
|
||||
return res;
|
||||
} else {
|
||||
@ -580,11 +583,12 @@ function loadInterfaceXml(filename) {
|
||||
}
|
||||
|
||||
class GenericMonitorDBUS {
|
||||
constructor() {
|
||||
constructor(extension) {
|
||||
this.logger = extension.getLogger();
|
||||
this.monitor_groups = {};
|
||||
this.actor_clicked = {};
|
||||
this.ClutterSettings = Clutter.Settings.get_default();
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml(extension, 'dbus.xml'), this);
|
||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||
this._dbusImpl.emit_signal('onActivate', null);
|
||||
}
|
||||
@ -595,19 +599,19 @@ class GenericMonitorDBUS {
|
||||
|
||||
_checkParameters(parameters) {
|
||||
if (!parameters.hasOwnProperty('group')) {
|
||||
log('No group defined');
|
||||
this.logger.error('No group defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parameters.hasOwnProperty('items')) {
|
||||
log('No items defined');
|
||||
this.logger.error('No items defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let itemIndex in parameters['items']) {
|
||||
const item = parameters['items'][itemIndex];
|
||||
if (!item.hasOwnProperty('name')) {
|
||||
log('No name defined for item');
|
||||
this.logger.error('No name defined for item');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -628,7 +632,7 @@ class GenericMonitorDBUS {
|
||||
_getItemFromFullName(fullname) {
|
||||
const splitName = fullname.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${fullname}`);
|
||||
this.logger.error(`Invalid name ${fullname}`);
|
||||
return null;
|
||||
}
|
||||
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
||||
@ -683,7 +687,7 @@ class GenericMonitorDBUS {
|
||||
if (position >= childrens.length)
|
||||
position = -1;
|
||||
}
|
||||
monitorWidget = new MonitorWidget(item, groupName, this, position);
|
||||
monitorWidget = new MonitorWidget(item, groupName, this, this.logger, position);
|
||||
group.push(monitorWidget);
|
||||
} else {
|
||||
monitorWidget.update(item);
|
||||
@ -705,7 +709,7 @@ class GenericMonitorDBUS {
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('items')) {
|
||||
log('No items defined');
|
||||
this.logger.error('No items defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -713,7 +717,7 @@ class GenericMonitorDBUS {
|
||||
let itemName = parameters['items'][itemIndex];
|
||||
const splitName = itemName.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${itemName}`);
|
||||
this.logger.error(`Invalid name ${itemName}`);
|
||||
return false;
|
||||
}
|
||||
itemName = splitName[0];
|
||||
@ -732,7 +736,7 @@ class GenericMonitorDBUS {
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('groups')) {
|
||||
log('No groups defined');
|
||||
this.logger.error('No groups defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -756,7 +760,7 @@ class GenericMonitorDBUS {
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('item')) {
|
||||
log('No item defined');
|
||||
this.logger.error('No item defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -764,7 +768,7 @@ class GenericMonitorDBUS {
|
||||
if (monitorWidget !== null)
|
||||
return monitorWidget;
|
||||
else
|
||||
log(`Item ${str} not found`);
|
||||
this.logger.error(`Item ${str} not found`);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -787,7 +791,7 @@ class GenericMonitorDBUS {
|
||||
monitorWidget.togglePopup();
|
||||
}
|
||||
|
||||
destructor() {
|
||||
destroy() {
|
||||
this._dbusImpl.emit_signal('onDeactivate', null);
|
||||
for (let groupIndex in this.monitor_groups) {
|
||||
const group = this.monitor_groups[groupIndex];
|
||||
@ -799,30 +803,21 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
}
|
||||
|
||||
class Extension {
|
||||
export default class GenericMonitorExtension extends Extension.Extension {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.textDBusService = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
this.textDBusService = new GenericMonitorDBUS();
|
||||
this.textDBusService = new GenericMonitorDBUS(this);
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.textDBusService.destructor();
|
||||
delete this.textDBusService;
|
||||
}
|
||||
}
|
||||
|
||||
let extension = null;
|
||||
|
||||
function init() {
|
||||
}
|
||||
|
||||
function enable() {
|
||||
extension = new Extension();
|
||||
extension.enable();
|
||||
}
|
||||
|
||||
function disable() {
|
||||
if (extension) {
|
||||
extension.disable();
|
||||
extension = null;
|
||||
if (this.textDBusService !== null) {
|
||||
this.textDBusService.destroy();
|
||||
delete this.textDBusService;
|
||||
this.textDBusService = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,9 @@
|
||||
"uuid": "generic-monitor@gnome-shell-extensions",
|
||||
"name": "Generic Monitor",
|
||||
"description": "Display text & icon on systray using DBUS",
|
||||
"version": "13",
|
||||
"version": "16",
|
||||
"shell-version": [
|
||||
"44",
|
||||
"43",
|
||||
"42.3",
|
||||
"42",
|
||||
"41"
|
||||
"48"
|
||||
],
|
||||
"url": "http://indefero.soutade.fr/p/genericmonitor"
|
||||
"url": "https://forge.soutade.fr/soutade/GnomeShellGenericMonitor"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user