use app name as window title

This commit is contained in:
Aran-Fey
2024-11-14 19:59:02 +01:00
parent 59b3d86c45
commit 7ef6ac3d04
3 changed files with 23 additions and 11 deletions

View File

@@ -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.

View File

@@ -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))

View File

@@ -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);