|
@@ -67,14 +67,11 @@ def add_dependencies(py_filepath: str, dependencies: List[str] = []) -> None:
|
|
return
|
|
return
|
|
globals.dependencies[py_filepath] = dependencies
|
|
globals.dependencies[py_filepath] = dependencies
|
|
|
|
|
|
- new_dependencies: List[str] = []
|
|
|
|
-
|
|
|
|
vue_filepath = os.path.splitext(os.path.realpath(py_filepath))[0] + '.js'
|
|
vue_filepath = os.path.splitext(os.path.realpath(py_filepath))[0] + '.js'
|
|
if vue_filepath not in jp.component_file_list:
|
|
if vue_filepath not in jp.component_file_list:
|
|
filename = os.path.basename(vue_filepath)
|
|
filename = os.path.basename(vue_filepath)
|
|
jp.app.routes.insert(0, Route(f'/{filename}', lambda _: FileResponse(vue_filepath)))
|
|
jp.app.routes.insert(0, Route(f'/{filename}', lambda _: FileResponse(vue_filepath)))
|
|
jp.component_file_list += [filename]
|
|
jp.component_file_list += [filename]
|
|
- new_dependencies.append(filename)
|
|
|
|
|
|
|
|
for dependency in dependencies:
|
|
for dependency in dependencies:
|
|
is_remote = dependency.startswith('http://') or dependency.startswith('https://')
|
|
is_remote = dependency.startswith('http://') or dependency.startswith('https://')
|
|
@@ -85,19 +82,11 @@ def add_dependencies(py_filepath: str, dependencies: List[str] = []) -> None:
|
|
filepath = f'{os.path.dirname(vue_filepath)}/{src}'
|
|
filepath = f'{os.path.dirname(vue_filepath)}/{src}'
|
|
route = Route(f'/{src}', lambda _, filepath=filepath: FileResponse(filepath))
|
|
route = Route(f'/{src}', lambda _, filepath=filepath: FileResponse(filepath))
|
|
jp.app.routes.insert(0, route)
|
|
jp.app.routes.insert(0, route)
|
|
- new_dependencies.append(src)
|
|
|
|
|
|
|
|
if asyncio.get_event_loop().is_running():
|
|
if asyncio.get_event_loop().is_running():
|
|
- create_task(inject_dependencies(new_dependencies))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-async def inject_dependencies(dependencies: List[str]) -> None:
|
|
|
|
- for page in get_current_view().pages.values():
|
|
|
|
- assert isinstance(page, Page)
|
|
|
|
- for src in dependencies:
|
|
|
|
- await page.await_javascript(f'''
|
|
|
|
- let script = document.createElement("script");
|
|
|
|
- script.src = "{src}";
|
|
|
|
- document.body.append(script);
|
|
|
|
- ''')
|
|
|
|
- await page.update()
|
|
|
|
|
|
+ # NOTE: if new dependencies are added after starting the server, we need to reload the page on connected clients
|
|
|
|
+ async def reload() -> None:
|
|
|
|
+ for page in get_current_view().pages.values():
|
|
|
|
+ assert isinstance(page, Page)
|
|
|
|
+ await page.await_javascript('location.reload()')
|
|
|
|
+ create_task(reload())
|