After linter pass

This commit is contained in:
Grégory Soutadé 2021-01-29 09:15:40 +01:00
parent b85ff4a782
commit 83609b58ab

View File

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