Properly handle having no remotes

This commit is contained in:
Heliguy
2024-08-25 16:28:23 -04:00
parent 1862d9e0a6
commit 39f27c094d
3 changed files with 79 additions and 33 deletions

View File

@@ -20,7 +20,30 @@ class RemoteRow(Adw.ActionRow):
remove = gtc()
def enable_remote_handler(self, *args):
def idle_stuff(*args):
if not self.remote.disabled:
self.parent_page.toast_overlay.add_toast(ErrorToast(_("Could not enable remote"), _("Remote is already enabled")).toast)
return
has_error = []
def thread(*args):
cmd = ['flatpak-spawn', '--host', 'flatpak', 'remote-modify', '--enable', self.remote.name]
if self.installation == "user" or self.installation == "system":
cmd.append(f"--{self.installation}")
else:
cmd.append(f"--installation={self.installation}")
try:
subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as cpe:
has_error.append(str(cpe.stderr))
except Exception as e:
has_error.append(str(e))
def callback(*args):
if len(has_error) > 0:
GLib.idle_add(lambda *args, cpe=cpe: self.parent_page.toast_overlay.add_toast(ErrorToast(_("Could not enable remote"), has_error[0]).toast))
return
self.remove_css_class("warning")
self.set_icon_name("")
self.remote.disabled = False
@@ -33,27 +56,8 @@ class RemoteRow(Adw.ActionRow):
if self.parent_page.total_disabled == 0:
self.parent_page.show_disabled_button.set_active(False)
self.parent_page.show_disabled_button.set_visible(False)
if not self.remote.disabled:
self.parent_page.toast_overlay.add_toast(ErrorToast(_("Could not enable remote"), _("Remote is already enabled")).toast)
return
cmd = ['flatpak-spawn', '--host', 'flatpak', 'remote-modify', '--enable', self.remote.name]
if self.installation == "user" or self.installation == "system":
cmd.append(f"--{self.installation}")
else:
cmd.append(f"--installation={self.installation}")
try:
subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as cpe:
GLib.idle_add(lambda *args, cpe=cpe: self.parent_page.toast_overlay.add_toast(ErrorToast(_("Could not enable remote"), str(cpe.stderr)).toast))
return
except Exception as e:
GLib.idle_add(lambda *args, e=e: self.parent_page.toast_overlay.add_toast(ErrorToast(_("Could not enable remote"), str(e)).toast))
return
idle_stuff()
Gio.Task.new(None, None, callback).run_in_thread(thread)
def disable_remote_handler(self, *args):
def callback(*args):
@@ -113,7 +117,7 @@ class RemoteRow(Adw.ActionRow):
HostInfo.clipboard.set(self.get_subtitle())
self.parent_page.toast_overlay.add_toast(Adw.Toast(title=_("Copied name")))
case self.enable_remote:
Gio.Task().run_in_thread(self.enable_remote_handler)
self.enable_remote_handler()
case self.disable_remote:
self.disable_remote_handler()
case self.remove:

View File

@@ -44,11 +44,6 @@ template $RemotesPage : Adw.NavigationPage {
description: _("Try a different search");
icon-name: "system-search-symbolic";
}
Adw.StatusPage no_remotes {
title: _("No Remotes Found");
description: _("Warehouse cannot see the current remotes or your system has no remotes added");
icon-name: "error-symbolic";
}
Adw.PreferencesPage content_page {
Adw.PreferencesGroup current_remotes_group {
title: _("Current Remotes");
@@ -64,16 +59,25 @@ template $RemotesPage : Adw.NavigationPage {
}
;
Adw.ActionRow none_visible {
styles ["warning"]
[child]
Box {
spacing: 3;
orientation: vertical;
Label {
margin-top: 7;
label: _("No Enabled Remotes");
wrap: true;
Box {
halign: center;
styles ["heading"]
Image {
valign: center;
margin-top: 7;
margin-end: 6;
icon-name: "eye-not-looking-symbolic";
}
Label {
margin-top: 7;
label: _("No Enabled Remotes");
wrap: true;
styles ["heading"]
}
}
Label {
label: _("You only have disabled remotes on this system");
@@ -86,6 +90,38 @@ template $RemotesPage : Adw.NavigationPage {
}
}
}
Adw.ActionRow no_remotes {
styles ["error"]
[child]
Box {
spacing: 3;
orientation: vertical;
Box {
halign: center;
Image {
valign: center;
margin-top: 7;
margin-end: 6;
icon-name: "error-symbolic";
}
Label {
margin-top: 7;
label: _("No Remotes Found");
wrap: true;
styles ["heading"]
}
}
Label {
label: _("Warehouse cannot see the current remotes or your system has no remotes added");
margin-start: 16;
margin-end: 16;
margin-bottom: 8;
justify: center;
halign: center;
wrap: true;
}
}
}
}
Adw.PreferencesGroup new_remotes_group {
visible: bind search_button.active inverted;

View File

@@ -134,6 +134,12 @@ class RemotesPage(Adw.NavigationPage):
self.none_visible.set_visible(total_visible == 0)
if len(self.current_remote_rows) == 0:
self.no_remotes.set_visible(True)
self.none_visible.set_visible(False)
else:
self.no_remotes.set_visible(False)
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.content_page))
self.search_button.set_sensitive(True)
self.search_entry.set_editable(True)