Skip to content

Commit

Permalink
extension: Make "System Monitor" action customizable
Browse files Browse the repository at this point in the history
Some users would like to use a different system monitor other than the
current GNOME System Monitor app. Add a new setting that can be used to
specify a custom command for a system monitor app, falling back to the
default when none is provided (or on error).

Fixes #96
  • Loading branch information
mgalgs committed Nov 8, 2024
1 parent ea84fe8 commit 9e41c6b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 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
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 9e41c6b

Please sign in to comment.