diff --git a/extension.js b/extension.js
index a8e32fd..2598f2c 100644
--- a/extension.js
+++ b/extension.js
@@ -62,7 +62,7 @@ class SignalMgt {
this.group = group;
this.fullname = this.name + '@' + this.group;
this.dbus = dbus;
- this.menu = menu;
+ this.menu = menu;
this.signals = {}
this.nbClicks = 0;
@@ -78,8 +78,8 @@ class SignalMgt {
}
destructor() {
- for(let widgetIdx in this.signals)
- this.disconnectWidgetSignals(this.signals[widgetIdx]);
+ for(let widgetIdx in this.signals)
+ this.disconnectWidgetSignals(this.signals[widgetIdx]);
}
updateSignals(item) {
@@ -134,13 +134,13 @@ class SignalMgt {
_doClickCallback() {
let right = '';
let nbClicks = '';
-
+
if (this.button == 3)
right = 'Right';
if (this.nbClicks > 1)
nbClicks = 'Dbl';
- let signalName = 'on' + right + nbClicks + 'Click';
+ const signalName = 'on' + right + nbClicks + 'Click';
let action = 'signal';
switch(signalName) {
@@ -181,19 +181,19 @@ class SignalMgt {
}
_onScroll(actor, event) {
- let signalName = '';
- let direction = event.get_scroll_direction ();
+ let signalName = '';
+ const direction = event.get_scroll_direction ();
if (direction == Clutter.ScrollDirection.UP)
signalName = 'onScrollUp';
else if (direction == Clutter.ScrollDirection.DOWN)
signalName = 'onScrollDown';
- return this._manageEventAction(this.onScroll, signalName);
+ return this._manageEventAction(this.onScroll, signalName);
}
}
var MyPopupMenuItem = GObject.registerClass({
- GTypeName: "MyPopupMenuItem"
+ GTypeName: 'MyPopupMenuItem'
},
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
_init(widgets, params) {
@@ -211,7 +211,7 @@ class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
var MonitorWidget = GObject.registerClass({
- GTypeName: "MonitorWidget"
+ GTypeName: 'MonitorWidget'
},
class MonitorWidget extends PanelMenu.Button {
@@ -223,11 +223,11 @@ class MonitorWidget extends PanelMenu.Button {
this.fullname = this.name + '@' + this.group;
this.dbus = dbus;
this.signals = new SignalMgt(item, this.name, group, dbus, this.menu);
- this.popup_signals = {};
-
+ this.popup_signals = {};
+
if (item.hasOwnProperty('icon'))
{
- if (typeof(item['icon']) === "string")
+ if (typeof(item['icon']) === 'string')
this.icon = this._createIconOld(item);
else
this.icon = this._createIcon(item['icon']);
@@ -235,13 +235,12 @@ class MonitorWidget extends PanelMenu.Button {
this.signals.connectWidgetSignals(this.icon);
this.add_child(this.icon);
}
- }
- else
+ } else
this.icon = null;
if (item.hasOwnProperty('text'))
{
- if (typeof(item['text']) === "string")
+ if (typeof(item['text']) === 'string')
this.widget = this._createTextOld(item);
else
this.widget = this._createText(item['text']);
@@ -250,14 +249,13 @@ class MonitorWidget extends PanelMenu.Button {
this.signals.connectWidgetSignals(this.widget);
this.add_child(this.widget);
}
- }
- else
+ } else
this.widget = null;
if (item.hasOwnProperty('popup'))
this._createPopup(item['popup']);
- let box = hashGet(item, 'box', 'center');
+ const box = hashGet(item, 'box', 'center');
if (box === 'right' && position == -1)
position = 0;
@@ -267,6 +265,110 @@ class MonitorWidget extends PanelMenu.Button {
Main.panel.addToStatusArea(this.fullname, this, position, box);
}
+ 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) {
+ this.signals.disconnectWidgetSignals(prevIcon);
+ 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();
+ for(let widgetIdx in this.popup_signals)
+ this.signals.disconnectWidgetSignals(this.popup_signals[widgetIdx]);
+ this.menu.removeAll();
+ //delete this.menuItem;
+ }
+
+ const popup = this._createPopup(item['popup']);
+ if (popup !== null && menuOpen)
+ this.menu.open(true);
+ }
+
+ this.signals.updateSignals(item);
+ }
+
+ openPopup() {
+ this.menu.open(true);
+ }
+
+ closePopup() {
+ this.menu.close();
+ }
+
+ togglePopup() {
+ this.menu.toggle();
+ }
+
+ destroy() {
+ this.menu.close();
+ super.destroy();
+ }
+
_onStyleChanged() {
// Force these values to avoid big spaces between each widgets
this._minHPadding = 1;
@@ -283,29 +385,27 @@ class MonitorWidget extends PanelMenu.Button {
let widget = null;
let widgetDict = item['items'][itemIndex];
- let nestedItem = null;
+ let nestedItem = null;
if (widgetDict.hasOwnProperty('text')) {
- nestedItem = widgetDict['text'];
+ nestedItem = widgetDict['text'];
widget = this._createText(nestedItem);
- }
- else if (widgetDict.hasOwnProperty('picture')) {
- nestedItem = widgetDict['picture'];
+ } else if (widgetDict.hasOwnProperty('picture')) {
+ nestedItem = widgetDict['picture'];
widget = this._createPicture(nestedItem);
- }
- else {
- log('No known widget defined in popup');
- }
-
+ } else {
+ log('No known widget defined in popup');
+ }
+
if (nestedItem === null) {
- continue;
- }
-
+ continue;
+ }
+
widgets.push(widget);
- let name = hashGet(nestedItem, 'name', '');
- this.popup_signals[widget] = new SignalMgt(nestedItem, name,
- this.fullname, this.dbus,
- this.menu);
- this.popup_signals[widget].connectWidgetSignals(widget);
+ const name = hashGet(nestedItem, 'name', '');
+ this.popup_signals[widget] = new SignalMgt(nestedItem, name,
+ this.fullname, this.dbus,
+ this.menu);
+ this.popup_signals[widget].connectWidgetSignals(widget);
}
if (widgets.length > 0) {
@@ -328,18 +428,18 @@ class MonitorWidget extends PanelMenu.Button {
_createText(item) {
if (!item.hasOwnProperty('text')) {
- log("Text must have a 'text' value");
+ log('Text must have a \'text\' value');
return null;
}
- let style = hashGet(item, 'style', '');
+ const style = hashGet(item, 'style', '');
this.textProperties = item;
if (item['text'] === '') {
return null;
} else {
- let widget = new St.Button({ label: item['text'] });
+ const widget = new St.Button({ label: item['text'] });
widget.set_style(style);
return widget;
@@ -356,11 +456,11 @@ class MonitorWidget extends PanelMenu.Button {
_createIcon(item) {
if (!item.hasOwnProperty('path')) {
- log("Icon must have a 'path' value");
+ log('Icon must have a \'path\' value');
return null;
}
- let style = hashGet(item, 'style', '');
+ const style = hashGet(item, 'style', '');
this.iconProperties = item;
@@ -377,152 +477,48 @@ class MonitorWidget extends PanelMenu.Button {
_createPicture(item) {
if (!item.hasOwnProperty('path')) {
- log("Picture must have a 'path' value");
+ log('Picture must have a \'path\' value');
return null;
}
let width = hashGet(item, 'width', -1);
let height = hashGet(item, 'height', -1);
- if (typeof(width) === "string")
+ if (typeof(width) === 'string')
width = parseInt(width, 10);
- if (typeof(height) === "string")
+ if (typeof(height) === 'string')
height = parseInt(height, 10);
- let img = new Clutter.Image();
- let initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
+ const img = new Clutter.Image();
+ const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
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());
- let picture = new Clutter.Actor();
+ const picture = new Clutter.Actor();
picture.set_content(img);
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
(height != -1)?height:initialPixbuf.get_height());
// Pack it in a box to avoid picture resize
- let box = new St.BoxLayout({});
+ const box = new St.BoxLayout({});
box.add_child(picture);
return box;
}
-
- update(item) {
- let prevWidget = this.widget;
- let 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 {
- let 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 {
- let 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) {
- this.signals.disconnectWidgetSignals(prevIcon);
- 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'))
- {
- let menuOpen = this.menu.isOpen;
- if (this.menuItem) {
- if (menuOpen)
- this.menu.close();
- for(let widgetIdx in this.popup_signals)
- this.signals.disconnectWidgetSignals(this.popup_signals[widgetIdx]);
- this.menu.removeAll();
- //delete this.menuItem;
- }
-
- let popup = this._createPopup(item['popup']);
- if (popup !== null && menuOpen)
- this.menu.open(true);
- }
-
- this.signals.updateSignals(item);
- }
-
- openPopup() {
- this.menu.open(true);
- }
-
- closePopup() {
- this.menu.close();
- }
-
- togglePopup() {
- this.menu.toggle();
- }
-
- destroy() {
- this.menu.close();
- super.destroy();
- }
});
// 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) {
- let extension = imports.misc.extensionUtils.getCurrentExtension();
+ const extension = imports.misc.extensionUtils.getCurrentExtension();
- let interfacesDir = extension.dir.get_child('.');
+ const interfacesDir = extension.dir.get_child('.');
- let file = interfacesDir.get_child(filename);
+ const file = interfacesDir.get_child(filename);
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
@@ -534,7 +530,7 @@ function loadInterfaceXml(filename) {
// will spit out a TypeError soon).
if (contents instanceof Uint8Array)
contents = imports.byteArray.toString(contents);
- let res = `${contents}`;
+ const res = `${contents}`;
return res;
} else {
throw new Error(`Generic monitor: Could not load file: ${filename}`);
@@ -567,7 +563,7 @@ class GenericMonitorDBUS {
}
for (let itemIndex in parameters['items']) {
- let item = parameters['items'][itemIndex];
+ const item = parameters['items'][itemIndex];
if (!item.hasOwnProperty('name')) {
log('No name defined for item');
return false;
@@ -579,7 +575,7 @@ class GenericMonitorDBUS {
_getItemFromGroup(group, name) {
for (let groupItemIndex in group) {
- let groupItem = group[groupItemIndex];
+ const groupItem = group[groupItemIndex];
if (groupItem.name === name)
return groupItem;
}
@@ -588,7 +584,7 @@ class GenericMonitorDBUS {
}
_getItemFromFullName(fullname) {
- let splitName = fullname.split('@');
+ const splitName = fullname.split('@');
if (splitName.length !== 2) {
log(`Invalid name ${fullname}`);
return null;
@@ -611,11 +607,11 @@ class GenericMonitorDBUS {
}
notify(str) {
- let parameters = JSON.parse(str);
+ const parameters = JSON.parse(str);
if (!this._checkParameters(parameters))
return;
- let groupName = parameters['group'];
+ const groupName = parameters['group'];
let group;
if (!this.monitor_groups.hasOwnProperty(groupName)) {
group = [];
@@ -625,7 +621,7 @@ class GenericMonitorDBUS {
}
for (let itemIndex in parameters['items']) {
- let item = parameters['items'][itemIndex];
+ const item = parameters['items'][itemIndex];
let monitorWidget = this._getItemFromGroup(group, item['name']);
// New widget
@@ -633,8 +629,8 @@ class GenericMonitorDBUS {
let position = group.length - 1;
// Find real position
if (position != -1) {
- let lastWidget = group[position].container;
- let childrens = lastWidget.get_parent().get_children();
+ const lastWidget = group[position].container;
+ const childrens = lastWidget.get_parent().get_children();
for(;position < childrens.length; position++)
{
if (childrens[position] == lastWidget) {
@@ -664,7 +660,7 @@ class GenericMonitorDBUS {
}
deleteItems(str) {
- let parameters = JSON.parse(str);
+ const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('items')) {
log('No items defined');
@@ -673,7 +669,7 @@ class GenericMonitorDBUS {
for (let itemIndex in parameters['items']) {
let itemName = parameters['items'][itemIndex];
- let splitName = itemName.split('@');
+ const splitName = itemName.split('@');
if (splitName.length !== 2) {
log(`Invalid name ${itemName}`);
return false;
@@ -691,7 +687,7 @@ class GenericMonitorDBUS {
}
deleteGroups(str) {
- let parameters = JSON.parse(str);
+ const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('groups')) {
log('No groups defined');
@@ -700,29 +696,29 @@ class GenericMonitorDBUS {
let groupsToDelete = [];
for (let groupIndex in parameters['groups']) {
- let groupName = parameters['groups'][groupIndex];
+ const groupName = parameters['groups'][groupIndex];
if (!this.monitor_groups.hasOwnProperty(groupName))
continue;
- let group = this.monitor_groups[groupName];
+ const group = this.monitor_groups[groupName];
for (let itemIndex in group)
group[itemIndex].destroy();
groupsToDelete.push(groupName);
}
for (let groupDeleteIndex in groupsToDelete) {
- let groupName = groupsToDelete[groupDeleteIndex];
+ const groupName = groupsToDelete[groupDeleteIndex];
delete this.monitor_groups[groupName];
}
}
_popupFunction(str) {
- let parameters = JSON.parse(str);
+ const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('item')) {
log('No item defined');
return false;
}
- let monitorWidget = this._getItemFromFullName(parameters['item']);
+ const monitorWidget = this._getItemFromFullName(parameters['item']);
if (monitorWidget !== null)
return monitorWidget;
else
@@ -732,19 +728,19 @@ class GenericMonitorDBUS {
}
openPopup(str) {
- let monitorWidget = this._popupFunction(str)
+ const monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.openPopup();
}
closePopup(str) {
- let monitorWidget = this._popupFunction(str)
+ const monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.closePopup();
}
togglePopup(str) {
- let monitorWidget = this._popupFunction(str)
+ const monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.togglePopup();
}
@@ -752,7 +748,7 @@ class GenericMonitorDBUS {
destructor() {
this._dbusImpl.emit_signal('onDeactivate', null);
for (let groupIndex in this.monitor_groups) {
- let group = this.monitor_groups[groupIndex];
+ const group = this.monitor_groups[groupIndex];
for (let itemIndex in group)
group[itemIndex].destroy();
}
@@ -772,7 +768,7 @@ class Extension {
}
}
-let extension = new Extension();
+const extension = new Extension();
function init() {
}