From 6614129f2096832bc429d2f34f2b3c3e9637cf0c Mon Sep 17 00:00:00 2001 From: 3bru <16ebruarslan@gmail.com> Date: Wed, 6 Mar 2024 16:27:18 +0300 Subject: [PATCH] conky and message written with dbus --- src/plugins/conky/execute_xmessage.py | 92 +++++++++++++++++---------- 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/src/plugins/conky/execute_xmessage.py b/src/plugins/conky/execute_xmessage.py index 12708c4..32723bf 100644 --- a/src/plugins/conky/execute_xmessage.py +++ b/src/plugins/conky/execute_xmessage.py @@ -7,7 +7,7 @@ from base.model.enum.content_type import ContentType import json from base.plugin.abstract_plugin import AbstractPlugin import threading - +import dbus class RunXMessageCommand(AbstractPlugin): def __init__(self, data, context): @@ -24,48 +24,70 @@ class RunXMessageCommand(AbstractPlugin): # command for ltsp self.custom_message_command_ltsp = "su {0} -c 'export DISPLAY={1} && export XAUTHORITY=~{2}/.Xauthority && python3 /usr/share/ahenk/plugins/conky/ask.py \"LİDER AHENK\\\ BİLDİRİ \" \"{3}\" ' " + # def execute_xmessage(self, message): + + # users = self.Sessions.user_name(); + # self.logger.debug('[XMessage] users : ' + str(users)) + + # for user in users: + # user_display = self.Sessions.display(user) + # user_ip = self.Sessions.userip(user) + + # if user_display is None: + # self.logger.debug('[XMessage] executing for display none for user ' + str(user)) + + # else: + # self.logger.debug('[XMessage] user display ' + str(user_display) + ' user ' + str(user)) + + # if user_ip is None: + # t = threading.Thread( + # target=self.execute(self.custom_message_command.format(user, user_display, user, message))) + # t.start() + + # else: + # # message format for ltsp + # self.logger.debug('user_ip: ' + str(user_ip) + ' user_display: ' + str(user_display)) + # message_list = [] + # message_parser = message.split(" ") + # self.logger.debug('running parser:--->> ' + str(message_parser)) + # for msg in message_parser: + # message = '\\\ ' + str(msg) + # message_list.append(message) + # self.logger.debug('message_list:--->> ' + str(message_list)) + # message = ''.join(str(x) for x in message_list) + # self.logger.debug('message: ' + str(message)) + # t = threading.Thread( + # target=self.execute(self.custom_message_command_ltsp.format(user, user_display, user, message), + # ip=user_ip)) + # t.start() + + # self.context.create_response(code=self.message_code.TASK_PROCESSED.value, + # message='İşlem başarıyla gerçekleştirildi.', + # data=json.dumps({'Result': message}), + # content_type=ContentType.APPLICATION_JSON.value) + def execute_xmessage(self, message): + bus = dbus.SessionBus() - users = self.Sessions.user_name(); - self.logger.debug('[XMessage] users : ' + str(users)) + service_name = "org.freedesktop.Notifications" + object_path = "/org/freedesktop/Notifications" - for user in users: - user_display = self.Sessions.display(user) - user_ip = self.Sessions.userip(user) - - if user_display is None: - self.logger.debug('[XMessage] executing for display none for user ' + str(user)) - - else: - self.logger.debug('[XMessage] user display ' + str(user_display) + ' user ' + str(user)) - - if user_ip is None: - t = threading.Thread( - target=self.execute(self.custom_message_command.format(user, user_display, user, message))) - t.start() - - else: - # message format for ltsp - self.logger.debug('user_ip: ' + str(user_ip) + ' user_display: ' + str(user_display)) - message_list = [] - message_parser = message.split(" ") - self.logger.debug('running parser:--->> ' + str(message_parser)) - for msg in message_parser: - message = '\\\ ' + str(msg) - message_list.append(message) - self.logger.debug('message_list:--->> ' + str(message_list)) - message = ''.join(str(x) for x in message_list) - self.logger.debug('message: ' + str(message)) - t = threading.Thread( - target=self.execute(self.custom_message_command_ltsp.format(user, user_display, user, message), - ip=user_ip)) - t.start() + obj = bus.get_object(service_name, object_path) + interface = dbus.Interface(obj, dbus_interface="org.freedesktop.Notifications") + app_name = "Liderahenk" + replaces_id = 0 + app_icon = "" + summary = "LİDER AHENK BİLDİRİM " + body = message + notification_id = interface.Notify(app_name, replaces_id, app_icon, summary, body, [], {}, -1) + self.logger.info("Notification sent with ID: {0}".format(notification_id)) self.context.create_response(code=self.message_code.TASK_PROCESSED.value, message='İşlem başarıyla gerçekleştirildi.', - data=json.dumps({'Result': message}), + data=json.dumps({'Result': body}), content_type=ContentType.APPLICATION_JSON.value) + def execute_user_message(self, selected_user, message): users = self.Sessions.user_name();