diff --git a/rio/cli/run_project/arbiter.py b/rio/cli/run_project/arbiter.py index d6e49984..58d4fd8c 100644 --- a/rio/cli/run_project/arbiter.py +++ b/rio/cli/run_project/arbiter.py @@ -374,7 +374,8 @@ class Arbiter: ) rio.cli._logger.debug("Starting the webview worker") - self._webview_worker.run() + assert self._uvicorn_worker is not None + self._webview_worker.run(self._uvicorn_worker.app_server.app) # If not running in a webview, just wait else: @@ -760,6 +761,9 @@ window.setConnectionLostPopupVisible(true); # Replace the app which is currently hosted by uvicorn self._uvicorn_worker.replace_app(new_app_server) + if self._webview_worker is not None: + self._webview_worker.update_window_for_app(new_app_server.app) + # The app has changed, but the uvicorn server is still the same. # Because of this, uvicorn won't call the `on_app_start` function - # do it manually. diff --git a/rio/cli/run_project/webview_worker.py b/rio/cli/run_project/webview_worker.py index e9cd0eac..9d83503d 100644 --- a/rio/cli/run_project/webview_worker.py +++ b/rio/cli/run_project/webview_worker.py @@ -2,6 +2,8 @@ import threading import time import typing as t +import rio + from . import run_models @@ -22,7 +24,7 @@ class WebViewWorker: # If running, this is the webview window self.window: webview_shim.Window | None = None - def run(self) -> None: + def run(self, initial_app: rio.App) -> None: """ Starts the worker and blocks until the window is closed or `request_stop` is called. This function must be called from the main @@ -39,8 +41,7 @@ class WebViewWorker: # Create the window self.window = webview_shim.create_window( - # TODO: Get the app's name, if possible - "Rio (debug)" if self.debug_mode else "Rio", + title=self._title_for_app(initial_app), url=self.url, ) webview_shim.start() @@ -70,3 +71,12 @@ class WebViewWorker: # Success. Make sure to forget the window. else: self.window = None + + def _title_for_app(self, app: rio.App) -> str: + return app.name + (" (debug)" if self.debug_mode else "") + + def update_window_for_app(self, app: rio.App) -> None: + if self.window is None: + return + + self.window.set_title(self._title_for_app(app)) diff --git a/rio/session.py b/rio/session.py index b0528fc2..8c950c33 100644 --- a/rio/session.py +++ b/rio/session.py @@ -516,19 +516,17 @@ class Session(unicall.Unicall): # self._is_maximized = is_maximized # self.create_task(self._set_maximized(is_maximized)) - async def _set_maximized(self, is_maximized: bool) -> None: + async def _set_maximized(self, maximized: bool) -> None: if self.running_in_window: window = await self._get_webview_window() - if is_maximized: - # Pyright has trouble with the `maximize` method, though it most - # definitely exists. - window.maximize() # type: ignore + if maximized: + window.maximize() else: raise NotImplementedError # FIXME else: - if is_maximized: - await self._evaluate_javascript_and_get_result( + if maximized: + await self._evaluate_javascript( """ window.moveTo(0, 0); window.resizeTo(screen.availWidth, screen.availHeight);