mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 07:27:18 +00:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from tfw.internals.networking import Scope
|
|
|
|
from .message_storage import FrontendMessageStorage
|
|
|
|
|
|
class FrontendHandler:
|
|
# 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'
|
|
# ]
|
|
keys = ['console', 'dashboard', 'message', 'ide.read', 'recover']
|
|
|
|
def __init__(self):
|
|
self.connector = None
|
|
self._frontend_message_storage = FrontendMessageStorage()
|
|
|
|
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()
|
|
if self._filter_message(message):
|
|
self.send_message(message)
|
|
|
|
@staticmethod
|
|
def _filter_message(message):
|
|
return not message['key'].startswith('ide')
|
|
|
|
def recover_frontend(self):
|
|
for message in self._frontend_message_storage.messages:
|
|
self.send_message(message)
|