Fix crash in orphans window

Orphans window would crash when there were no orphans to show
This commit is contained in:
heliguy
2023-09-22 06:13:00 -04:00
parent a1409e870e
commit 5f15eebb92
3 changed files with 26 additions and 16 deletions

View File

@@ -76,13 +76,18 @@ class myUtils:
return image return image
def getHostRemotes(self): 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") lines = output.strip().split("\n")
columns = lines[0].split("\t") columns = lines[0].split("\t")
data = [columns] data = [columns]
for line in lines[1:]: for line in lines[1:]:
row = line.split("\t") row = line.split("\t")
data.append(row) data.append(row)
try:
for i in range(len(data)):
data[i][7] = data[i][7].split(",")[0]
except:
pass
return data return data
def getHostFlatpaks(self): def getHostFlatpaks(self):

View File

@@ -14,6 +14,9 @@ class OrphansWindow(Adw.Window):
select_all_button = Gtk.Template.Child() select_all_button = Gtk.Template.Child()
main_overlay = Gtk.Template.Child() main_overlay = Gtk.Template.Child()
toast_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") window_title = _("Manage Leftover Data")
host_home = str(pathlib.Path.home()) host_home = str(pathlib.Path.home())
@@ -188,6 +191,9 @@ class OrphansWindow(Adw.Window):
# Add row to list # Add row to list
self.list_of_data.append(dir_row) 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): def __init__(self, main_window, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
@@ -209,6 +215,8 @@ class OrphansWindow(Adw.Window):
self.add_controller(event_controller) self.add_controller(event_controller)
self.install_button.connect("clicked", self.installButtonHandler) 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.trash_button.connect("clicked", self.trashHandler)
self.select_all_button.connect("toggled", self.selectAllHandler) self.select_all_button.connect("toggled", self.selectAllHandler)
self.main_overlay.add_overlay(self.progress_bar) self.main_overlay.add_overlay(self.progress_bar)

View File

@@ -1,4 +1,5 @@
from gi.repository import Gtk, Adw, GLib, Gdk, Gio from gi.repository import Gtk, Adw, GLib, Gdk, Gio
from .common import myUtils
import subprocess import subprocess
import re import re
@@ -21,15 +22,15 @@ class RemotesWindow(Adw.Window):
data.append(row) data.append(row)
return data return data
def get_host_remotes(self): # def get_host_remotes(self):
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout # output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout
lines = output.strip().split("\n") # lines = output.strip().split("\n")
columns = lines[0].split("\t") # columns = lines[0].split("\t")
data = [columns] # data = [columns]
for line in lines[1:]: # for line in lines[1:]:
row = line.split("\t") # row = line.split("\t")
data.append(row) # data.append(row)
return data # return data
def on_add_response(self, _dialog, response_id, _function): def on_add_response(self, _dialog, response_id, _function):
if response_id == "cancel": if response_id == "cancel":
@@ -197,18 +198,13 @@ class RemotesWindow(Adw.Window):
app_row = Adw.ActionRow(title=self.host_flatpaks[i][0]) app_row = Adw.ActionRow(title=self.host_flatpaks[i][0])
apps_list.append(app_row) apps_list.append(app_row)
apps_scroll.set_child(apps_list) apps_scroll.set_child(apps_list)
dialog.set_extra_child(apps_box) dialog.set_extra_child(apps_box)
dialog.present() dialog.present()
def generate_list(self): def generate_list(self):
self.remotes_list.remove_all() 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() self.host_flatpaks = self.get_host_flatpaks()
if len(self.host_remotes) < 1: 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")) 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): def __init__(self, main_window, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.my_utils = myUtils(self)
# Create Variables # Create Variables
self.window_title = _("Manage Remotes") self.window_title = _("Manage Remotes")