clan-app: Add cancellable tasks
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../webview-lib"
|
||||
},
|
||||
{
|
||||
"path": "../clan-cli/clan_lib"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
|
||||
17
pkgs/clan-app/clan_app/api/cancel.py
Normal file
17
pkgs/clan-app/clan_app/api/cancel.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import logging
|
||||
|
||||
from clan_lib.api import ErrorDataClass, SuccessDataClass
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def cancel_task(
|
||||
task_id: str, *, op_key: str
|
||||
) -> SuccessDataClass[None] | ErrorDataClass:
|
||||
"""Cancel a task by its op_key."""
|
||||
log.info(f"Cancelling task with op_key: {task_id}")
|
||||
return SuccessDataClass(
|
||||
op_key=op_key,
|
||||
data=None,
|
||||
status="success",
|
||||
)
|
||||
@@ -12,6 +12,7 @@ from pathlib import Path
|
||||
from clan_cli.custom_logger import setup_logging
|
||||
from clan_lib.api import API
|
||||
|
||||
from clan_app.api.cancel import cancel_task
|
||||
from clan_app.api.file_gtk import open_file
|
||||
from clan_app.deps.webview.webview import Size, SizeHint, Webview
|
||||
|
||||
@@ -42,6 +43,8 @@ def app_run(app_opts: ClanAppOptions) -> int:
|
||||
webview = Webview(debug=app_opts.debug)
|
||||
|
||||
API.overwrite_fn(open_file)
|
||||
# breakpoint()
|
||||
API.overwrite_fn(cancel_task)
|
||||
webview.bind_jsonschema_api(API)
|
||||
webview.size = Size(1280, 1024, SizeHint.NONE)
|
||||
webview.navigate(content_uri)
|
||||
|
||||
@@ -113,6 +113,7 @@ class Webview:
|
||||
reconciled_arguments["op_key"] = seq.decode()
|
||||
# TODO: We could remove the wrapper in the MethodRegistry
|
||||
# and just call the method directly
|
||||
|
||||
result = wrap_method(**reconciled_arguments)
|
||||
|
||||
serialized = json.dumps(
|
||||
|
||||
Reference in New Issue
Block a user