Skip to content

Commit

Permalink
fix: added import for DBusGMainLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Jul 8, 2023
1 parent ebc387f commit 476c872
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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}")

Expand All @@ -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
Expand All @@ -166,7 +168,6 @@ def main():
)
args = parser.parse_args()


if not args.force:
check_inhibitors()

Expand Down
27 changes: 13 additions & 14 deletions src/ublue_update/notification_manager.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 476c872

Please sign in to comment.