From bb35702bdd57b0aa8119aab3ccd440635951679b Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:41:46 +0100 Subject: [PATCH] provider wip --- src/MainWindow.vala | 8 +-- src/Managers/ContainerManager.vala | 2 - src/Managers/HttpClientAsync.vala | 2 +- src/Managers/ProcessManager.vala | 30 ++------- src/Managers/ProcessProvider.vala | 85 ++++++-------------------- src/Services/DBusWorkaroundClient.vala | 2 +- subprojects/stylesheet | 2 +- 7 files changed, 26 insertions(+), 105 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 77c7c0cb..5c620623 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -69,7 +69,6 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { show_all (); dbusserver = DBusServer.get_default (); - var dbus_workaround_client = DBusWorkaroundClient.get_default(); headerbar.search_revealer.set_reveal_child (stack.visible_child_name == "process_view"); stack.notify["visible-child-name"].connect (() => { @@ -90,12 +89,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow { var res = resources.serialize (); statusbar.update (res); dbusserver.update (res); - try { - HashTable[] p = dbus_workaround_client.interface.get_processes (""); - debug("%s", p[400]["cmdline"] ); - } catch (Error e) { - warning (e.message); - } + return false; }); return true; diff --git a/src/Managers/ContainerManager.vala b/src/Managers/ContainerManager.vala index 9d04fae1..75e21183 100644 --- a/src/Managers/ContainerManager.vala +++ b/src/Managers/ContainerManager.vala @@ -157,8 +157,6 @@ namespace Monitor { assert_nonnull (container_object); this.add_container (container_object); - - } var remove_me = new Gee.HashSet (); foreach (var container in this.container_list.values) { diff --git a/src/Managers/HttpClientAsync.vala b/src/Managers/HttpClientAsync.vala index f5a222b0..abf2b5c6 100644 --- a/src/Managers/HttpClientAsync.vala +++ b/src/Managers/HttpClientAsync.vala @@ -49,7 +49,7 @@ namespace Monitor { r = curl.setopt (Curl.Option.WRITEFUNCTION, HttpClientResponse.read_body_data); assert_true (r == Curl.Code.OK); - // debug ("call api method: %s - %s", this.get_request_method (method), url); + debug ("call api method: %s - %s", this.get_request_method (method), url); yield this.perform (curl); diff --git a/src/Managers/ProcessManager.vala b/src/Managers/ProcessManager.vala index 3cd06b2d..c7954f17 100644 --- a/src/Managers/ProcessManager.vala +++ b/src/Managers/ProcessManager.vala @@ -97,7 +97,7 @@ namespace Monitor { /** * Gets all new process and adds them */ - public async void update_processes () { + public async void update_processes () { /* CPU */ GTop.Cpu cpu_data; GTop.get_cpu (out cpu_data); @@ -135,34 +135,14 @@ namespace Monitor { // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, uid); - if (ProcessUtils.is_flatpak_env ()) { - var pp = ProcessProvider.get_default (); - var pp_pids = pp.get_pids (); + for (int i = 0; i < proclist.number; i++) { + int pid = pids[i]; - // foreach (var pid in pp_pids) { - // debug ("yeah %d", pid); - // } - - debug ("Size %u", pp_pids.length ()); - - foreach (int pid in pp_pids) { - if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { - add_process (pid); - } + if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { + add_process (pid); } - debug ("process_list size %u", process_list.size); - } else { - // for (int i = 0; i < proclist.number; i++) { - // int pid = pids[i]; - - // if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) { - // add_process (pid); - // } - // } } - - cpu_last_used = used; cpu_last_total = cpu_data.total; cpu_last_useds = useds; diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index a888808d..431d6e25 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -7,77 +7,26 @@ namespace Monitor { public Gee.HashSet pids = new Gee.HashSet (); + DBusWorkaroundClient dbus_workaround_client; + public ProcessProvider () { + if (ProcessUtils.is_flatpak_env ()) { + dbus_workaround_client = DBusWorkaroundClient.get_default (); + } } - public GLib.List get_pids () { - var new_pids = new GLib.List (); - - try { - string[] spawn_args = { "flatpak-spawn", "--host", "ls" }; - string[] spawn_env = Environ.get (); - Pid child_pid; - - int standard_input; - int standard_output; - int standard_error; - - - string ls_stdout; - string ls_stderr; - int ls_status; - - // GLib.Process.spawn_async_with_pipes - // ( - // "/proc/", - // spawn_args, - // spawn_env, - // SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, - // null, - // out child_pid, - // out standard_input, - // out standard_output, - // out standard_error - // ); - - GLib.Process.spawn_command_line_sync ( - "ls /tmp/fakeproc/proc/", - out ls_stdout, - out ls_stderr, - out ls_status); - - // stdout: - // IOChannel output = new IOChannel.unix_new (standard_output); - // output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - // return process_line (channel, condition, new_pids); - // }); - - //// stderr: - // IOChannel error = new IOChannel.unix_new (standard_error); - // error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { - //// return process_line (channel, condition, "stderr"); - // return true; - // }); - - // ChildWatch.add (child_pid, (pid, status) => { - ////// Triggered when the child indicated by child_pid exits - // GLib.Process.close_pid (pid); - //// loop.quit (); - // }); - - // debug (ls_stdout); - foreach (var line in ls_stdout.strip ().split ("\n")) { - if (line[0].isdigit ()) { - // print ("---->" + line + "\n"); - new_pids.append (int.parse (line)); - } - } - - - } catch (SpawnError e) { - error ("Error: %s\n", e.message); - } - return new_pids; + public int[] get_pids () { + // try { + // HashTable[] p = dbus_workaround_client.interface.get_processes (""); + // debug ("%s", p[400]["cmdline"] ); + // } catch (Error e) { + // warning (e.message); + // } + GTop.ProcList proclist; + // var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid); + int[] pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ()); + debug("%d", pids.length); + return pids; } private bool process_line (IOChannel channel, IOCondition condition, GLib.List _pids) { diff --git a/src/Services/DBusWorkaroundClient.vala b/src/Services/DBusWorkaroundClient.vala index bdf5ccff..dc425bfd 100644 --- a/src/Services/DBusWorkaroundClient.vala +++ b/src/Services/DBusWorkaroundClient.vala @@ -1,6 +1,6 @@ [DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")] public interface Monitor.DBusWorkaroundClientInterface : Object { - public abstract HashTable[] get_processes (string empty) throws Error; + public abstract HashTable[] get_processes (string empty) throws Error; } diff --git a/subprojects/stylesheet b/subprojects/stylesheet index fbe2b247..a8b3c703 160000 --- a/subprojects/stylesheet +++ b/subprojects/stylesheet @@ -1 +1 @@ -Subproject commit fbe2b24704bbfd489152350627033295b3770a38 +Subproject commit a8b3c70331f983ed9a2568817188df15a257e319