From 5977071580763398eb215baea91a9bf4c50533c0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 26 Apr 2025 09:31:38 +0200 Subject: Allow the socket connection beiing available with different applications --- socketserver.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'socketserver.py') diff --git a/socketserver.py b/socketserver.py index 57000d8..c68915a 100755 --- a/socketserver.py +++ b/socketserver.py @@ -10,6 +10,7 @@ import socket import selectors import json +import csv from dataclasses import dataclass from typing import Callable @@ -54,9 +55,15 @@ class Handler(object): c = waitEvent() c.callback = self.accept self.sel.register(self.socket, selectors.EVENT_READ, c) - self.application_name = configuration.get("name", None) - if self.application_name is not None: - self.application_name = self.application_name.lower() + # Read the name to associate the connection with. + application_name = configuration.get("name", None) + if application_name is not None: + # Split the values using `,` as separator + reader = csv.reader([application_name]) + self.application_name = [name.lower() for name in next(reader)] + else: + self.application_name = None + self.connexions = [] self.layout_queue = layout_queue @@ -114,7 +121,7 @@ class Handler(object): try: js = json.loads(json_data) for key in js.keys(): - component.handle(Debug("Received %s from the socket" % (key))) + component.handle(Debug("Received '%s' from the socket" % (key))) except Exception as e: print("Can’t read", json_data, e) return @@ -122,18 +129,12 @@ class Handler(object): if self.application_name is not None: # As we have a name in the configuration to associate with, use # this name as a reference - title = self.application_name + for title in self.application_name: + self.layout_queue.put((js, title)) else: # Associate the layout with the current window title = component.queryUtility(desktopEvent.IDesktop).getForegroundWindowTitle() - self.layout_queue.put((js, title)) - - # The application name is hardcoded in the code, and should be reported - # in the configuration or somewhere else. - - # The name of the current application is not reliable because the - # message can be send with some lattency. - self.layout_queue.put((js, self.application_name)) + self.layout_queue.put((js, title)) def _send(self:object, conn:socket, mask:int, text) -> None: """ Internal method used to dispatch the message to the socket. """ -- cgit v1.2.3