Lint fixes
This commit is contained in:
parent
d7e6db3bec
commit
b3200da89c
15
example.py
15
example.py
@ -79,7 +79,11 @@ def getEvents(mail_user, mail_password, proxy):
|
|||||||
encoder = json.JSONEncoder()
|
encoder = json.JSONEncoder()
|
||||||
res = {'group':'Mail', 'items':[]}
|
res = {'group':'Mail', 'items':[]}
|
||||||
res['items'] += getMail(mail_user, mail_password)
|
res['items'] += getMail(mail_user, mail_password)
|
||||||
|
try:
|
||||||
proxy.notify(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
proxy.notify(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
||||||
|
except dbus.exceptions.DBusException as e:
|
||||||
|
print(str(e))
|
||||||
|
pass
|
||||||
|
|
||||||
class StockThread(Thread):
|
class StockThread(Thread):
|
||||||
SLEEP_TIME = 30
|
SLEEP_TIME = 30
|
||||||
@ -103,7 +107,10 @@ def signalHandler(signal_received, frame):
|
|||||||
stockThread.join()
|
stockThread.join()
|
||||||
encoder = json.JSONEncoder()
|
encoder = json.JSONEncoder()
|
||||||
res = {'groups':['Mail', 'Pidgin']}
|
res = {'groups':['Mail', 'Pidgin']}
|
||||||
|
try:
|
||||||
systray_proxy.deleteGroups(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
systray_proxy.deleteGroups(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
PURPLE_CONV_UPDATE_UNSEEN = 4
|
PURPLE_CONV_UPDATE_UNSEEN = 4
|
||||||
@ -171,7 +178,11 @@ def pidginConversationUpdated(conversation, _type):
|
|||||||
if not pidginConversation.isSeen():
|
if not pidginConversation.isSeen():
|
||||||
res = {'group':'Pidgin', 'items':[]}
|
res = {'group':'Pidgin', 'items':[]}
|
||||||
res['items'] += DBUSItem('pidgin', icon='/usr/share/icons/hicolor/22x22/apps/pidgin.png', iconStyle='icon-size:22px').toMap()
|
res['items'] += DBUSItem('pidgin', icon='/usr/share/icons/hicolor/22x22/apps/pidgin.png', iconStyle='icon-size:22px').toMap()
|
||||||
|
try:
|
||||||
systray_proxy.notify(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
systray_proxy.notify(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
||||||
|
except dbus.exceptions.DBusException as e:
|
||||||
|
print(str(e))
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
deleteIcon = True
|
deleteIcon = True
|
||||||
# Are all messages seen ?
|
# Are all messages seen ?
|
||||||
@ -181,7 +192,11 @@ def pidginConversationUpdated(conversation, _type):
|
|||||||
break
|
break
|
||||||
if deleteIcon:
|
if deleteIcon:
|
||||||
res = {'items':['pidgin@Pidgin']}
|
res = {'items':['pidgin@Pidgin']}
|
||||||
|
try:
|
||||||
systray_proxy.deleteItems(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
systray_proxy.deleteItems(encoder.encode(res), dbus_interface='com.soutade.GenericMonitor')
|
||||||
|
except dbus.exceptions.DBusException as e:
|
||||||
|
print(str(e))
|
||||||
|
pass
|
||||||
|
|
||||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
|
222
extension.js
222
extension.js
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
const St = imports.gi.St;
|
const St = imports.gi.St;
|
||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
const Lang = imports.lang;
|
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
|
|
||||||
class MonitorWidget {
|
class MonitorWidget {
|
||||||
@ -31,64 +30,55 @@ class MonitorWidget {
|
|||||||
this._createText(text, style);
|
this._createText(text, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createText(text, style)
|
_createText(text, style) {
|
||||||
{
|
|
||||||
this.style = style;
|
this.style = style;
|
||||||
if (text == "")
|
if (text === '') {
|
||||||
this.widget = null;
|
this.widget = null;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
this.widget = new St.Button({ label: text });
|
this.widget = new St.Button({ label: text });
|
||||||
this.widget.set_style(this.style);
|
this.widget.set_style(this.style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_createIcon(icon, style)
|
_createIcon(icon, style) {
|
||||||
{
|
|
||||||
this.iconStyle = style;
|
this.iconStyle = style;
|
||||||
if (icon == "")
|
if (icon === '') {
|
||||||
this.icon = null;
|
this.icon = null;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
let gicon = Gio.icon_new_for_string(icon);
|
let gicon = Gio.icon_new_for_string(icon);
|
||||||
this.icon = new St.Icon({ gicon });
|
this.icon = new St.Icon({ gicon });
|
||||||
this.icon.set_style(this.iconStyle);
|
this.icon.set_style(this.iconStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update(text, style, icon, iconStyle)
|
update(text, style, icon, iconStyle) {
|
||||||
{
|
if (!this.widget) {
|
||||||
if (!this.widget)
|
this._createText(text, style);
|
||||||
this._createText(text, style)
|
} else {
|
||||||
else
|
if (text !== '')
|
||||||
{
|
|
||||||
if (text != "")
|
|
||||||
this.widget.label = text;
|
this.widget.label = text;
|
||||||
this.style = style;
|
this.style = style;
|
||||||
this.widget.set_style(this.style);
|
this.widget.set_style(this.style);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon != "")
|
if (icon !== '')
|
||||||
this._createIcon(icon, iconStyle);
|
this._createIcon(icon, iconStyle);
|
||||||
else
|
|
||||||
{
|
if (icon === '' && iconStyle !== '' && this.icon) {
|
||||||
if (iconStyle != "" && this.icon)
|
|
||||||
{
|
|
||||||
this.iconStyle = style;
|
this.iconStyle = style;
|
||||||
this.icon.set_style(this.iconStyle);
|
this.icon.set_style(this.iconStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
||||||
// loads a xml file into an in-memory string
|
// loads a xml file into an in-memory string
|
||||||
function loadInterfaceXml(filename) {
|
function loadInterfaceXml(filename) {
|
||||||
let extension = imports.misc.extensionUtils.getCurrentExtension();
|
let extension = imports.misc.extensionUtils.getCurrentExtension();
|
||||||
|
|
||||||
let interfaces_dir = extension.dir.get_child(".")
|
let interfacesDir = extension.dir.get_child('.');
|
||||||
|
|
||||||
let file = interfaces_dir.get_child(filename);
|
let file = interfacesDir.get_child(filename);
|
||||||
|
|
||||||
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
||||||
|
|
||||||
@ -100,108 +90,98 @@ function loadInterfaceXml(filename) {
|
|||||||
// will spit out a TypeError soon).
|
// will spit out a TypeError soon).
|
||||||
if (contents instanceof Uint8Array)
|
if (contents instanceof Uint8Array)
|
||||||
contents = imports.byteArray.toString(contents);
|
contents = imports.byteArray.toString(contents);
|
||||||
return "<node>" + contents + "</node>";
|
let res = `<node>${contents}</node>`;
|
||||||
|
return res;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Generic monitor: Could not load file: "+filename);
|
throw new Error(`Generic monitor: Could not load file: ${filename}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const GenericMonitorDBUS = new Lang.Class({
|
class GenericMonitorDBUS {
|
||||||
Name: 'GenericMonitor',
|
constructor() {
|
||||||
|
|
||||||
_init: function() {
|
|
||||||
this.monitor_groups = {};
|
this.monitor_groups = {};
|
||||||
this.box = Main.panel._centerBox;
|
this.box = Main.panel._centerBox;
|
||||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
||||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||||
},
|
|
||||||
|
|
||||||
_checkParmeters: function(parameters)
|
|
||||||
{
|
|
||||||
if (!parameters.hasOwnProperty("group"))
|
|
||||||
throw new Error("No group defined");
|
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty("items"))
|
|
||||||
throw new Error("No items defined");
|
|
||||||
|
|
||||||
for (let itemIndex in parameters["items"]) {
|
|
||||||
let item = parameters["items"][itemIndex];
|
|
||||||
if (!item.hasOwnProperty("name"))
|
|
||||||
throw new Error("No name defined for item");
|
|
||||||
if (!item.hasOwnProperty("text") && !item.hasOwnProperty("icon"))
|
|
||||||
throw new Error("No text not icon defined for item");
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
_getItemFromGroup: function(group, name)
|
_checkParmeters(parameters) {
|
||||||
{
|
if (!parameters.hasOwnProperty('group'))
|
||||||
for (let groupItemIndex in group)
|
throw new Error('No group defined');
|
||||||
{
|
|
||||||
|
if (!parameters.hasOwnProperty('items'))
|
||||||
|
throw new Error('No items defined');
|
||||||
|
|
||||||
|
for (let itemIndex in parameters['items']) {
|
||||||
|
let item = parameters['items'][itemIndex];
|
||||||
|
if (!item.hasOwnProperty('name'))
|
||||||
|
throw new Error('No name defined for item');
|
||||||
|
if (!item.hasOwnProperty('text') && !item.hasOwnProperty('icon'))
|
||||||
|
throw new Error('No text not icon defined for item');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_getItemFromGroup(group, name) {
|
||||||
|
for (let groupItemIndex in group) {
|
||||||
let groupItem = group[groupItemIndex];
|
let groupItem = group[groupItemIndex];
|
||||||
if (groupItem.name == name)
|
if (groupItem.name === name)
|
||||||
return groupItem;
|
return groupItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
|
|
||||||
notify: function(str) {
|
notify(str) {
|
||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
this._checkParmeters(parameters);
|
this._checkParmeters(parameters);
|
||||||
|
|
||||||
let groupName = parameters["group"];
|
let groupName = parameters['group'];
|
||||||
let group;
|
let group;
|
||||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
if (!this.monitor_groups.hasOwnProperty(groupName)) {
|
||||||
{
|
|
||||||
group = [];
|
group = [];
|
||||||
this.monitor_groups[groupName] = group;
|
this.monitor_groups[groupName] = group;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
group = this.monitor_groups[groupName];
|
group = this.monitor_groups[groupName];
|
||||||
|
}
|
||||||
|
|
||||||
for (let itemIndex in parameters["items"]) {
|
for (let itemIndex in parameters['items']) {
|
||||||
let item = parameters["items"][itemIndex];
|
let item = parameters['items'][itemIndex];
|
||||||
let style = "";
|
let style = '';
|
||||||
if (item.hasOwnProperty("style"))
|
if (item.hasOwnProperty('style'))
|
||||||
style = item["style"];
|
style = item['style'];
|
||||||
let text = "";
|
let text = '';
|
||||||
if (item.hasOwnProperty("text"))
|
if (item.hasOwnProperty('text'))
|
||||||
text = item["text"];
|
text = item['text'];
|
||||||
let icon = "";
|
let icon = '';
|
||||||
if (item.hasOwnProperty("icon"))
|
if (item.hasOwnProperty('icon'))
|
||||||
icon = item["icon"];
|
icon = item['icon'];
|
||||||
let iconStyle = "";
|
let iconStyle = '';
|
||||||
if (item.hasOwnProperty("icon-style"))
|
if (item.hasOwnProperty('icon-style'))
|
||||||
iconStyle = item["icon-style"];
|
iconStyle = item['icon-style'];
|
||||||
|
|
||||||
let monitorWidget = this._getItemFromGroup(group, item["name"]);
|
let monitorWidget = this._getItemFromGroup(group, item['name']);
|
||||||
let lastWidget = null;
|
let lastWidget = null;
|
||||||
|
|
||||||
// New widget
|
// New widget
|
||||||
if (monitorWidget == null)
|
if (monitorWidget === null) {
|
||||||
{
|
monitorWidget = new MonitorWidget(item['name'], groupName, text, style, icon, iconStyle);
|
||||||
monitorWidget = new MonitorWidget(item["name"], groupName, text, style, icon, iconStyle);
|
|
||||||
if (group.length)
|
if (group.length)
|
||||||
lastWidget = group[group.length - 1].widget;
|
lastWidget = group[group.length - 1].widget;
|
||||||
group.push(monitorWidget);
|
group.push(monitorWidget);
|
||||||
// lastWidget => NULL, insert at the end
|
// lastWidget => NULL, insert at the end
|
||||||
if (monitorWidget.icon)
|
if (monitorWidget.icon) {
|
||||||
{
|
|
||||||
this.box.insert_child_above(monitorWidget.icon, lastWidget);
|
this.box.insert_child_above(monitorWidget.icon, lastWidget);
|
||||||
lastWidget = monitorWidget.icon;
|
lastWidget = monitorWidget.icon;
|
||||||
}
|
}
|
||||||
if (monitorWidget.widget)
|
if (monitorWidget.widget)
|
||||||
this.box.insert_child_above(monitorWidget.widget, lastWidget);
|
this.box.insert_child_above(monitorWidget.widget, lastWidget);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
let prevWidget = monitorWidget.widget;
|
let prevWidget = monitorWidget.widget;
|
||||||
let prevIcon = monitorWidget.icon;
|
let prevIcon = monitorWidget.icon;
|
||||||
|
|
||||||
monitorWidget.update(text, style, icon, iconStyle);
|
monitorWidget.update(text, style, icon, iconStyle);
|
||||||
|
|
||||||
if (monitorWidget.icon)
|
if (monitorWidget.icon) {
|
||||||
{
|
|
||||||
if (prevIcon)
|
if (prevIcon)
|
||||||
this.box.remove_child(prevIcon);
|
this.box.remove_child(prevIcon);
|
||||||
this.box.insert_child_above(monitorWidget.icon, lastWidget);
|
this.box.insert_child_above(monitorWidget.icon, lastWidget);
|
||||||
@ -212,94 +192,88 @@ const GenericMonitorDBUS = new Lang.Class({
|
|||||||
this.box.insert_child_above(monitorWidget.widget, lastWidget);
|
this.box.insert_child_above(monitorWidget.widget, lastWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_removeItemFromBox: function(item) {
|
_removeItemFromBox(item) {
|
||||||
if (item.widget)
|
if (item.widget)
|
||||||
this.box.remove_child(item.widget);
|
this.box.remove_child(item.widget);
|
||||||
if (item.icon)
|
if (item.icon)
|
||||||
this.box.remove_child(item.icon);
|
this.box.remove_child(item.icon);
|
||||||
},
|
}
|
||||||
|
|
||||||
deleteItems: function(str) {
|
deleteItems(str) {
|
||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty("items"))
|
if (!parameters.hasOwnProperty('items'))
|
||||||
throw new Error("No items defined");
|
throw new Error('No items defined');
|
||||||
|
|
||||||
for (let itemIndex in parameters["items"]) {
|
for (let itemIndex in parameters['items']) {
|
||||||
let itemName = parameters["items"][itemIndex];
|
let itemName = parameters['items'][itemIndex];
|
||||||
let fullName = itemName.split("@");
|
let fullName = itemName.split('@');
|
||||||
if (fullName.length != 2)
|
if (fullName.length !== 2)
|
||||||
throw new Error("Invalid name " + itemName);
|
throw new Error(`Invalid name ${itemName}`);
|
||||||
itemName = fullName[0];
|
itemName = fullName[0];
|
||||||
let groupName = fullName[1];
|
let groupName = fullName[1];
|
||||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
if (!this.monitor_groups.hasOwnProperty(groupName))
|
||||||
continue;
|
continue;
|
||||||
let group = this.monitor_groups[groupName];
|
let group = this.monitor_groups[groupName];
|
||||||
let item = this._getItemFromGroup(group, itemName);
|
let item = this._getItemFromGroup(group, itemName);
|
||||||
if (item != null)
|
if (item !== null) {
|
||||||
{
|
|
||||||
this._removeItemFromBox(item);
|
this._removeItemFromBox(item);
|
||||||
delete group[item["name"]];
|
delete group[item['name']];
|
||||||
if (group.length == 0)
|
if (group.length === 0)
|
||||||
delete this.monitor_groups[groupName];
|
delete this.monitor_groups[groupName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
deleteGroups: function(str) {
|
deleteGroups(str) {
|
||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty("groups"))
|
if (!parameters.hasOwnProperty('groups'))
|
||||||
throw new Error("No groups defined");
|
throw new Error('No groups defined');
|
||||||
|
|
||||||
let groupsToDelete = [];
|
let groupsToDelete = [];
|
||||||
for (let groupIndex in parameters["groups"]) {
|
for (let groupIndex in parameters['groups']) {
|
||||||
groupName = parameters["groups"][groupIndex];
|
let groupName = parameters['groups'][groupIndex];
|
||||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
if (!this.monitor_groups.hasOwnProperty(groupName))
|
||||||
continue;
|
continue;
|
||||||
let group = this.monitor_groups[groupName];
|
let group = this.monitor_groups[groupName];
|
||||||
for (let itemIndex in group) {
|
for (let itemIndex in group)
|
||||||
this._removeItemFromBox(group[itemIndex]);
|
this._removeItemFromBox(group[itemIndex]);
|
||||||
}
|
|
||||||
groupsToDelete.push(groupName);
|
groupsToDelete.push(groupName);
|
||||||
}
|
}
|
||||||
for(let groupDeleteIndex in groupsToDelete)
|
for (let groupDeleteIndex in groupsToDelete) {
|
||||||
{
|
|
||||||
let groupName = groupsToDelete[groupDeleteIndex];
|
let groupName = groupsToDelete[groupDeleteIndex];
|
||||||
delete this.monitor_groups[groupName];
|
delete this.monitor_groups[groupName];
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
deleteAll: function() {
|
destructor() {
|
||||||
for (let groupIndex in this.monitor_groups) {
|
for (let groupIndex in this.monitor_groups) {
|
||||||
let group = this.monitor_groups[groupIndex];
|
let group = this.monitor_groups[groupIndex];
|
||||||
for (let itemIndex in group) {
|
for (let itemIndex in group)
|
||||||
this._removeItemFromBox(group[itemIndex]);
|
this._removeItemFromBox(group[itemIndex]);
|
||||||
}
|
}
|
||||||
|
this.monitor_groups = {};
|
||||||
|
this._dbusImpl.unexport();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.monitor_groups = {}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
class Extension {
|
class Extension {
|
||||||
constructor() {
|
enable() {
|
||||||
this.textDBusService = new GenericMonitorDBUS();
|
this.textDBusService = new GenericMonitorDBUS();
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
|
||||||
}
|
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
this.textDBusService.deleteAll();
|
this.textDBusService.destructor();
|
||||||
|
delete this.textDBusService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let extension = null;
|
let extension = new Extension();
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
extension = new Extension();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable() {
|
function enable() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user