Skip to content

Commit

Permalink
Workaround started automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Jan 2, 2024
1 parent fe48f0e commit 841fd80
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 70 deletions.
3 changes: 3 additions & 0 deletions com.github.stsdc.monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@
{
"name": "com.github.stsdc.monitor",
"buildsystem": "meson",
"config-opts": [
"-Dflatpak-workaround=enabled"
],
"sources": [
{
"type": "dir",
Expand Down
4 changes: 4 additions & 0 deletions flatpak/workaround/process_monitor.py → ...nd/com.github.stsdc.monitor-workaround.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/python

"""The workaround script should run only in Flatpak environment."""

import os

import dbus
Expand Down
4 changes: 4 additions & 0 deletions flatpak/workaround/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
install_data(
join_paths('com.github.stsdc.monitor-workaround.py'),
install_dir: join_paths(datadir, 'workaround')
)
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ subdir('src')
meson.add_install_script('meson/post_install.py')

subdir('po')


if get_option('flatpak-workaround').enabled()
subdir('flatpak/workaround')
endif

# subdir('tests')
3 changes: 2 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
option('indicator-wingpanel', type : 'feature', value : 'disabled', description : 'Enables the Indicator for Wingpanel.')
option('indicator-wingpanel', type : 'feature', value : 'disabled', description : 'Enables the Indicator for Wingpanel.')
option('flatpak-workaround', type : 'feature', value : 'disabled', description : 'Enables the Flatpak workaround.')
50 changes: 20 additions & 30 deletions src/Managers/ProcessProvider.vala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace Monitor {
public class ProcessProvider {
public class ProcessProvider : GLib.Object{
private static GLib.Once<ProcessProvider> instance;
public static unowned ProcessProvider get_default () {
return instance.once (() => { return new ProcessProvider (); });
}

private bool is_flatpak;

public Gee.HashMap<int, string> pids_cmdline = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_stat = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_statm = new Gee.HashMap<int, string> ();
Expand All @@ -14,14 +16,28 @@ namespace Monitor {

DBusWorkaroundClient dbus_workaround_client;

public ProcessProvider () {
if (ProcessUtils.is_flatpak_env ()) {
construct {
this.is_flatpak = ProcessUtils.is_flatpak_env ();
if (this.is_flatpak) {
this.spawn_workaround ();
dbus_workaround_client = DBusWorkaroundClient.get_default ();
}
}

private bool spawn_workaround () {
try {
debug ("Spawning workaround...");
string app_path = ProcessUtils.get_flatpak_app_path ();
string command = @"flatpak-spawn --host env LANG=C $app_path/share/workaround/com.github.stsdc.monitor-workaround.py";
return GLib.Process.spawn_command_line_async (command);
} catch (SpawnError e) {
warning ("Spawning workaround error: %s\n", e.message);
return false;
}
}

public int[] get_pids () {
if (ProcessUtils.is_flatpak_env ()) {
if (this.is_flatpak) {
int[] pids;
pids_cmdline.clear ();
pids_stat.clear ();
Expand Down Expand Up @@ -54,31 +70,5 @@ namespace Monitor {

return pids;
}

private bool process_line (IOChannel channel, IOCondition condition, GLib.List<int> _pids) {
if (condition == IOCondition.HUP) {
// debug ("%s: The fd has been closed.\n", stream_name);
return false;
}

try {
string line;
channel.read_line (out line, null, null);
if (line[0].isdigit ()) {
print ("%d\n", int.parse (line));
// pids.add (line.strip ());

}
} catch (IOChannelError e) {
warning ("IOChannelError: %s\n", e.message);
return false;
} catch (ConvertError e) {
warning ("ConvertError: %s\n", e.message);
return false;
}

return true;
}

}
}
49 changes: 10 additions & 39 deletions src/Managers/ProcessUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,48 +88,9 @@ public class Monitor.ProcessUtils {
out status
);


// GLib.Process.spawn_async_with_pipes
// ("/",
// spawn_args,
// Environ.get (),
// SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
// null,
// out child_pid,
// out standard_input,
// out standard_output,
// out standard_error
// );
// debug ("Status: %d", status);
} catch (SpawnError e) {
error (e.message);
}
// IOChannel output = new IOChannel.unix_new (standard_output);
// output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
// if (condition == IOCondition.HUP) {
// print ("%s: The fd has been closed.\n", "stream_name");
// return false;
// }

// try {
// string line;
// channel.read_line (out line, null, null);
// print ("%s: %s", "stream_name", line);
// } catch (IOChannelError e) {
// print ("%s: IOChannelError: %s\n", "stream_name", e.message);
// return false;
// } catch (ConvertError e) {
// print ("%s: ConvertError: %s\n", "stream_name", e.message);
// return false;
// }

// return true;
// });

// ChildWatch.add (child_pid, (pid, status) => {
//// Triggered when the child indicated by child_pid exits
// GLib.Process.close_pid (pid);
// });


string ? stdout_no_debug = "";
Expand Down Expand Up @@ -167,4 +128,14 @@ public class Monitor.ProcessUtils {
return false;
}

public static string get_flatpak_app_path () {
string ? flatpak_info_content = ProcessUtils.read_file ("/.flatpak-info");
foreach (var line in flatpak_info_content.split ("\n")) {
if (line.contains ("app-path")) {
return line.replace ("app-path=", "");
}
}
return "";
}

}

0 comments on commit 841fd80

Please sign in to comment.