All checks were successful
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
checks / checks-impure (pull_request) Successful in 2m19s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
151 lines
4.0 KiB
Python
151 lines
4.0 KiB
Python
import logging
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "4.0")
|
|
gi.require_version("Adw", "1")
|
|
|
|
from gi.repository import Adw
|
|
|
|
from clan_app.singletons.use_views import ViewStack
|
|
from clan_app.views.logs import Logs
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class ToastOverlay:
|
|
"""
|
|
The ToastOverlay is a class that manages the display of toasts
|
|
It should be used as a singleton in your application to prevent duplicate toasts
|
|
Usage
|
|
"""
|
|
|
|
# For some reason, the adw toast overlay cannot be subclassed
|
|
# Thats why it is added as a class property
|
|
overlay: Adw.ToastOverlay
|
|
active_toasts: set[str]
|
|
|
|
_instance: "None | ToastOverlay" = None
|
|
|
|
def __init__(self) -> None:
|
|
raise RuntimeError("Call use() instead")
|
|
|
|
@classmethod
|
|
def use(cls: Any) -> "ToastOverlay":
|
|
if cls._instance is None:
|
|
cls._instance = cls.__new__(cls)
|
|
cls.overlay = Adw.ToastOverlay()
|
|
cls.active_toasts = set()
|
|
|
|
return cls._instance
|
|
|
|
def add_toast_unique(self, toast: Adw.Toast, key: str) -> None:
|
|
if key not in self.active_toasts:
|
|
self.active_toasts.add(key)
|
|
self.overlay.add_toast(toast)
|
|
toast.connect("dismissed", lambda toast: self.active_toasts.remove(key))
|
|
|
|
|
|
class ErrorToast:
|
|
toast: Adw.Toast
|
|
|
|
def __init__(
|
|
self, message: str, persistent: bool = False, details: str = ""
|
|
) -> None:
|
|
super().__init__()
|
|
self.toast = Adw.Toast.new(
|
|
f"""<span foreground='red'>❌ Error </span> {message}"""
|
|
)
|
|
self.toast.set_use_markup(True)
|
|
|
|
self.toast.set_priority(Adw.ToastPriority.HIGH)
|
|
self.toast.set_button_label("Show more")
|
|
|
|
if persistent:
|
|
self.toast.set_timeout(0)
|
|
|
|
views = ViewStack.use().view
|
|
|
|
# we cannot check this type, python is not smart enough
|
|
logs_view: Logs = views.get_child_by_name("logs") # type: ignore
|
|
logs_view.set_message(details)
|
|
|
|
self.toast.connect(
|
|
"button-clicked",
|
|
lambda _: views.set_visible_child_name("logs"),
|
|
)
|
|
|
|
|
|
class WarningToast:
|
|
toast: Adw.Toast
|
|
|
|
def __init__(self, message: str, persistent: bool = False) -> None:
|
|
super().__init__()
|
|
self.toast = Adw.Toast.new(
|
|
f"<span foreground='orange'>⚠ Warning </span> {message}"
|
|
)
|
|
self.toast.set_use_markup(True)
|
|
|
|
self.toast.set_priority(Adw.ToastPriority.NORMAL)
|
|
|
|
if persistent:
|
|
self.toast.set_timeout(0)
|
|
|
|
|
|
class InfoToast:
|
|
toast: Adw.Toast
|
|
|
|
def __init__(self, message: str, persistent: bool = False) -> None:
|
|
super().__init__()
|
|
self.toast = Adw.Toast.new(f"<span>❕</span> {message}")
|
|
self.toast.set_use_markup(True)
|
|
|
|
self.toast.set_priority(Adw.ToastPriority.NORMAL)
|
|
|
|
if persistent:
|
|
self.toast.set_timeout(0)
|
|
|
|
|
|
class SuccessToast:
|
|
toast: Adw.Toast
|
|
|
|
def __init__(self, message: str, persistent: bool = False) -> None:
|
|
super().__init__()
|
|
self.toast = Adw.Toast.new(f"<span foreground='green'>✅</span> {message}")
|
|
self.toast.set_use_markup(True)
|
|
|
|
self.toast.set_priority(Adw.ToastPriority.NORMAL)
|
|
|
|
if persistent:
|
|
self.toast.set_timeout(0)
|
|
|
|
|
|
class LogToast:
|
|
toast: Adw.Toast
|
|
|
|
def __init__(
|
|
self,
|
|
message: str,
|
|
on_button_click: Callable[[], None],
|
|
button_label: str = "More",
|
|
persistent: bool = False,
|
|
) -> None:
|
|
super().__init__()
|
|
self.toast = Adw.Toast.new(
|
|
f"""Logs are available <span weight="regular">{message}</span>"""
|
|
)
|
|
self.toast.set_use_markup(True)
|
|
|
|
self.toast.set_priority(Adw.ToastPriority.NORMAL)
|
|
|
|
if persistent:
|
|
self.toast.set_timeout(0)
|
|
|
|
self.toast.set_button_label(button_label)
|
|
self.toast.connect(
|
|
"button-clicked",
|
|
lambda _: on_button_click(),
|
|
)
|