From 01c2f4616feeda1a084537dad706c4dde9288bd6 Mon Sep 17 00:00:00 2001 From: Heliguy Date: Sat, 28 Sep 2024 16:00:34 -0400 Subject: [PATCH] Use error toast for snapshotting --- src/snapshot_page/new_snapshot_dialog.py | 1 + src/snapshot_page/snapshot_box.py | 1 + src/snapshot_page/tar_worker.py | 12 +++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/snapshot_page/new_snapshot_dialog.py b/src/snapshot_page/new_snapshot_dialog.py index d0a32a3..4d768ed 100644 --- a/src/snapshot_page/new_snapshot_dialog.py +++ b/src/snapshot_page/new_snapshot_dialog.py @@ -120,6 +120,7 @@ class NewSnapshotDialog(Adw.Dialog): new_path=f"{HostInfo.snapshots_path}{package.info['id']}", file_name=f"{int(time.time())}_{package.info["version"]}", name=self.name_entry.get_text(), + toast_overlay=self.snapshot_page.toast_overlay, ) self.workers.append(worker) worker.compress() diff --git a/src/snapshot_page/snapshot_box.py b/src/snapshot_page/snapshot_box.py index 8a6eca2..16160ae 100644 --- a/src/snapshot_page/snapshot_box.py +++ b/src/snapshot_page/snapshot_box.py @@ -158,6 +158,7 @@ class SnapshotBox(Gtk.Box): existing_path=f"{snapshots_path}{folder}", new_path=f"{HostInfo.home}/.var/app/{self.app_id}/", file_name=self.app_id, + toast_overlay=self.toast_overlay, ) split_folder = folder.split('_') diff --git a/src/snapshot_page/tar_worker.py b/src/snapshot_page/tar_worker.py index 81c56a9..95696b4 100644 --- a/src/snapshot_page/tar_worker.py +++ b/src/snapshot_page/tar_worker.py @@ -4,7 +4,7 @@ from .error_toast import ErrorToast import os, tarfile, subprocess, json class TarWorker: - def __init__(self, existing_path, new_path, file_name, name=""): + def __init__(self, existing_path, new_path, file_name, name="", toast_overlay=None): self.existing_path = existing_path self.new_path = new_path self.file_name = file_name @@ -14,6 +14,7 @@ class TarWorker: self.fraction = 0.0 self.total = 0 self.process = None + self.toast_overlay = toast_overlay def compress_thread(self, *args): try: @@ -80,13 +81,14 @@ class TarWorker: if not files_to_trash is None: try: subprocess.run(['gio', 'trash'] + files_to_trash, capture_output=True, check=True) - + except Exception: pass - + self.stop = True - print("Error in cancelling:", error_str) - + if self.toast_overlay: + self.toast_overlay.add_toast(ErrorToast(_("Error in snapshot handling"), error_str).toast) + def check_size(self, check_path): try: output = subprocess.run(['du', '-s', check_path], check=True, text=True, capture_output=True).stdout.split('\t')[0]