mirror of
https://github.com/morgan9e/warehouse
synced 2026-04-14 00:04:08 +09:00
Catch errors more properly when loading packages
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from gi.repository import Adw, Gtk, Gdk, GLib
|
||||
from .host_info import HostInfo
|
||||
|
||||
class ErrorToast:
|
||||
main_window = None
|
||||
@@ -7,11 +6,12 @@ class ErrorToast:
|
||||
|
||||
def on_response(dialog, response_id):
|
||||
if response_id == "copy":
|
||||
HostInfo.clipboard.set(error_msg)
|
||||
self.clipboard.set(error_msg)
|
||||
|
||||
# Extra Object Creation
|
||||
self.toast = Adw.Toast(title=display_msg, button_label=_("Details"))
|
||||
popup = Adw.AlertDialog.new(display_msg)
|
||||
self.clipboard = Gdk.Display.get_default().get_clipboard()
|
||||
|
||||
# Apply
|
||||
print(display_msg)
|
||||
|
||||
100
src/host_info.py
100
src/host_info.py
@@ -1,7 +1,6 @@
|
||||
import subprocess, os, pathlib
|
||||
|
||||
from gi.repository import Gio, Gtk, GLib, Adw, Gdk
|
||||
# from .app_row import AppRow
|
||||
from .error_toast import ErrorToast
|
||||
import subprocess, os, pathlib
|
||||
|
||||
home = f"{pathlib.Path.home()}"
|
||||
icon_theme = Gtk.IconTheme.new()
|
||||
@@ -311,52 +310,57 @@ class HostInfo:
|
||||
if lines[0] != '':
|
||||
this.pins[installation] = lines
|
||||
|
||||
# Installations
|
||||
# Get all config files for any extra installations
|
||||
custom_install_config_path = "/run/host/etc/flatpak/installations.d"
|
||||
if os.path.exists(custom_install_config_path):
|
||||
for file in os.listdir(custom_install_config_path):
|
||||
with open(f"{custom_install_config_path}/{file}", "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("[Installation"):
|
||||
# Get specifically the installation name itself
|
||||
this.installations.append(line.replace("[Installation \"", "").replace("\"]", "").strip())
|
||||
try:
|
||||
# Installations
|
||||
# Get all config files for any extra installations
|
||||
custom_install_config_path = "/run/host/etc/flatpak/installations.d"
|
||||
if os.path.exists(custom_install_config_path):
|
||||
for file in os.listdir(custom_install_config_path):
|
||||
with open(f"{custom_install_config_path}/{file}", "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("[Installation"):
|
||||
# Get specifically the installation name itself
|
||||
this.installations.append(line.replace("[Installation \"", "").replace("\"]", "").strip())
|
||||
|
||||
this.installations.append("user")
|
||||
this.installations.append("system")
|
||||
for i in this.installations:
|
||||
remote_info(i)
|
||||
remote_info("user")
|
||||
remote_info("system")
|
||||
this.installations.append("user")
|
||||
this.installations.append("system")
|
||||
for i in this.installations:
|
||||
remote_info(i)
|
||||
remote_info("user")
|
||||
remote_info("system")
|
||||
|
||||
# Packages
|
||||
output = subprocess.run(
|
||||
['flatpak-spawn', '--host',
|
||||
'flatpak', 'list', '--columns=all'],
|
||||
text=True,
|
||||
capture_output=True,
|
||||
).stdout
|
||||
lines = output.strip().split("\n")
|
||||
for i in lines:
|
||||
package = Flatpak(i.split("\t"))
|
||||
this.flatpaks.append(package)
|
||||
this.id_to_flatpak[package.info["id"]] = package
|
||||
this.ref_to_flatpak[package.info["ref"]] = package
|
||||
|
||||
# Dependant Runtimes
|
||||
output = subprocess.run(
|
||||
['flatpak-spawn', '--host',
|
||||
'flatpak', 'list', '--columns=runtime'],
|
||||
text=True,
|
||||
capture_output=True,
|
||||
).stdout
|
||||
lines = output.strip().split("\n")
|
||||
for index, runtime in enumerate(lines):
|
||||
package = this.flatpaks[index]
|
||||
if package.is_runtime:
|
||||
continue
|
||||
package.dependant_runtime = this.ref_to_flatpak[runtime]
|
||||
if not runtime in this.dependant_runtime_refs:
|
||||
this.dependant_runtime_refs.append(runtime)
|
||||
# Packages
|
||||
output = subprocess.run(
|
||||
['flatpak-spawn', '--host',
|
||||
'flatpak', 'list', '--columns=all'],
|
||||
text=True, check=True,
|
||||
capture_output=True,
|
||||
).stdout
|
||||
lines = output.strip().split("\n")
|
||||
for i in lines:
|
||||
package = Flatpak(i.split("\t"))
|
||||
this.flatpaks.append(package)
|
||||
this.id_to_flatpak[package.info["id"]] = package
|
||||
this.ref_to_flatpak[package.info["ref"]] = package
|
||||
|
||||
# Dependant Runtimes
|
||||
output = subprocess.run(
|
||||
['flatpak-spawn', '--host',
|
||||
'flatpak', 'list', '--columns=runtime'],
|
||||
text=True, check=True,
|
||||
capture_output=True,
|
||||
).stdout
|
||||
lines = output.strip().split("\n")
|
||||
for index, runtime in enumerate(lines):
|
||||
package = this.flatpaks[index]
|
||||
if package.is_runtime:
|
||||
continue
|
||||
package.dependant_runtime = this.ref_to_flatpak[runtime]
|
||||
if not runtime in this.dependant_runtime_refs:
|
||||
this.dependant_runtime_refs.append(runtime)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
this.main_window.toast_overlay.add_toast(ErrorToast(_("Could not load pacakges"), cpe.stderr).toast)
|
||||
except Exception as e:
|
||||
this.main_window.toast_overlay.add_toast(ErrorToast(_("Could not load pacakges"), str(e)).toast)
|
||||
|
||||
Gio.Task.new(None, None, callback).run_in_thread(thread)
|
||||
@@ -16,124 +16,126 @@ template $WarehouseWindow: Adw.ApplicationWindow {
|
||||
}
|
||||
}
|
||||
content:
|
||||
Adw.OverlaySplitView main_split {
|
||||
collapsed: true;
|
||||
show-sidebar: true;
|
||||
sidebar-width-fraction: 0.2;
|
||||
// max-sidebar-width: 280;
|
||||
min-sidebar-width: 250;
|
||||
sidebar:
|
||||
Adw.NavigationPage {
|
||||
title: "Warehouse";
|
||||
Adw.ToolbarView main_toolbar_view {
|
||||
[top]
|
||||
Adw.HeaderBar header_bar {
|
||||
[start]
|
||||
Button refresh_button {
|
||||
icon-name: "arrow-circular-top-right-symbolic";
|
||||
tooltip-text: _("Refresh List");
|
||||
Adw.ToastOverlay toast_overlay {
|
||||
Adw.OverlaySplitView main_split {
|
||||
collapsed: true;
|
||||
show-sidebar: true;
|
||||
sidebar-width-fraction: 0.2;
|
||||
// max-sidebar-width: 280;
|
||||
min-sidebar-width: 250;
|
||||
sidebar:
|
||||
Adw.NavigationPage {
|
||||
title: "Warehouse";
|
||||
Adw.ToolbarView main_toolbar_view {
|
||||
[top]
|
||||
Adw.HeaderBar header_bar {
|
||||
[start]
|
||||
Button refresh_button {
|
||||
icon-name: "arrow-circular-top-right-symbolic";
|
||||
tooltip-text: _("Refresh List");
|
||||
}
|
||||
[end]
|
||||
MenuButton main_menu {
|
||||
icon-name: "open-menu-symbolic";
|
||||
tooltip-text: _("Main Menu");
|
||||
menu-model: primary_menu;
|
||||
}
|
||||
}
|
||||
[end]
|
||||
MenuButton main_menu {
|
||||
icon-name: "open-menu-symbolic";
|
||||
tooltip-text: _("Main Menu");
|
||||
menu-model: primary_menu;
|
||||
}
|
||||
}
|
||||
content:
|
||||
ScrolledWindow {
|
||||
ListBox navigation_row_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
content:
|
||||
ScrolledWindow {
|
||||
ListBox navigation_row_listbox {
|
||||
styles ["navigation-sidebar"]
|
||||
|
||||
Box packages_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
Box packages_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Image icon {
|
||||
icon-name: "flatpak-symbolic";
|
||||
Image icon {
|
||||
icon-name: "flatpak-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Packages");
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Packages");
|
||||
}
|
||||
}
|
||||
|
||||
Box remotes_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Image {
|
||||
icon-name: "server-pick-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Remotes");
|
||||
}
|
||||
}
|
||||
|
||||
Box user_data_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
Box remotes_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Image {
|
||||
icon-name: "file-manager-symbolic";
|
||||
}
|
||||
Image {
|
||||
icon-name: "server-pick-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("User Data");
|
||||
Label {
|
||||
label: _("Remotes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box snapshots_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Box user_data_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Image {
|
||||
icon-name: "snapshots-alt-symbolic";
|
||||
}
|
||||
Image {
|
||||
icon-name: "file-manager-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Snapshots");
|
||||
Label {
|
||||
label: _("User Data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box install_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
Box snapshots_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Image {
|
||||
icon-name: "arrow-pointing-at-line-down-symbolic";
|
||||
Image {
|
||||
icon-name: "snapshots-alt-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Snapshots");
|
||||
}
|
||||
}
|
||||
|
||||
Box install_row {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
spacing: 12;
|
||||
|
||||
Label {
|
||||
label: _("Install Packages");
|
||||
Image {
|
||||
icon-name: "arrow-pointing-at-line-down-symbolic";
|
||||
}
|
||||
|
||||
Label {
|
||||
label: _("Install Packages");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
content:
|
||||
Stack stack {
|
||||
}
|
||||
;
|
||||
;
|
||||
content:
|
||||
Stack stack {
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
|
||||
__gtype_name__ = "WarehouseWindow"
|
||||
gtc = Gtk.Template.Child
|
||||
main_breakpoint = gtc()
|
||||
toast_overlay = gtc()
|
||||
main_split = gtc()
|
||||
stack = gtc()
|
||||
refresh_button = gtc()
|
||||
@@ -89,6 +90,8 @@ class WarehouseWindow(Adw.ApplicationWindow):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Extra Object Creation
|
||||
HostInfo.main_window = self
|
||||
ErrorToast.main_window = self
|
||||
self.settings = Gio.Settings.new("io.github.flattool.Warehouse")
|
||||
event_controller = Gtk.EventControllerKey()
|
||||
file_drop = Gtk.DropTarget.new(Gio.File, Gdk.DragAction.COPY)
|
||||
@@ -104,7 +107,6 @@ class WarehouseWindow(Adw.ApplicationWindow):
|
||||
self.stack.add_child(page)
|
||||
|
||||
# Apply
|
||||
ErrorToast.main_window = self
|
||||
self.settings.bind("window-width", self, "default-width", Gio.SettingsBindFlags.DEFAULT)
|
||||
self.settings.bind("window-height", self, "default-height", Gio.SettingsBindFlags.DEFAULT)
|
||||
self.settings.bind("is-maximized", self, "maximized", Gio.SettingsBindFlags.DEFAULT)
|
||||
@@ -121,7 +123,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
|
||||
# file_drop.connect("drop", self.drop_callback)
|
||||
self.refresh_button.connect("clicked", self.refresh_handler)
|
||||
|
||||
self.activate_row(self.snapshots_row)
|
||||
self.activate_row(self.packages_row)
|
||||
self.main_split.set_show_sidebar(True)
|
||||
|
||||
self.start_loading()
|
||||
|
||||
Reference in New Issue
Block a user