clan-app: Moved thread handling up to the ApiBridge

This commit is contained in:
Qubasa
2025-07-10 12:02:30 +07:00
parent dbe40e6f5b
commit 70f7f7e676
8 changed files with 94 additions and 61 deletions

View File

@@ -58,6 +58,10 @@ def app_run(app_opts: ClanAppOptions) -> int:
load_in_all_api_functions()
API.overwrite_fn(open_file)
# Create a shared threads dictionary for both HTTP and Webview modes
shared_threads = {}
tasks.BAKEND_THREADS = shared_threads
# Start HTTP API server if requested
http_server = None
if app_opts.http_api:
@@ -72,6 +76,7 @@ def app_run(app_opts: ClanAppOptions) -> int:
swagger_dist=Path(swagger_dist) if swagger_dist else None,
host=app_opts.http_host,
port=app_opts.http_port,
shared_threads=shared_threads,
)
# Add middleware to HTTP server
@@ -103,7 +108,10 @@ def app_run(app_opts: ClanAppOptions) -> int:
# Create webview if not running in HTTP-only mode
if not app_opts.http_api:
webview = Webview(
debug=app_opts.debug, title="Clan App", size=Size(1280, 1024, SizeHint.NONE)
debug=app_opts.debug,
title="Clan App",
size=Size(1280, 1024, SizeHint.NONE),
shared_threads=shared_threads,
)
# Add middleware to the webview
@@ -111,12 +119,6 @@ def app_run(app_opts: ClanAppOptions) -> int:
webview.add_middleware(LoggingMiddleware(log_manager=log_manager))
webview.add_middleware(MethodExecutionMiddleware(api=API))
# Create the bridge
webview.create_bridge()
# Init BAKEND_THREADS global in tasks module
tasks.BAKEND_THREADS = webview.threads
webview.bind_jsonschema_api(API, log_manager=log_manager)
webview.navigate(content_uri)
webview.run()