diff options
Diffstat (limited to 'socketserver.py')
-rwxr-xr-x | socketserver.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/socketserver.py b/socketserver.py index fb71d6d..471b8be 100755 --- a/socketserver.py +++ b/socketserver.py @@ -9,6 +9,7 @@ import socket
import selectors
+import json
from dataclasses import dataclass
from typing import Callable
@@ -52,7 +53,9 @@ class Handler(object): c = waitEvent()
c.callback = self.accept
self.sel.register(self.socket, selectors.EVENT_READ, c)
- self.application_name = configuration["name"].lower()
+ self.application_name = configuration.get("name", None)
+ if self.application_name is not None:
+ self.application_name = self.application_name.lower()
self.connexions = []
self.layout_queue = layout_queue
@@ -106,23 +109,21 @@ class Handler(object): # A socket ready but sending garbage is a dead socket.
self.close(conn)
return
- last_layout = str(data, "utf-8")
+ json_data = str(data, "utf-8")
try:
- js = json.loads(last_layout)[-1]
- for key, value in js.items():
- last_layout = actions[key](value)
- except:
- print(last_layout)
-
- #title = component.queryUtility(desktopEvent.IDesktop).getForegroundWindowTitle()
- # 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.
- component.handle(Debug("Received %s from the socket" % (last_layout)))
+ js = json.loads(json_data)
+ for key in js.keys():
+ component.handle(Debug("Received %s from the socket" % (key)))
+ except Exception as e:
+ print("Can’t read", json_data, e)
+ return
- # Associate the layout with the current window
- self.layout_queue.put((last_layout, self.application_name))
+ if self.application_name is not None:
+ title = self.application_name
+ else:
+ # Associate the layout with the current window
+ title = component.queryUtility(desktopEvent.IDesktop).getForegroundWindowTitle()
+ 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. """
|