Skip to content

Commit

Permalink
Flatpak process listing for presets (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawstorant authored Oct 29, 2024
1 parent 21615a7 commit b733f5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
29 changes: 29 additions & 0 deletions boxflat/process_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
from threading import Thread, Event
from time import sleep
from boxflat.subscription import EventDispatcher
from os import environ, path
import subprocess


def list_processes(filter: str="") -> list[str]:
if environ["BOXFLAT_FLATPAK_EDITION"] == "true":
return _list_process_flatpak(filter)

return _list_process_native(filter)


def _list_process_native(filter: str) -> list[str]:
processes = []

for p in psutil.process_iter(['name']):
Expand All @@ -13,6 +23,25 @@ def list_processes(filter: str="") -> list[str]:
return processes


def _list_process_flatpak(filter: str) -> list[str]:
user = psutil.Process().username()
processes = subprocess.check_output(["flatpak-spawn", "--host", "ps", "-wwu", user, "-o", "exe="])
processes = processes.decode().split()
output = []

for name in processes:
if len(name) < 3:
continue

name = path.basename(name)
if not filter.lower() in name.lower():
continue

output.append(name)

return output


class ProcessObserver(EventDispatcher):
def __init__(self) -> None:
super().__init__()
Expand Down
6 changes: 2 additions & 4 deletions boxflat/widgets/preset_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ def _list_processes(self, entry: Adw.EntryRow, page: Adw.PreferencesPage):
page.add(group)
self._process_list_group = group

if len(name) < 2:
group.add(BoxflatLabelRow("Enter at least two letters"))
if environ["FLATPAK_EDITION"] == "true":
group.add(BoxflatLabelRow("Host Process listing doesn't work with flatpak yet"))
if len(name) < 3:
group.add(BoxflatLabelRow("Enter at least three letters"))
return

for name in sorted(process_handler.list_processes(name)):
Expand Down
2 changes: 1 addition & 1 deletion data/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.22.0
v1.22.1
4 changes: 2 additions & 2 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

data_path = "/usr/share/boxflat/data"
config_path = "~/.config/boxflat/"
os.environ["FLATPAK_EDITION"] = "false"
os.environ["BOXFLAT_FLATPAK_EDITION"] = "false"

if args.data_path:
data_path = args.data_path
Expand All @@ -26,7 +26,7 @@

if args.flatpak:
data_path = "/app/share/boxflat/data"
os.environ["FLATPAK_EDITION"] = "true"
os.environ["BOXFLAT_FLATPAK_EDITION"] = "true"

app.MyApp(data_path,
config_path,
Expand Down
5 changes: 5 additions & 0 deletions io.github.lawstorant.boxflat.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
<update_contact>[email protected]</update_contact>

<releases>
<release version="v1.22.1" date="2024-10-29">
<description>
<p>Process listing now works under flatpak. Automatic preset loading possible.</p>
</description>
</release>
<release version="v1.22.0" date="2024-10-27">
<description>
<p>Automatic, per-game preset loading</p>
Expand Down

0 comments on commit b733f5e

Please sign in to comment.