40
40
over the GUI message bus.
41
41
"""
42
42
import shutil
43
- from os import makedirs
44
43
from os .path import join , dirname , isfile , exists
45
44
from threading import Event , Lock , Timer
46
45
from typing import List , Union , Optional , Dict
47
46
48
47
from ovos_config .config import Configuration
49
- from ovos_utils .log import LOG , log_deprecation
48
+ from ovos_utils .log import LOG
50
49
51
50
from ovos_bus_client import Message , MessageBusClient
52
51
from ovos_gui .bus import (
57
56
)
58
57
from ovos_gui .gui_file_server import start_gui_http_server
59
58
from ovos_gui .page import GuiPage
60
-
59
+ from ovos_gui . constants import GUI_CACHE_PATH
61
60
namespace_lock = Lock ()
62
61
63
62
RESERVED_KEYS = ['__from' , '__idle' ]
@@ -433,9 +432,6 @@ def __init__(self, core_bus: MessageBusClient):
433
432
self ._system_res_dir = join (dirname (__file__ ), "res" , "gui" )
434
433
self ._ready_event = Event ()
435
434
self .gui_file_server = None
436
- self .gui_file_path = None # HTTP Server local path
437
- self .gui_file_host_path = None # Docker host path
438
- self ._connected_frameworks : List [str ] = list ()
439
435
self ._init_gui_file_share ()
440
436
self ._define_message_handlers ()
441
437
@@ -450,20 +446,10 @@ def _init_gui_file_share(self):
450
446
If `gui_file_server` is defined, resources will be served via HTTP
451
447
"""
452
448
config = Configuration ().get ("gui" , {})
453
- self .gui_file_host_path = config .get ("gui_file_host_path" )
454
-
455
- # Check for GUI file sharing via HTTP server or mounted host path
456
- if config .get ("gui_file_server" ) or self .gui_file_host_path :
457
- from ovos_utils .xdg_utils import xdg_cache_home
458
- if config .get ("server_path" ):
459
- log_deprecation ("`server_path` configuration is deprecated. "
460
- "Files will always be saved to "
461
- "XDG_CACHE_HOME/ovos_gui_file_server" , "0.1.0" )
462
- self .gui_file_path = config .get ("server_path" ) or \
463
- join (xdg_cache_home (), "ovos_gui_file_server" )
464
- if config .get ("gui_file_server" ):
465
- self .gui_file_server = start_gui_http_server (self .gui_file_path )
466
- self ._upload_system_resources ()
449
+ # Check for GUI file sharing via HTTP server
450
+ if config .get ("gui_file_server" ):
451
+ self .gui_file_server = start_gui_http_server (GUI_CACHE_PATH )
452
+ self ._cache_system_resources ()
467
453
468
454
def _define_message_handlers (self ):
469
455
"""
@@ -474,7 +460,6 @@ def _define_message_handlers(self):
474
460
self .core_bus .on ("gui.page.delete" , self .handle_delete_page )
475
461
self .core_bus .on ("gui.page.delete.all" , self .handle_delete_all_pages )
476
462
self .core_bus .on ("gui.page.show" , self .handle_show_page )
477
- self .core_bus .on ("gui.page.upload" , self .handle_receive_gui_pages )
478
463
self .core_bus .on ("gui.status.request" , self .handle_status_request )
479
464
self .core_bus .on ("gui.value.set" , self .handle_set_value )
480
465
self .core_bus .on ("mycroft.gui.connected" , self .handle_client_connected )
@@ -485,68 +470,6 @@ def _define_message_handlers(self):
485
470
486
471
def handle_ready (self , message ):
487
472
self ._ready_event .set ()
488
- self .core_bus .on ("gui.volunteer_page_upload" ,
489
- self .handle_gui_pages_available )
490
-
491
- def handle_gui_pages_available (self , message : Message ):
492
- """
493
- Handle a skill or plugin advertising that it has GUI pages available to
494
- upload. If there are connected clients, request pages for each connected
495
- GUI framework.
496
- @param message: `gui.volunteer_page_upload` message
497
- """
498
- if not any ((self .gui_file_host_path , self .gui_file_server )):
499
- LOG .debug ("No GUI file server running or host path configured" )
500
- return
501
-
502
- LOG .debug (f"Requesting resources for { self ._connected_frameworks } " )
503
- for framework in self ._connected_frameworks :
504
- skill_id = message .data .get ("skill_id" )
505
- self .core_bus .emit (message .reply ("gui.request_page_upload" ,
506
- {'skill_id' : skill_id ,
507
- 'framework' : framework },
508
- {"source" : "gui" ,
509
- "destination" : ["skills" ,
510
- "PHAL" ]}))
511
-
512
- def handle_receive_gui_pages (self , message : Message ):
513
- """
514
- Handle GUI resources from a skill or plugin. Pages are written to
515
- `self.server_path` which is accessible via a lightweight HTTP server and
516
- may additionally be mounted to a host path/volume in container setups.
517
- @param message: Message containing UI resource file contents and meta
518
- message.data:
519
- pages: dict page_filename to encoded bytes content;
520
- paths are relative to the `framework` directory, so a page
521
- for framework `all` could be `qt5/subdir/file.qml` and the
522
- equivalent page for framework `qt5` would be
523
- `subdir/file.qml`
524
- framework: `all` if all GUI resources are included, else the
525
- specific GUI framework (i.e. `qt5`, `qt6`)
526
- __from: skill_id of module uploading GUI resources
527
- """
528
- for page , contents in message .data ["pages" ].items ():
529
- try :
530
- if message .data .get ("framework" ) == "all" :
531
- # All GUI resources are uploaded
532
- resource_base_path = join (self .gui_file_path ,
533
- message .data ['__from' ])
534
- else :
535
- resource_base_path = join (self .gui_file_path ,
536
- message .data ['__from' ],
537
- message .data .get ('framework' ) or
538
- "qt5" )
539
- byte_contents = bytes .fromhex (contents )
540
- file_path = join (resource_base_path , page )
541
- LOG .debug (f"writing UI file: { file_path } " )
542
- makedirs (dirname (file_path ), exist_ok = True )
543
- with open (file_path , 'wb+' ) as f :
544
- f .write (byte_contents )
545
- except Exception as e :
546
- LOG .exception (f"Failed to write { page } : { e } " )
547
- if message .data ["__from" ] == self ._active_homescreen :
548
- # Configured home screen skill just uploaded pages, show it again
549
- self .core_bus .emit (message .forward ("homescreen.manager.show_active" ))
550
473
551
474
def handle_clear_namespace (self , message : Message ):
552
475
"""
@@ -952,23 +875,9 @@ def handle_client_connected(self, message: Message):
952
875
websocket_config = get_gui_websocket_config ()
953
876
port = websocket_config ["base_port" ]
954
877
message = message .forward ("mycroft.gui.port" ,
955
- dict (port = port , gui_id = gui_id ))
878
+ dict (port = port , gui_id = gui_id , framework = framework ))
956
879
self .core_bus .emit (message )
957
880
958
- if self .gui_file_path or self .gui_file_host_path :
959
- if not self ._ready_event .wait (90 ):
960
- LOG .warning ("Not reported ready after 90s" )
961
- if framework not in self ._connected_frameworks :
962
- LOG .debug (f"Requesting page upload for { framework } " )
963
- self .core_bus .emit (Message ("gui.request_page_upload" ,
964
- {'framework' : framework },
965
- {"source" : "gui" ,
966
- "destination" : ["skills" , "PHAL" ]}))
967
-
968
- if framework not in self ._connected_frameworks :
969
- LOG .debug (f"Connecting framework: { framework } " )
970
- self ._connected_frameworks .append (framework )
971
-
972
881
def handle_page_interaction (self , message : Message ):
973
882
"""
974
883
Handles an event from the GUI indicating a page has been interacted with.
@@ -1037,13 +946,13 @@ def _del_namespace_in_remove_timers(self, namespace_name: str):
1037
946
if namespace_name in self .remove_namespace_timers :
1038
947
del self .remove_namespace_timers [namespace_name ]
1039
948
1040
- def _upload_system_resources (self ):
949
+ def _cache_system_resources (self ):
1041
950
"""
1042
951
Copy system GUI resources to the served file path
1043
952
"""
1044
- output_path = join ( self . gui_file_path , " system")
953
+ output_path = f" { GUI_CACHE_PATH } / system"
1045
954
if exists (output_path ):
1046
955
LOG .info (f"Removing existing system resources before updating" )
1047
956
shutil .rmtree (output_path )
1048
957
shutil .copytree (self ._system_res_dir , output_path )
1049
- LOG .debug (f"Copied system resources to { self .gui_file_path } " )
958
+ LOG .debug (f"Copied system resources from { self ._system_res_dir } to { output_path } " )
0 commit comments