From 5f15eebb92c656cfe24c7ea8bbd0acb2e72b94c8 Mon Sep 17 00:00:00 2001 From: heliguy Date: Fri, 22 Sep 2023 06:13:00 -0400 Subject: [PATCH] Fix crash in orphans window Orphans window would crash when there were no orphans to show --- src/common.py | 7 ++++++- src/orphans_window.py | 8 ++++++++ src/remotes.py | 27 ++++++++++++--------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/common.py b/src/common.py index ca9c669..38bf024 100644 --- a/src/common.py +++ b/src/common.py @@ -76,13 +76,18 @@ class myUtils: return image def getHostRemotes(self): - output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout + output = subprocess.run(["flatpak-spawn", "--host", "flatpakd", "remotes", "--columns=all"], capture_output=True, text=True).stdout lines = output.strip().split("\n") columns = lines[0].split("\t") data = [columns] for line in lines[1:]: row = line.split("\t") data.append(row) + try: + for i in range(len(data)): + data[i][7] = data[i][7].split(",")[0] + except: + pass return data def getHostFlatpaks(self): diff --git a/src/orphans_window.py b/src/orphans_window.py index 70fcc52..f1db37e 100644 --- a/src/orphans_window.py +++ b/src/orphans_window.py @@ -14,6 +14,9 @@ class OrphansWindow(Adw.Window): select_all_button = Gtk.Template.Child() main_overlay = Gtk.Template.Child() toast_overlay = Gtk.Template.Child() + main_stack = Gtk.Template.Child() + no_data = Gtk.Template.Child() + action_bar = Gtk.Template.Child() window_title = _("Manage Leftover Data") host_home = str(pathlib.Path.home()) @@ -188,6 +191,9 @@ class OrphansWindow(Adw.Window): # Add row to list self.list_of_data.append(dir_row) + if self.list_of_data.get_row_at_index(0) == None: + self.main_stack.set_visible_child(self.no_data) + self.action_bar.set_visible(False) def __init__(self, main_window, **kwargs): super().__init__(**kwargs) @@ -209,6 +215,8 @@ class OrphansWindow(Adw.Window): self.add_controller(event_controller) self.install_button.connect("clicked", self.installButtonHandler) + if self.host_remotes[0][0] == '': + self.install_button.set_visible(False) self.trash_button.connect("clicked", self.trashHandler) self.select_all_button.connect("toggled", self.selectAllHandler) self.main_overlay.add_overlay(self.progress_bar) \ No newline at end of file diff --git a/src/remotes.py b/src/remotes.py index dafd6c3..fb6f8f5 100644 --- a/src/remotes.py +++ b/src/remotes.py @@ -1,4 +1,5 @@ from gi.repository import Gtk, Adw, GLib, Gdk, Gio +from .common import myUtils import subprocess import re @@ -21,15 +22,15 @@ class RemotesWindow(Adw.Window): data.append(row) return data - def get_host_remotes(self): - output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout - lines = output.strip().split("\n") - columns = lines[0].split("\t") - data = [columns] - for line in lines[1:]: - row = line.split("\t") - data.append(row) - return data + # def get_host_remotes(self): + # output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout + # lines = output.strip().split("\n") + # columns = lines[0].split("\t") + # data = [columns] + # for line in lines[1:]: + # row = line.split("\t") + # data.append(row) + # return data def on_add_response(self, _dialog, response_id, _function): if response_id == "cancel": @@ -197,18 +198,13 @@ class RemotesWindow(Adw.Window): app_row = Adw.ActionRow(title=self.host_flatpaks[i][0]) apps_list.append(app_row) - - - - - apps_scroll.set_child(apps_list) dialog.set_extra_child(apps_box) dialog.present() def generate_list(self): self.remotes_list.remove_all() - self.host_remotes = self.get_host_remotes() + self.host_remotes = self.my_utils.getHostRemotes() self.host_flatpaks = self.get_host_flatpaks() if len(self.host_remotes) < 1: no_remotes = Adw.StatusPage(icon_name="error-symbolic", title=_("No Remotes"), description=_("Warehouse cannot see the list of remotes or the system has no remotes added")) @@ -234,6 +230,7 @@ class RemotesWindow(Adw.Window): def __init__(self, main_window, **kwargs): super().__init__(**kwargs) + self.my_utils = myUtils(self) # Create Variables self.window_title = _("Manage Remotes")