2021-11-09 15:26:18 +01:00
|
|
|
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
/*
|
|
|
|
Monito Gnome-Shell extension
|
|
|
|
Copyright (C) 2021 Benjamin Drieu
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
2021-11-09 15:21:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* exported init */
|
|
|
|
|
|
|
|
const GETTEXT_DOMAIN = 'monito';
|
|
|
|
|
|
|
|
let _httpSession;
|
|
|
|
let _status;
|
|
|
|
let _ok_text;
|
|
|
|
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2021-11-17 21:01:51 +01:00
|
|
|
const Lang = imports.lang;
|
2021-11-09 15:21:21 +01:00
|
|
|
const Main = imports.ui.main;
|
2021-11-17 21:01:51 +01:00
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Me = ExtensionUtils.getCurrentExtension();
|
2021-11-09 15:21:21 +01:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2021-11-17 21:01:51 +01:00
|
|
|
|
|
|
|
const Gettext = imports.gettext.domain(GETTEXT_DOMAIN);
|
|
|
|
const _ = Gettext.gettext;
|
2021-11-09 15:21:21 +01:00
|
|
|
|
2021-11-12 12:11:20 +01:00
|
|
|
const { GObject, St, Clutter, Gio } = imports.gi;
|
2021-11-09 15:21:21 +01:00
|
|
|
|
2021-11-17 17:15:21 +01:00
|
|
|
const SETTINGS_SCHEMA = "org.gnome.shell.extensions.monito";
|
|
|
|
const SETTINGS_SCHEMA_ACCOUNT = "org.gnome.shell.extensions.monito.account";
|
|
|
|
const SETTINGS_SCHEMA_ACCOUNT_PATH = "/org/gnome/shell/extensions/monito/account";
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
const Convenience = Me.imports.convenience;
|
2021-11-19 17:46:36 +01:00
|
|
|
const GenericServer = Me.imports.servers.genericserver.GenericServer;
|
2021-11-12 12:11:20 +01:00
|
|
|
const Icinga = Me.imports.servers.icinga.Icinga;
|
|
|
|
const Icinga2 = Me.imports.servers.icinga2.Icinga2;
|
2021-11-17 21:01:51 +01:00
|
|
|
const Preferences = Me.imports.prefs;
|
2021-11-12 12:11:20 +01:00
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
let settings = Convenience.getSettings(SETTINGS_SCHEMA);
|
2021-11-17 17:15:21 +01:00
|
|
|
let account_settings = [ ];
|
2021-11-09 15:21:21 +01:00
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
const column_definitions = {
|
|
|
|
status: { label: _('Status'), width: 50, expand: false, },
|
|
|
|
host_name: { label: _('Host name'), width: 300, expand: false, },
|
|
|
|
service_display_name: { label: _('Service'), width: 300, expand: false, },
|
2021-11-19 23:07:45 +01:00
|
|
|
last_check: { label: _('Last check'), width: 200, expand: false, type: 'date' },
|
2021-11-19 17:46:36 +01:00
|
|
|
attempts: { label: _('Attempts'), width: 50, expand: false, },
|
|
|
|
status_information: { label: _('Information'), width: 600, expand: true, },
|
2021-11-19 22:16:45 +01:00
|
|
|
actions: { label: 'Actions', width: 100, expand: true, special: 'actions' },
|
2021-11-19 17:46:36 +01:00
|
|
|
};
|
2021-11-19 11:21:20 +01:00
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
|
|
|
|
const Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.Button {
|
2021-11-18 23:08:49 +01:00
|
|
|
_init(server) {
|
2021-11-09 15:21:21 +01:00
|
|
|
super._init(0.0, _('Monito Checker'));
|
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
this.server = server;
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
this.initStatus ( );
|
|
|
|
|
2021-11-10 17:21:03 +01:00
|
|
|
this.namesBoxes = { };
|
|
|
|
this.warningBoxes = { };
|
|
|
|
this.criticalBoxes = { };
|
|
|
|
this.unknownBoxes = { };
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
this.sortIcons = { };
|
|
|
|
account_settings [ server ] = Preferences.getAccountSettings ( this.server );
|
|
|
|
this.account_settings = account_settings [ server ];
|
|
|
|
|
|
|
|
let type = this.account_settings.get_string ( "type" );
|
|
|
|
if ( type == 'Icinga' )
|
|
|
|
this.serverlogic = new Icinga ( this.server );
|
|
|
|
else if ( type == 'Icinga2' )
|
|
|
|
this.serverlogic = new Icinga2 ( this.server );
|
|
|
|
|
2021-11-17 17:15:21 +01:00
|
|
|
this.initUI ( );
|
|
|
|
}
|
|
|
|
|
|
|
|
initUI ( ) {
|
|
|
|
let box = new St.BoxLayout ( { } );
|
|
|
|
this.add_child(box);
|
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
monitoLog ( '> Server ' + this.server );
|
|
|
|
|
|
|
|
let serverBox = new St.BoxLayout ( { style_class: 'monito-serverbox' } );
|
|
|
|
box.add_child(serverBox);
|
|
|
|
|
|
|
|
let name_box = new St.BoxLayout( { style_class: 'monito-namebox' } );
|
2021-11-19 17:46:36 +01:00
|
|
|
this.namesBoxes [ this.server ] = new St.Label ( { text: this.account_settings.get_string ( 'name' ) } );
|
2021-11-18 23:08:49 +01:00
|
|
|
name_box.add_child ( this.namesBoxes [ this.server ] );
|
|
|
|
serverBox.add_child(name_box);
|
2021-11-19 17:46:36 +01:00
|
|
|
this.account_settings.bind ( 'name', this.namesBoxes [ this.server ], 'text', Gio.SettingsBindFlags.GET );
|
2021-11-18 23:08:49 +01:00
|
|
|
|
|
|
|
this.namesBoxes [ this.server ].connect ( 'button-press-event', Lang.bind ( this, function ( ) { this.setMenu ( this.menu ); } ) );
|
|
|
|
|
|
|
|
|
|
|
|
let warning_box = new St.BoxLayout({ style_class: 'monito-warning-box monito-box' });
|
2021-11-19 17:46:36 +01:00
|
|
|
warning_box.set_style ( 'background-color: ' + this.account_settings.get_string ( 'warning-color' ) );
|
|
|
|
this.account_settings.connect("changed::warning-color", Lang.bind ( { widget: warning_box }, setColor ) );
|
2021-11-18 23:08:49 +01:00
|
|
|
|
|
|
|
this.warningBoxes [ this.server ] = new St.Label({ text: String(_status['WARNING']) })
|
|
|
|
warning_box.add_child ( this.warningBoxes [ this.server ] );
|
|
|
|
serverBox.add_child(warning_box);
|
|
|
|
|
|
|
|
let critical_box = new St.BoxLayout({ style_class: 'monito-critical-box monito-box' });
|
2021-11-19 17:46:36 +01:00
|
|
|
critical_box.set_style ( 'background-color: ' + this.account_settings.get_string ( 'critical-color' ) );
|
|
|
|
this.account_settings.connect("changed::critical-color", Lang.bind ( { widget: critical_box }, setColor ) );
|
2021-11-18 23:08:49 +01:00
|
|
|
|
|
|
|
this.criticalBoxes [ this.server ] = new St.Label({ text: String(_status['CRITICAL']) })
|
|
|
|
critical_box.add_child ( this.criticalBoxes [ this.server ] );
|
|
|
|
serverBox.add_child(critical_box);
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
box.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
this.menu_new = new PopupMenu.PopupMenu(this, Clutter.ActorAlign.START, St.Side.TOP, 0);
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
// Menu
|
|
|
|
this._buttonMenu = new PopupMenu.PopupBaseMenuItem({
|
|
|
|
reactive: false,
|
|
|
|
style_class: 'monito-menu-button-container',
|
|
|
|
});
|
|
|
|
this.menu.addMenuItem(this._buttonMenu);
|
|
|
|
|
2021-11-10 17:21:03 +01:00
|
|
|
let _path = Me.path + '/img/monito.png';
|
|
|
|
let _icon = new St.Icon({
|
|
|
|
gicon: Gio.icon_new_for_string(_path),
|
|
|
|
});
|
|
|
|
let _iconBin = new St.Bin();
|
|
|
|
_iconBin.child = _icon;
|
|
|
|
this._buttonMenu.actor.add_actor(_iconBin);
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
this._mainLabel = new St.Label ( { style_class: 'monito-title', text: 'Monito Checker', x_expand: true } );
|
2021-11-09 15:21:21 +01:00
|
|
|
this._buttonMenu.actor.add_actor(this._mainLabel);
|
|
|
|
|
|
|
|
this._prefsButton = this._createButton ( 'preferences-system-symbolic', 'Preferences', this._onPreferencesActivate );
|
|
|
|
this._buttonMenu.actor.add_child (this._prefsButton);
|
|
|
|
|
2021-11-19 23:07:45 +01:00
|
|
|
this._updateButton = this._createButton ( 'emblem-synchronizing-symbolic', 'Reload', this.updateStatus ); // Implement this
|
2021-11-19 22:16:45 +01:00
|
|
|
this._buttonMenu.actor.add_child (this._updateButton );
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
this._reloadButton = this._createButton ( 'view-refresh-symbolic', 'Reload', this.updateStatus );
|
|
|
|
this._buttonMenu.actor.add_child (this._reloadButton );
|
|
|
|
|
|
|
|
let _intermediate = new PopupMenu.PopupBaseMenuItem ( {
|
|
|
|
style_class: 'monito-services',
|
|
|
|
reactive: false
|
|
|
|
});
|
|
|
|
|
|
|
|
this.menu.addMenuItem(_intermediate);
|
|
|
|
this._box = new St.BoxLayout({
|
|
|
|
style_class: 'monito-services',
|
|
|
|
vertical: true,
|
|
|
|
x_expand: true
|
|
|
|
});
|
|
|
|
_intermediate.actor.add_actor(this._box);
|
2021-11-18 23:08:49 +01:00
|
|
|
this.menu_orig = this.menu;
|
2021-11-09 15:21:21 +01:00
|
|
|
|
|
|
|
this.updateStatus ( );
|
2021-11-17 14:44:04 +01:00
|
|
|
this.setupTimeout ( );
|
|
|
|
}
|
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
cancelTimeout ( )
|
|
|
|
{
|
|
|
|
if (this.timeout)
|
|
|
|
Mainloop.source_remove(this.timeout);
|
|
|
|
}
|
|
|
|
|
2021-11-17 14:44:04 +01:00
|
|
|
setupTimeout ( )
|
|
|
|
{
|
2021-11-17 17:15:21 +01:00
|
|
|
monitoLog ( 'Setting up timeout of ' + settings.get_int ( "poll-delay" ) + ' secs' );
|
2021-11-18 23:08:49 +01:00
|
|
|
this.cancelTimeout ( );
|
2021-11-17 14:44:04 +01:00
|
|
|
this.timeout = Mainloop.timeout_add ( settings.get_int ( "poll-delay" ) * 1000, Lang.bind(this, this.updateStatus ) );
|
2021-11-09 15:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initStatus ( ) {
|
|
|
|
_status = { 'OK': 0,
|
|
|
|
'WARNING': 0,
|
|
|
|
'CRITICAL': 0,
|
|
|
|
'UNKNOWN': 0 };
|
|
|
|
}
|
|
|
|
|
2021-11-17 14:44:04 +01:00
|
|
|
updateStatus ( )
|
|
|
|
{
|
2021-11-19 17:46:36 +01:00
|
|
|
if ( ! this.serverlogic.refresh ( this ) )
|
2021-11-10 17:21:03 +01:00
|
|
|
{
|
2021-11-19 17:46:36 +01:00
|
|
|
this.warningBoxes[this.server].set_text ( '…' );
|
|
|
|
this.criticalBoxes[this.server].set_text ( '…' );
|
2021-11-10 17:21:03 +01:00
|
|
|
}
|
2021-11-17 14:44:04 +01:00
|
|
|
|
|
|
|
this.setupTimeout ( );
|
2021-11-09 15:21:21 +01:00
|
|
|
}
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
createHeaderBin ( colName ) {
|
|
|
|
let col = column_definitions [ colName ];
|
|
|
|
|
|
|
|
let _box = new St.BoxLayout ( { vertical: false,
|
|
|
|
x_expand: true } );
|
|
|
|
_box.add_child ( new St.Label ( { text: col.label,
|
|
|
|
x_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.START } ) );
|
|
|
|
|
|
|
|
let _iconBin = new St.Bin ( { x_align: Clutter.ActorAlign.END });
|
|
|
|
_box.add_child ( _iconBin );
|
|
|
|
|
|
|
|
let _iconName = '';
|
|
|
|
let _sortOrder = Preferences.getSortOrder ( this.server );
|
|
|
|
if ( _sortOrder.indexOf ( colName + '+' ) >= 0 )
|
|
|
|
_iconName = 'view-sort-descending-symbolic';
|
|
|
|
else if ( _sortOrder.indexOf ( colName + '-' ) >= 0 )
|
|
|
|
_iconName = 'view-sort-ascending-symbolic';
|
|
|
|
|
|
|
|
this.sortIcons [ colName ] = new St.Icon ( {
|
|
|
|
style_class: 'monito-button-icon',
|
|
|
|
icon_name: _iconName,
|
|
|
|
icon_size: 16,
|
|
|
|
} );
|
|
|
|
_iconBin.child = this.sortIcons [ colName ];
|
|
|
|
|
|
|
|
let _button = new St.Button ( {
|
2021-11-19 11:21:20 +01:00
|
|
|
x_align: Clutter.ActorAlign.START,
|
2021-11-17 20:16:53 +01:00
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
2021-11-19 11:21:20 +01:00
|
|
|
width: col.width,
|
2021-11-17 20:16:53 +01:00
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
2021-11-19 17:46:36 +01:00
|
|
|
accessible_name: col.label,
|
2021-11-17 20:16:53 +01:00
|
|
|
style_class: 'button',
|
2021-11-19 17:46:36 +01:00
|
|
|
} );
|
|
|
|
_button.column = colName;
|
|
|
|
|
|
|
|
_button.add_actor ( _box );
|
|
|
|
_button.connect ( 'clicked', Lang.bind ( this, this._onSortColumnClick ) );
|
|
|
|
|
|
|
|
let _bin = new St.Bin({
|
|
|
|
style_class: 'monito-service',
|
|
|
|
width: col.width,
|
|
|
|
x_expand: col.expand,
|
|
|
|
child: _button,
|
2021-11-17 20:16:53 +01:00
|
|
|
});
|
2021-11-19 17:46:36 +01:00
|
|
|
|
2021-11-17 20:16:53 +01:00
|
|
|
return _bin;
|
|
|
|
}
|
|
|
|
|
2021-11-10 17:21:03 +01:00
|
|
|
createBin ( status, text, col ) {
|
2021-11-19 22:16:45 +01:00
|
|
|
let _child;
|
|
|
|
|
|
|
|
if ( ! col [ 'special' ] )
|
2021-11-19 23:07:45 +01:00
|
|
|
_child = new St.Label({ style_class: 'monito-label', text: text, });
|
2021-11-19 22:16:45 +01:00
|
|
|
else if ( col.special == 'actions' )
|
|
|
|
{
|
|
|
|
_child = new St.BoxLayout ( { x_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.FILL,
|
|
|
|
vertical: false } );
|
|
|
|
let _button = new St.Button ( {
|
2021-11-19 23:07:45 +01:00
|
|
|
style_class: 'button small-button',
|
|
|
|
x_expand: true,
|
2021-11-19 22:16:45 +01:00
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
can_focus: true,
|
|
|
|
} );
|
|
|
|
_button.child = new St.Icon ( {
|
|
|
|
icon_name: 'view-refresh-symbolic',
|
|
|
|
icon_size: 16,
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
} );
|
|
|
|
_child.add_child ( _button );
|
|
|
|
}
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
let _bin = new St.Bin({
|
|
|
|
style_class: 'monito-service-' + status,
|
2021-11-17 20:16:53 +01:00
|
|
|
track_hover: true,
|
2021-11-19 11:21:20 +01:00
|
|
|
width: col.width,
|
|
|
|
x_expand: col.expand,
|
2021-11-19 22:16:45 +01:00
|
|
|
child: _child,
|
2021-11-09 15:21:21 +01:00
|
|
|
});
|
|
|
|
return _bin;
|
|
|
|
}
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
refreshUI ( ) {
|
|
|
|
this.initStatus ( );
|
2021-11-12 12:11:20 +01:00
|
|
|
|
|
|
|
this._box.remove_all_children();
|
2021-11-18 23:16:59 +01:00
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
if ( this.serverlogic.error )
|
2021-11-18 23:16:59 +01:00
|
|
|
{
|
2021-11-19 17:46:36 +01:00
|
|
|
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: this.serverlogic.error } ) );
|
2021-11-18 23:16:59 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-11-12 12:11:20 +01:00
|
|
|
|
2021-11-17 20:16:53 +01:00
|
|
|
let headerBox = new St.BoxLayout({
|
|
|
|
hover: true,
|
|
|
|
x_expand: true
|
|
|
|
});
|
|
|
|
this._box.add_child(headerBox);
|
2021-11-19 17:46:36 +01:00
|
|
|
|
|
|
|
let _columns = Preferences.getColumns ( this.server );
|
|
|
|
for ( let _col of _columns )
|
|
|
|
headerBox.add_child ( this.createHeaderBin ( _col ) );
|
2021-11-19 22:16:45 +01:00
|
|
|
headerBox.add_child ( this.createHeaderBin ( 'actions' ) );
|
2021-11-17 20:16:53 +01:00
|
|
|
|
2021-11-19 11:21:20 +01:00
|
|
|
let scrollBox = new St.ScrollView ( { hscrollbar_policy: St.PolicyType.NEVER,
|
|
|
|
enable_mouse_scrolling: true, } );
|
|
|
|
this._box.add_child(scrollBox);
|
|
|
|
|
|
|
|
let tableBox = new St.BoxLayout({
|
|
|
|
hover: true,
|
|
|
|
vertical: true,
|
|
|
|
x_expand: true,
|
|
|
|
});
|
|
|
|
scrollBox.add_actor(tableBox);
|
2021-11-17 20:16:53 +01:00
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
for ( let entry of this.serverlogic.getProcessedStatus ( ) )
|
2021-11-12 12:11:20 +01:00
|
|
|
{
|
2021-11-19 17:46:36 +01:00
|
|
|
_status [ entry.status ] ++;
|
|
|
|
if ( entry.status != 'OK' )
|
2021-11-12 12:11:20 +01:00
|
|
|
{
|
|
|
|
let infoBox = new St.BoxLayout({
|
2021-11-19 17:46:36 +01:00
|
|
|
style_class: 'monito-service-line monito-service-line-' + entry.status,
|
2021-11-19 11:21:20 +01:00
|
|
|
track_hover: true,
|
|
|
|
x_expand: true,
|
2021-11-12 12:11:20 +01:00
|
|
|
});
|
2021-11-19 11:21:20 +01:00
|
|
|
tableBox.add_child(infoBox);
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
let _columns = Preferences.getColumns ( this.server );
|
|
|
|
for ( let _col of _columns )
|
2021-11-19 11:21:20 +01:00
|
|
|
{
|
2021-11-19 17:46:36 +01:00
|
|
|
infoBox.add_child ( this.createBin ( entry.status, entry [ _col ], column_definitions [ _col ] ) );
|
2021-11-19 11:21:20 +01:00
|
|
|
}
|
2021-11-19 22:16:45 +01:00
|
|
|
infoBox.add_child ( this.createBin ( entry.status, '', column_definitions [ 'actions' ] ) );
|
2021-11-12 12:11:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
this.warningBoxes[this.serverlogic.server].set_text ( String(_status.WARNING) );
|
|
|
|
this.criticalBoxes[this.serverlogic.server].set_text ( String(_status.CRITICAL) );
|
2021-11-18 23:08:49 +01:00
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-10 17:21:03 +01:00
|
|
|
_onPreferencesActivate ( ) {
|
2021-11-09 15:21:21 +01:00
|
|
|
this.menu.actor.hide();
|
|
|
|
if (typeof ExtensionUtils.openPrefs === 'function') {
|
|
|
|
ExtensionUtils.openPrefs();
|
|
|
|
} else {
|
|
|
|
Util.spawn([
|
|
|
|
"gnome-shell-extension-prefs",
|
|
|
|
Me.uuid
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-19 17:46:36 +01:00
|
|
|
_onSortColumnClick ( button ) {
|
|
|
|
monitoLog ( 'column >> ' + button.column );
|
|
|
|
|
|
|
|
let _sortOrder = Preferences.getSortOrder ( this.server );
|
|
|
|
let _columns = Preferences.getColumns ( this.server );
|
|
|
|
|
|
|
|
let _indexPlus = _sortOrder.indexOf ( button.column + '+' );
|
|
|
|
let _indexMinus = _sortOrder.indexOf ( button.column + '-' );
|
|
|
|
|
|
|
|
if ( _indexPlus >= 0 )
|
|
|
|
_sortOrder [ _indexPlus ] = button.column + '-';
|
|
|
|
else if ( _indexMinus >= 0 )
|
|
|
|
_sortOrder.splice ( _indexMinus, 1 );
|
|
|
|
else
|
|
|
|
_sortOrder.unshift ( button.column + '+' );
|
|
|
|
|
|
|
|
Preferences.setSortOrder ( this.server, _sortOrder );
|
|
|
|
this.refreshUI ( );
|
|
|
|
}
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
_createButton ( icon, text, callback ) {
|
|
|
|
let button = new St.Button({
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
|
|
|
accessible_name: text,
|
2021-11-19 23:07:45 +01:00
|
|
|
style_class: 'button big-button',
|
2021-11-09 15:21:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
button.child = new St.Icon({
|
|
|
|
style_class: 'monito-button-icon',
|
|
|
|
icon_name: icon,
|
|
|
|
icon_size: 24,
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
});
|
|
|
|
|
|
|
|
button.connect('clicked', Lang.bind(this, callback ) );
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
class Extension {
|
|
|
|
constructor(uuid) {
|
|
|
|
this._uuid = uuid;
|
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
settings.connect("changed::servers", Lang.bind ( this, function(stgs, key) {
|
|
|
|
this.disable ( );
|
|
|
|
this.enable ( );
|
|
|
|
} ) );
|
|
|
|
|
2021-11-09 15:21:21 +01:00
|
|
|
ExtensionUtils.initTranslations(GETTEXT_DOMAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
enable() {
|
2021-11-18 23:08:49 +01:00
|
|
|
this._indicators = { };
|
2021-11-10 17:21:03 +01:00
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
for ( let _server of Preferences.getServersList() )
|
|
|
|
{
|
|
|
|
this._indicators [ _server ] = new Indicator(_server);
|
|
|
|
Main.panel.addToStatusArea ( '%s-%d'.format ( this._uuid, _server), this._indicators [ _server ] );
|
|
|
|
}
|
2021-11-09 15:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
2021-11-18 23:08:49 +01:00
|
|
|
for ( var i of Object.keys(this._indicators) )
|
|
|
|
{
|
|
|
|
this._indicators[i].cancelTimeout();
|
|
|
|
this._indicators[i].destroy();
|
|
|
|
}
|
2021-11-09 15:21:21 +01:00
|
|
|
|
2021-11-18 23:08:49 +01:00
|
|
|
this._indicators = { };
|
2021-11-09 15:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(meta) {
|
|
|
|
return new Extension(meta.uuid);
|
|
|
|
}
|
2021-11-17 17:15:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
function monitoLog ( msg )
|
|
|
|
{
|
|
|
|
log ( 'Monito: ' + msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setColor (stgs, key) {
|
|
|
|
monitoLog ( stgs.get_string(key) );
|
|
|
|
this.widget.set_style ( 'background-color: ' + stgs.get_string(key) );
|
|
|
|
}
|