From 9c07eb6657d07c4b3a3afbc8b921a05ed29c67ba Mon Sep 17 00:00:00 2001 From: Roy Golan Date: Fri, 20 Dec 2024 09:29:02 +0200 Subject: [PATCH] Add pod list sort-by to preferences Signed-off-by: Roy Golan --- src/modules/podman.js | 3 ++- src/prefs.js | 20 ++++++++++++++++++- ...me.shell.extensions.containers.gschema.xml | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/podman.js b/src/modules/podman.js index 20a0fab..452c248 100644 --- a/src/modules/podman.js +++ b/src/modules/podman.js @@ -25,7 +25,8 @@ export async function getContainers(settings) { let jsonContainers; try { - const out = await spawnCommandline("podman ps -a --format json"); + const sortBy = settings.get_string("pod-list-sort-by"); + const out = await spawnCommandline(`podman ps -a --sort ${sortBy} --format json`); jsonContainers = JSON.parse(out); } catch (e) { console.error(e.message); diff --git a/src/prefs.js b/src/prefs.js index e9bf3c6..8249319 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -1,5 +1,6 @@ -import Gio from "gi://Gio"; import Adw from "gi://Adw"; +import Gio from "gi://Gio"; +import Gtk from "gi://Gtk"; import {ExtensionPreferences, gettext as _} from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js"; @@ -19,6 +20,7 @@ export default class ContainersPreferences extends ExtensionPreferences { }); page.add(appearanceGroup); + // extra info const extraInfoRow = new Adw.SwitchRow({ title: _("Extra Info"), subtitle: _("Whether to show extra info of a container in name and the opened menu"), @@ -26,12 +28,28 @@ export default class ContainersPreferences extends ExtensionPreferences { appearanceGroup.add(extraInfoRow); window._settings.bind("extra-info", extraInfoRow, "active", Gio.SettingsBindFlags.DEFAULT); + const sortBy = ["command", "created", "id", "image", "names", "runningfor", "size", "status"]; + const comboModel = new Gtk.StringList({strings: sortBy}); + const podListSortBy = new Adw.ComboRow({ + title: _("Pod List sort by column"), + model: comboModel, + }); + let initVal = window._settings.get_string("pod-list-sort-by"); + podListSortBy.set_selected(sortBy.indexOf(initVal)); + podListSortBy.connect("notify::selected-item", () => { + let selectedItem = podListSortBy.get_selected_item(); + window._settings.set_string("pod-list-sort-by", selectedItem.get_string()); + }); + appearanceGroup.add(podListSortBy); + + const behaviourGroup = new Adw.PreferencesGroup({ title: _("Behaviour"), description: _("Configure the behaviour of the extension"), }); page.add(behaviourGroup); + // terminal program const terminalRow = new Adw.EntryRow({ title: _("Terminal program with arguments"), show_apply_button: true, // Allows user to apply the input diff --git a/src/schemas/org.gnome.shell.extensions.containers.gschema.xml b/src/schemas/org.gnome.shell.extensions.containers.gschema.xml index af3d4cd..4b97ca0 100644 --- a/src/schemas/org.gnome.shell.extensions.containers.gschema.xml +++ b/src/schemas/org.gnome.shell.extensions.containers.gschema.xml @@ -4,6 +4,11 @@ true + + + "created" + + "gnome-terminal --" The terminal program and arguments to use for running commands such as shell, logs, stats, and watch