clan-app: Add plug and play middleware interface
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
import logging
|
||||
|
||||
from clan_cli.profiler import profile
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import clan_lib.machines.actions # noqa: F401
|
||||
from clan_cli.profiler import profile
|
||||
from clan_lib.api import API, load_in_all_api_functions, tasks
|
||||
from clan_lib.custom_logger import setup_logging
|
||||
from clan_lib.dirs import user_data_dir
|
||||
@@ -15,8 +11,15 @@ from clan_lib.log_manager import LogGroupConfig, LogManager
|
||||
from clan_lib.log_manager import api as log_manager_api
|
||||
|
||||
from clan_app.api.file_gtk import open_file
|
||||
from clan_app.deps.webview.middleware import (
|
||||
ArgumentParsingMiddleware,
|
||||
LoggingMiddleware,
|
||||
MethodExecutionMiddleware,
|
||||
)
|
||||
from clan_app.deps.webview.webview import Size, SizeHint, Webview
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ClanAppOptions:
|
||||
@@ -39,9 +42,6 @@ def app_run(app_opts: ClanAppOptions) -> int:
|
||||
site_index: Path = Path(os.getenv("WEBUI_PATH", ".")).resolve() / "index.html"
|
||||
content_uri = f"file://{site_index}"
|
||||
|
||||
webview = Webview(debug=app_opts.debug)
|
||||
webview.title = "Clan App"
|
||||
|
||||
# Add a log group ["clans", <dynamic_name>, "machines", <dynamic_name>]
|
||||
log_manager = LogManager(base_dir=user_data_dir() / "clan-app" / "logs")
|
||||
clan_log_group = LogGroupConfig("clans", "Clans").add_child(
|
||||
@@ -51,15 +51,23 @@ def app_run(app_opts: ClanAppOptions) -> int:
|
||||
# Init LogManager global in log_manager_api module
|
||||
log_manager_api.LOG_MANAGER_INSTANCE = log_manager
|
||||
|
||||
# Populate the API global with all functions
|
||||
load_in_all_api_functions()
|
||||
API.overwrite_fn(open_file)
|
||||
|
||||
webview = Webview(
|
||||
debug=app_opts.debug, title="Clan App", size=Size(1280, 1024, SizeHint.NONE)
|
||||
)
|
||||
|
||||
# Add middleware to the webview
|
||||
webview.add_middleware(ArgumentParsingMiddleware(api=API))
|
||||
webview.add_middleware(LoggingMiddleware(log_manager=log_manager))
|
||||
webview.add_middleware(MethodExecutionMiddleware(api=API))
|
||||
|
||||
# Init BAKEND_THREADS global in tasks module
|
||||
tasks.BAKEND_THREADS = webview.threads
|
||||
|
||||
# Populate the API global with all functions
|
||||
load_in_all_api_functions()
|
||||
|
||||
API.overwrite_fn(open_file)
|
||||
webview.bind_jsonschema_api(API, log_manager=log_manager_api.LOG_MANAGER_INSTANCE)
|
||||
webview.size = Size(1280, 1024, SizeHint.NONE)
|
||||
webview.bind_jsonschema_api(API, log_manager=log_manager)
|
||||
webview.navigate(content_uri)
|
||||
webview.run()
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user