Skip to content

Commit

Permalink
Merge pull request #99 from mgalgs/custom-system-monitor-app
Browse files Browse the repository at this point in the history
Custom system monitor app (#99)
  • Loading branch information
mgalgs authored Nov 8, 2024
2 parents 8503b78 + 9e41c6b commit 40f525c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
43 changes: 39 additions & 4 deletions system-monitor-next@paradoxxx.zero.gmail.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,44 @@ const Icon = class SystemMonitor_Icon {
}

export default class SystemMonitorExtension extends Extension {
openSystemMonitor() {
let _appSys = Shell.AppSystem.get_default();
let _gsmApp = _appSys.lookup_app('org.gnome.SystemMonitor.desktop') || _appSys.lookup_app('gnome-system-monitor.desktop');
let customCmd = this._Schema.get_string('custom-monitor-command');

if (!customCmd || customCmd.trim() === '') {
_gsmApp.activate();
return;
}

sm_log("Executing custom system monitor command: " + customCmd);
try {
let [success, argv] = GLib.shell_parse_argv(customCmd);
if (!success) {
sm_log('Failed to parse custom monitor command: ' + customCmd, 'error');
_gsmApp.activate();
return;
}

let proc = new Gio.Subprocess({
argv: argv,
flags: Gio.SubprocessFlags.NONE
});
proc.init(null);
proc.wait_async(null, (proc, result) => {
try {
proc.wait_finish(result);
sm_log('Custom system monitor command completed with exit code: ' + proc.get_exit_status());
} catch (e) {
sm_log('Error waiting for process completion: ' + e.message, 'error');
}
});
} catch (e) {
sm_log('Failed to execute custom monitor command: ' + e.message, 'error');
_gsmApp.activate();
}
}

enable() {
sm_log('applet enable from ' + this.path);

Expand Down Expand Up @@ -2526,13 +2564,10 @@ export default class SystemMonitorExtension extends Extension {
}
);

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();
this.openSystemMonitor();
});
tray.menu.addMenuItem(item);

Expand Down
2 changes: 1 addition & 1 deletion system-monitor-next@paradoxxx.zero.gmail.com/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"uuid": "system-monitor-next@paradoxxx.zero.gmail.com",
"name": "system-monitor-next",
"url": "https://github.com/mgalgs/gnome-shell-system-monitor-applet",
"description": "Display system information in GNOME Shell status bar, such as memory, CPU, disk and battery usages, network rates…\n\nThis is a fork of the seemingly abandoned paradoxxxzero/gnome-shell-system-monitor-applet.\n\nIf you get an error after updating, try logging out and logging back in (this is a known issue that is being worked on).",
"description": "Display system information in GNOME Shell status bar, such as memory, CPU, disk and battery usages, network rates…\n\nIf you get an error after updating, try logging out and logging back in (this is a known issue that is being worked on).",
"settings-schema": "org.gnome.shell.extensions.system-monitor-next-applet",
"gettext-domain": "system-monitor",
"version": -1
Expand Down
18 changes: 17 additions & 1 deletion system-monitor-next@paradoxxx.zero.gmail.com/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const SMGeneralPrefsPage = GObject.registerClass({
GTypeName: 'SMGeneralPrefsPage',
Template: import.meta.url.replace('prefs.js', 'ui/prefsGeneralSettings.ui'),
InternalChildren: ['background', 'icon_display', 'show_tooltip', 'move_clock',
'compact_display', 'center_display', 'rotate_labels', 'tooltip_delay_ms'],
'compact_display', 'center_display', 'rotate_labels', 'tooltip_delay_ms',
'custom_monitor_switch', 'custom_monitor_command'],
}, class SMGeneralPrefsPage extends Adw.PreferencesPage {
constructor(settings, params = {}) {
super(params);
Expand Down Expand Up @@ -86,6 +87,21 @@ const SMGeneralPrefsPage = GObject.registerClass({
this._settings.bind('tooltip-delay-ms', this._tooltip_delay_ms,
'value', Gio.SettingsBindFlags.DEFAULT
);

const hasCommand = this._settings.get_string('custom-monitor-command').trim() !== '';
this._custom_monitor_switch.active = hasCommand;
this._custom_monitor_command.visible = hasCommand;

this._custom_monitor_switch.connect('notify::active', () => {
this._custom_monitor_command.visible = this._custom_monitor_switch.active;
if (!this._custom_monitor_switch.active) {
this._settings.set_string('custom-monitor-command', '');
}
});

this._settings.bind('custom-monitor-command', this._custom_monitor_command,
'text', Gio.SettingsBindFlags.DEFAULT
);
}
});

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,10 @@
<default>9</default>
<summary>Position in which to display the battery display</summary>
</key>
<key name="custom-monitor-command" type="s">
<default>''</default>
<summary>Custom system monitor command</summary>
<description>When set, this command will be executed instead of launching GNOME System Monitor</description>
</key>
</schema>
</schemalist>
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="custom_monitor_switch">
<property name="title" translatable="yes">Custom System Monitor Command</property>
<property name="subtitle" translatable="yes">Use a custom command instead of GNOME System Monitor</property>
</object>
</child>
<child>
<object class="AdwEntryRow" id="custom_monitor_command">
<property name="title" translatable="yes">Command (e.g. 'missioncenter')</property>
<property name="tooltip-text" translatable="yes">Command to run instead of GNOME System Monitor</property>
</object>
</child>
</object>
</child>
</template>
Expand Down

0 comments on commit 40f525c

Please sign in to comment.