Skip to content

Commit

Permalink
extension: Drop gtop and nm dependency checks and pop-up dialog
Browse files Browse the repository at this point in the history
Our system dependency pop-up dialog (smDialog) is currently using some
private APIs which are being removed in Gnome Shell 46 [1]. Rather than
fixing this let's just tie it up and throw it overboard. This is a
reasonable course of action because:

  (1) It's not clear which replacement APIs we should be moving to. We
      could figure this out with a bit of research and testing, but it
      may not be worth it because:

  (2) The smDialog dependency checks have actually been hard-coded out
      since the port to Gnome Shell 45 [2] (since the old dependency
      check method relied on a try/catch of the library imports, which
      isn't supported in es6).

So even if we figure out a new API for copying props to the child, we'd
still never be using any of that new code anyway since we're hard-coding an
assumption of the dependencies being present.

Ultimately we *should* fix this for the best possible user experience, but
in the interest of keeping things moving with Gnome Shell updates we'll
defer that work to the back burner (#69).

[1] #64 (comment)
[2] (f838b97: "extension: Update for Gnome Shell 45")
  • Loading branch information
mgalgs committed Mar 25, 2024
1 parent 694f159 commit b3630b1
Showing 1 changed file with 117 additions and 192 deletions.
309 changes: 117 additions & 192 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const UPower = UPowerGlib;
// Copied as of https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/5fa08fe53376f5dca755360bd005a4a51ca78917/js/ui/panel.js#L45
const PANEL_ICON_SIZE = 16;

let smDepsGtop = true;
let smDepsNM = true;

// stale network shares will cause the shell to freeze, enable this with caution
const ENABLE_NETWORK_DISK_USAGE = false;

Expand Down Expand Up @@ -252,59 +249,6 @@ const smStyleManager = class SystemMonitor_smStyleManager {
}
}

const smDialog = GObject.registerClass(
class SystemMonitor_smDialog extends ModalDialog.ModalDialog {
constructor(extension) {
this.extension = extension;

const MESSAGE = _('Dependencies Missing\n\
Please install: \n\
gnome-system-monitor and libgtop, clutter and Network Manager gir bindings \n\
\t on Debian and Ubuntu: gir1.2-gtop-2.0, gir1.2-nm-1.0, gir1.2-clutter-1.0, gnome-system-monitor \n\
\t on Fedora: libgtop2-devel, NetworkManager-libnm-devel, gnome-system-monitor \n\
\t on Arch: libgtop, networkmanager, gnome-system-monitor\n\
\t on openSUSE: typelib-1_0-GTop-2_0, typelib-1_0-NetworkManager-1_0, gnome-system-monitor \n\
\t on Mageia 64-bit: lib64gtop-gir2.0, lib64nm-gir1.0, lib64clutter-gir1.0, gnome-system-monitor\n');

super({styleClass: 'prompt-dialog'});
let mainContentBox = new St.BoxLayout({style_class: 'prompt-dialog-main-layout',
vertical: false});
this.contentLayout.add_child(mainContentBox,
{x_fill: true,
y_fill: true});

let messageBox = new St.BoxLayout({style_class: 'prompt-dialog-message-layout',
vertical: true});
mainContentBox.add_child(messageBox,
{y_align: St.Align.START});

this._subjectLabel = new St.Label({style_class: 'prompt-dialog-headline',
text: _('System Monitor Extension')});

messageBox.add_child(this._subjectLabel,
{y_fill: false,
y_align: St.Align.START});

this._descriptionLabel = new St.Label({style_class: 'prompt-dialog-description',
text: MESSAGE});

messageBox.add_child(this._descriptionLabel,
{y_fill: true,
y_align: St.Align.START});


this.setButtons([
{
label: _('Cancel'),
action: () => {
this.close();
},
key: Clutter.Escape
}
]);
}
});

const Chart = class SystemMonitor_Chart {
constructor(extension, width, height, parent) {
this.extension = extension;
Expand Down Expand Up @@ -2384,152 +2328,133 @@ export default class SystemMonitorExtension extends Extension {

this._Background = color_from_string(this._Schema.get_string('background'));

this.dialogTimeout = null;
this.menuTimeout = null;

if (!(smDepsGtop && smDepsNM)) {
this.__sm = {
smdialog: new smDialog()
};

this.dialogTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
1,
() => {
this.__sm.smdialog.open();
return GLib.SOURCE_REMOVE;
});
} else {
let panel = Main.panel._rightBox;
if (this._Schema.get_boolean('center-display')) {
panel = Main.panel._centerBox;
}

this._MountsMonitor.connect();

// Debug
this.__sm = {
tray: new PanelMenu.Button(0.5),
icon: new Icon(this),
pie: new Pie(this),
bar: new Bar(this),
elts: [],
};

// Items to Monitor
let tray = this.__sm.tray;

// Load the preferred position of the displays and insert them in said order.
const positionList = {};
// CPUs are inserted differently, so cpu-position is stored apart
const cpuPosition = this._Schema.get_int('cpu-position');
positionList[cpuPosition] = createCpus(this);
positionList[this._Schema.get_int('freq-position')] = new Freq(this);
positionList[this._Schema.get_int('memory-position')] = new Mem(this);
positionList[this._Schema.get_int('swap-position')] = new Swap(this);
positionList[this._Schema.get_int('net-position')] = new Net(this);
positionList[this._Schema.get_int('disk-position')] = new Disk(this);
positionList[this._Schema.get_int('gpu-position')] = new Gpu(this);
positionList[this._Schema.get_int('thermal-position')] = new Thermal(this);
positionList[this._Schema.get_int('fan-position')] = new Fan(this);
// See TODO inside Battery
// positionList[this._Schema.get_int('battery-position')] = new Battery(this);

if (this._Schema.get_boolean('move-clock')) {
let dateMenu = Main.panel.statusArea.dateMenu;
Main.panel._centerBox.remove_child(dateMenu.container);
Main.panel._addToPanelBox('dateMenu', dateMenu, -1, Main.panel._rightBox);
tray.clockMoved = true;
}

this._Schema.connect('changed::background', (schema, key) => {
this._Background = color_from_string(this._Schema.get_string(key));
});
Main.panel._addToPanelBox('system-monitor', tray, 1, panel);

// The spacing adds a distance between the graphs/text on the top bar
let spacing = this._Schema.get_boolean('compact-display') ? '1' : '4';
let box = new St.BoxLayout({style: 'spacing: ' + spacing + 'px;'});
tray.add_child(box);
box.add_child(this.__sm.icon.actor);

// Need to convert the positionList object into an array
// (sorted by object key) and then expand out the CPUs list
const sortedPLEntries = Object.entries(positionList).sort((a, b) => a[0] - b[0]);
const sortedPLValues = sortedPLEntries.map(([key, value]) => value);
this.__sm.elts = sortedPLValues.flat();

// Add items to panel box
for (const elt of this.__sm.elts) {
box.add_child(elt.actor);
}

// Build Menu Info Box Table
let menu_info = new PopupMenu.PopupBaseMenuItem({reactive: false});
let menu_info_box = new St.BoxLayout();
menu_info.actor.add_child(menu_info_box);
this.__sm.tray.menu.addMenuItem(menu_info, 0);

build_menu_info(this);

tray.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

let pie_item = this.__sm.pie;
pie_item.create_menu_item();
tray.menu.addMenuItem(pie_item.menu_item);

let bar_item = this.__sm.bar;
bar_item.create_menu_item();
tray.menu.addMenuItem(bar_item.menu_item);

change_usage(this);
this._Schema.connect('changed::disk-usage-style', change_usage);

tray.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

tray.menu.connect(
'open-state-changed',
(menu, isOpen) => {
if (isOpen) {
this.__sm.pie.actor.queue_repaint();
let panel = Main.panel._rightBox;
if (this._Schema.get_boolean('center-display')) {
panel = Main.panel._centerBox;
}

this._MountsMonitor.connect();

// Debug
this.__sm = {
tray: new PanelMenu.Button(0.5),
icon: new Icon(this),
pie: new Pie(this),
bar: new Bar(this),
elts: [],
};

// Items to Monitor
let tray = this.__sm.tray;

// Load the preferred position of the displays and insert them in said order.
const positionList = {};
// CPUs are inserted differently, so cpu-position is stored apart
const cpuPosition = this._Schema.get_int('cpu-position');
positionList[cpuPosition] = createCpus(this);
positionList[this._Schema.get_int('freq-position')] = new Freq(this);
positionList[this._Schema.get_int('memory-position')] = new Mem(this);
positionList[this._Schema.get_int('swap-position')] = new Swap(this);
positionList[this._Schema.get_int('net-position')] = new Net(this);
positionList[this._Schema.get_int('disk-position')] = new Disk(this);
positionList[this._Schema.get_int('gpu-position')] = new Gpu(this);
positionList[this._Schema.get_int('thermal-position')] = new Thermal(this);
positionList[this._Schema.get_int('fan-position')] = new Fan(this);
// See TODO inside Battery
// positionList[this._Schema.get_int('battery-position')] = new Battery(this);

if (this._Schema.get_boolean('move-clock')) {
let dateMenu = Main.panel.statusArea.dateMenu;
Main.panel._centerBox.remove_child(dateMenu.container);
Main.panel._addToPanelBox('dateMenu', dateMenu, -1, Main.panel._rightBox);
tray.clockMoved = true;
}

this.menuTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
5,
() => {
this.__sm.pie.actor.queue_repaint();
return GLib.SOURCE_CONTINUE;
});
} else {
GLib.Source.remove(this.menuTimeout);
}
this._Schema.connect('changed::background', (schema, key) => {
this._Background = color_from_string(this._Schema.get_string(key));
});
Main.panel._addToPanelBox('system-monitor', tray, 1, panel);

// The spacing adds a distance between the graphs/text on the top bar
let spacing = this._Schema.get_boolean('compact-display') ? '1' : '4';
let box = new St.BoxLayout({style: 'spacing: ' + spacing + 'px;'});
tray.add_child(box);
box.add_child(this.__sm.icon.actor);

// Need to convert the positionList object into an array
// (sorted by object key) and then expand out the CPUs list
const sortedPLEntries = Object.entries(positionList).sort((a, b) => a[0] - b[0]);
const sortedPLValues = sortedPLEntries.map(([key, value]) => value);
this.__sm.elts = sortedPLValues.flat();

// Add items to panel box
for (const elt of this.__sm.elts) {
box.add_child(elt.actor);
}

// Build Menu Info Box Table
let menu_info = new PopupMenu.PopupBaseMenuItem({reactive: false});
let menu_info_box = new St.BoxLayout();
menu_info.actor.add_child(menu_info_box);
this.__sm.tray.menu.addMenuItem(menu_info, 0);

build_menu_info(this);

tray.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

let pie_item = this.__sm.pie;
pie_item.create_menu_item();
tray.menu.addMenuItem(pie_item.menu_item);

let bar_item = this.__sm.bar;
bar_item.create_menu_item();
tray.menu.addMenuItem(bar_item.menu_item);

change_usage(this);
this._Schema.connect('changed::disk-usage-style', change_usage);

tray.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

tray.menu.connect(
'open-state-changed',
(menu, isOpen) => {
if (isOpen) {
this.__sm.pie.actor.queue_repaint();

this.menuTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
5,
() => {
this.__sm.pie.actor.queue_repaint();
return GLib.SOURCE_CONTINUE;
});
} else {
GLib.Source.remove(this.menuTimeout);
}
);
}
);

let _appSys = Shell.AppSystem.get_default();
let _gsmApp = _appSys.lookup_app('org.gnome.SystemMonitor.desktop') || _appSys.lookup_app('gnome-system-monitor.desktop');
let _appSys = Shell.AppSystem.get_default();
let _gsmApp = _appSys.lookup_app('org.gnome.SystemMonitor.desktop') || _appSys.lookup_app('gnome-system-monitor.desktop');

let item;
item = new PopupMenu.PopupMenuItem(_('System Monitor...'));
item.connect('activate', () => {
_gsmApp.activate();
});
tray.menu.addMenuItem(item);
let item;
item = new PopupMenu.PopupMenuItem(_('System Monitor...'));
item.connect('activate', () => {
_gsmApp.activate();
});
tray.menu.addMenuItem(item);

item = new PopupMenu.PopupMenuItem(_('Preferences...'));
item.connect('activate', () => {
this.openPreferences();
});
tray.menu.addMenuItem(item);
Main.panel.menuManager.addMenu(tray.menu);
}
item = new PopupMenu.PopupMenuItem(_('Preferences...'));
item.connect('activate', () => {
this.openPreferences();
});
tray.menu.addMenuItem(item);
Main.panel.menuManager.addMenu(tray.menu);
}

disable() {
if (this.dialogTimeout) {
GLib.Source.remove(this.dialogTimeout);
this.dialogTimeout = null;
}
if (this.menuTimeout) {
GLib.Source.remove(this.menuTimeout);
this.menuTimeout = null;
Expand Down

0 comments on commit b3630b1

Please sign in to comment.