mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 08:27:18 +00:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from tfw.internals.networking import Scope
|
|
|
|
from .message_storage import FrontendMessageStorage
|
|
|
|
|
|
class FrontendHandler:
|
|
# TODO: do not store dashboard messages like reloadFrontend
|
|
keys = [
|
|
'console.read',
|
|
'console.write',
|
|
'console.showLiveLogs',
|
|
'console.rewriteContentWithProcessLogsOnDeploy',
|
|
'dashboard.layout',
|
|
'dashboard.hideMessages',
|
|
'dashboard.terminalMenuItem',
|
|
'dashboard.reloadFrontend',
|
|
'dashboard.reloadIframe',
|
|
'message.config',
|
|
'message.queue',
|
|
'message.send'
|
|
]
|
|
|
|
def __init__(self):
|
|
self.connector = None
|
|
self.keys = [*type(self).keys, 'recover']
|
|
self._frontend_message_storage = FrontendMessageStorage(type(self).keys)
|
|
|
|
def send_message(self, message):
|
|
self.connector.send_message(message, scope=Scope.WEBSOCKET)
|
|
|
|
def handle_event(self, message, _):
|
|
self._frontend_message_storage.save_message(message)
|
|
if message['key'] == 'recover':
|
|
self.recover_frontend()
|
|
self.send_message(message)
|
|
|
|
def recover_frontend(self):
|
|
for message in self._frontend_message_storage.messages:
|
|
self.send_message(message)
|