From 896be1118d68c30e8a2b6717cefc76fe22a0f8f2 Mon Sep 17 00:00:00 2001 From: heliguy Date: Sun, 7 Jul 2024 23:20:55 -0400 Subject: [PATCH] enable opening apps, handle trash errors better --- src/host_info.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/host_info.py b/src/host_info.py index c5539e2..8d12599 100644 --- a/src/host_info.py +++ b/src/host_info.py @@ -1,6 +1,6 @@ import subprocess, os, pathlib -from gi.repository import Gio, Gtk, GLib, Adw +from gi.repository import Gio, Gtk, GLib, Adw, Gdk # from .app_row import AppRow home = f"{pathlib.Path.home()}" @@ -10,6 +10,20 @@ direction = Gtk.Image().get_direction() class Flatpak: + def open_app(self, callback=None): + self.failed_app_run = None + def thread(*args): + if self.is_runtime: + self.failed_app_run = "error: cannot open a runtime" + try: + subprocess.run(['flatpak-spawn', '--host', 'flatpak', 'run', f"{self.info['ref']}"], capture_output=True, text=True, check=True) + except subprocess.CalledProcessError as cpe: + self.failed_app_run = cpe.stderr + except Exception as e: + self.failed_app_run = e + + Gio.Task.new(None, None, callback).run_in_thread(thread) + def open_data(self): if not os.path.exists(self.data_path): return f"Path '{self.data_path}' does not exist" @@ -30,7 +44,9 @@ class Flatpak: def trash_data(self, callback=None): try: - subprocess.run(['gio', 'trash', f"{self.data_path}"]) + subprocess.run(['gio', 'trash', f"{self.data_path}"], capture_output=True, text=True, check=True) + except subprocess.CalledProcessError as cpe: + raise cpe except Exception as e: raise e @@ -90,6 +106,7 @@ class Flatpak: self.is_eol = "eol=" in self.info["options"] self.dependant_runtime = None + self.failed_app_run = None try: self.is_masked = self.info["id"] in HostInfo.masks[self.info["installation"]] @@ -121,6 +138,7 @@ class Remote: class HostInfo: home = home + clipboard = Gdk.Display.get_default().get_clipboard() # Get all possible installation icon theme dirs output = subprocess.run(