aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsocketserver.py27
1 files changed, 14 insertions, 13 deletions
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. """