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

@ -140,7 +140,7 @@ class SignalMgt {
if (this.nbClicks > 1)
nbClicks = 'Dbl';
let signalName = 'on' + right + nbClicks + 'Click';
const signalName = 'on' + right + nbClicks + 'Click';
let action = 'signal';
switch(signalName) {
@ -182,7 +182,7 @@ class SignalMgt {
_onScroll(actor, event) {
let signalName = '';
let direction = event.get_scroll_direction ();
const direction = event.get_scroll_direction ();
if (direction == Clutter.ScrollDirection.UP)
signalName = 'onScrollUp';
else if (direction == Clutter.ScrollDirection.DOWN)
@ -193,7 +193,7 @@ class SignalMgt {
}
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 {
@ -227,7 +227,7 @@ class MonitorWidget extends PanelMenu.Button {
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;
@ -287,12 +389,10 @@ class MonitorWidget extends PanelMenu.Button {
if (widgetDict.hasOwnProperty('text')) {
nestedItem = widgetDict['text'];
widget = this._createText(nestedItem);
}
else if (widgetDict.hasOwnProperty('picture')) {
} else if (widgetDict.hasOwnProperty('picture')) {
nestedItem = widgetDict['picture'];
widget = this._createPicture(nestedItem);
}
else {
} else {
log('No known widget defined in popup');
}
@ -301,7 +401,7 @@ class MonitorWidget extends PanelMenu.Button {
}
widgets.push(widget);
let name = hashGet(nestedItem, 'name', '');
const name = hashGet(nestedItem, 'name', '');
this.popup_signals[widget] = new SignalMgt(nestedItem, name,
this.fullname, this.dbus,
this.menu);
@ -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 = `<node>${contents}</node>`;
const res = `<node>${contents}</node>`;
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() {
}