fix: try to fix error on update on computer switch off
This commit is contained in:
36
lib/ui.py
36
lib/ui.py
@ -59,6 +59,13 @@ class UpdaterWindow(Adw.ApplicationWindow):
|
||||
self.pending_group.set_description(
|
||||
"Ces paquets seront installés automatiquement à la prochaine extinction du PC"
|
||||
)
|
||||
|
||||
self.install_now_btn = Gtk.Button.new_with_label("Installer maintenant")
|
||||
self.install_now_btn.add_css_class("suggested-action")
|
||||
self.install_now_btn.add_css_class("pill")
|
||||
self.install_now_btn.connect("clicked", self._on_install_pending_clicked)
|
||||
self.pending_group.set_header_suffix(self.install_now_btn)
|
||||
|
||||
main_box.append(self.pending_group)
|
||||
|
||||
# Groupe "Récemment installées"
|
||||
@ -233,6 +240,10 @@ class UpdaterWindow(Adw.ApplicationWindow):
|
||||
pass
|
||||
self.status_sub_lbl.set_text(sub)
|
||||
|
||||
# ── Bouton "Installer maintenant" ────────────────────────────────
|
||||
can_install = status in ("idle", "error") and bool(pending)
|
||||
self.install_now_btn.set_sensitive(can_install)
|
||||
|
||||
# ── Liste des paquets en attente de redémarrage ──────────────────
|
||||
for row in self._pending_rows:
|
||||
self.pending_group.remove(row)
|
||||
@ -306,6 +317,31 @@ class UpdaterWindow(Adw.ApplicationWindow):
|
||||
self.refresh_btn.set_sensitive(False)
|
||||
threading.Thread(target=self._send_check_now, daemon=True).start()
|
||||
|
||||
def _on_install_pending_clicked(self, _btn):
|
||||
self.install_now_btn.set_sensitive(False)
|
||||
threading.Thread(target=self._send_install_pending, daemon=True).start()
|
||||
|
||||
def _send_install_pending(self):
|
||||
try:
|
||||
s = sock_module.socket(sock_module.AF_UNIX, sock_module.SOCK_STREAM)
|
||||
s.settimeout(5)
|
||||
s.connect(str(SOCKET_PATH))
|
||||
s.sendall(json.dumps({"action": "install_pending"}).encode())
|
||||
s.recv(1024)
|
||||
s.close()
|
||||
except PermissionError:
|
||||
GLib.idle_add(
|
||||
self._show_toast,
|
||||
"Permission refusée — êtes-vous dans le groupe wheel ?",
|
||||
)
|
||||
GLib.idle_add(self.install_now_btn.set_sensitive, True)
|
||||
except Exception as e:
|
||||
GLib.idle_add(
|
||||
self._show_toast,
|
||||
f"Impossible de contacter le service : {e}",
|
||||
)
|
||||
GLib.idle_add(self.install_now_btn.set_sensitive, True)
|
||||
|
||||
def _send_check_now(self):
|
||||
try:
|
||||
s = sock_module.socket(sock_module.AF_UNIX, sock_module.SOCK_STREAM)
|
||||
|
||||
Reference in New Issue
Block a user