From 476c872c58783487b9a045f1d2718590e7660543 Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Sat, 8 Jul 2023 12:49:38 -0700 Subject: [PATCH] fix: added import for DBusGMainLoop --- src/ublue_update/cli.py | 13 ++++++------ src/ublue_update/notification_manager.py | 27 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index 8d49124..2b8afdf 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -1,13 +1,14 @@ import psutil -#import notify2 + import dbus +from dbus.mainloop.glib import DBusGMainLoop import os import subprocess import logging import tomllib import argparse from ublue_update.notification_manager import NotificationManager -from gi.repository import GLib + def check_cpu_load(): # get load average percentage in last 5 minutes: @@ -122,11 +123,11 @@ def run_updates(): f"Error in update script: {file}, check logs for more info", 3, ) - #notify2.Notification( + # notify2.Notification( # "System Updater", # f"Error in update script: {file}, check logs for more info", # "notification-message-im", - #).show() + # ).show() else: log.info(f"could not execute file {full_path}") @@ -145,12 +146,13 @@ def run_updates(): log = logging.getLogger(__name__) loop = GLib.MainLoop() -dbus_loop = dbus.DBusGMainLoop() +dbus_loop = DBusGMainLoop() bus = dbus.SessionBus(mainloop=dbus_loop) if dbus_notify: notification_manager = NotificationManager("Universal Blue Updater", bus) + def main(): # setup argparse @@ -166,7 +168,6 @@ def main(): ) args = parser.parse_args() - if not args.force: check_inhibitors() diff --git a/src/ublue_update/notification_manager.py b/src/ublue_update/notification_manager.py index 67fff28..2f9eeb0 100644 --- a/src/ublue_update/notification_manager.py +++ b/src/ublue_update/notification_manager.py @@ -1,43 +1,42 @@ import dbus + class NotificationManager: """Manages DBus notifications and action dispatching""" def __init__(self, app_name, bus): item = "org.freedesktop.Notifications" - path = "/"+item.replace(".", "/") + path = "/" + item.replace(".", "/") self._app_name = app_name self._actions = [] - self._notify_interface = dbus.Interface( - bus.get_object(item, path), - item - ) - bus.add_signal_receiver(self._on_action,"ActionInvoked") + self._notify_interface = dbus.Interface(self._bus.get_object(item, path), item) + bus.add_signal_receiver(self._on_action, "ActionInvoked") def get_action_list(self, actions): dbus_actions = [] for action in actions: - dbus_actions.append(action['key']) - dbus_actions.append(action['text']) + dbus_actions.append(action["key"]) + dbus_actions.append(action["text"]) return dbus_actions def add_action(self, action): self._actions.append(action) def _on_action(self, id, action_key): - triggered_action = [action for action in self._actions if action['key'] == action_key][0] - triggered_action['handler']() + triggered_action = [ + action for action in self._actions if action["key"] == action_key + ][0] + triggered_action["handler"]() def notify(self, id, title, body, timeout): actions = self.get_action_list(self._actions) self._notify_interface.Notify( self._app_name, id, - "weather-clear", # not sure what this is + "weather-clear", # not sure what this is title, body, actions, - { "urgency": 1 }, - timeout * 1000 + {"urgency": 1}, + timeout * 1000, ) -