webview-lib: Moved repo to gitea, updated revision. Removed set_icon
This commit is contained in:
@@ -88,9 +88,6 @@ class _WebviewLibrary:
|
|||||||
self.webview_set_title = self.lib.webview_set_title
|
self.webview_set_title = self.lib.webview_set_title
|
||||||
self.webview_set_title.argtypes = [c_void_p, c_char_p]
|
self.webview_set_title.argtypes = [c_void_p, c_char_p]
|
||||||
|
|
||||||
self.webview_set_icon = self.lib.webview_set_icon
|
|
||||||
self.webview_set_icon.argtypes = [c_void_p, c_char_p]
|
|
||||||
|
|
||||||
self.webview_set_size = self.lib.webview_set_size
|
self.webview_set_size = self.lib.webview_set_size
|
||||||
self.webview_set_size.argtypes = [c_void_p, c_int, c_int, c_int]
|
self.webview_set_size.argtypes = [c_void_p, c_int, c_int, c_int]
|
||||||
|
|
||||||
@@ -112,6 +109,10 @@ class _WebviewLibrary:
|
|||||||
self.webview_return = self.lib.webview_return
|
self.webview_return = self.lib.webview_return
|
||||||
self.webview_return.argtypes = [c_void_p, c_char_p, c_int, c_char_p]
|
self.webview_return.argtypes = [c_void_p, c_char_p, c_int, c_char_p]
|
||||||
|
|
||||||
|
self.binding_callback_t = CFUNCTYPE(
|
||||||
|
None, c_char_p, c_char_p, c_void_p
|
||||||
|
)
|
||||||
|
|
||||||
self.CFUNCTYPE = CFUNCTYPE
|
self.CFUNCTYPE = CFUNCTYPE
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import ctypes
|
|
||||||
import functools
|
import functools
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -16,6 +14,7 @@ from clan_lib.api import (
|
|||||||
dataclass_to_dict,
|
dataclass_to_dict,
|
||||||
from_dict,
|
from_dict,
|
||||||
)
|
)
|
||||||
|
from clan_lib.api.tasks import WebThread
|
||||||
from clan_lib.async_run import AsyncContext, get_async_ctx, set_async_ctx
|
from clan_lib.async_run import AsyncContext, get_async_ctx, set_async_ctx
|
||||||
from clan_lib.custom_logger import setup_logging
|
from clan_lib.custom_logger import setup_logging
|
||||||
from clan_lib.log_manager import LogManager
|
from clan_lib.log_manager import LogManager
|
||||||
@@ -44,12 +43,6 @@ class Size:
|
|||||||
self.hint = hint
|
self.hint = hint
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class WebThread:
|
|
||||||
thread: threading.Thread
|
|
||||||
stop_event: threading.Event
|
|
||||||
|
|
||||||
|
|
||||||
class Webview:
|
class Webview:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, debug: bool = False, size: Size | None = None, window: int | None = None
|
self, debug: bool = False, size: Size | None = None, window: int | None = None
|
||||||
@@ -74,20 +67,22 @@ class Webview:
|
|||||||
op_key = op_key_bytes.decode()
|
op_key = op_key_bytes.decode()
|
||||||
args = json.loads(request_data.decode())
|
args = json.loads(request_data.decode())
|
||||||
log.debug(f"Calling {method_name}({args[0]})")
|
log.debug(f"Calling {method_name}({args[0]})")
|
||||||
|
metadata: dict[str, Any] = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Initialize dataclasses from the payload
|
# Initialize dataclasses from the payload
|
||||||
reconciled_arguments = {}
|
reconciled_arguments = {}
|
||||||
for k, v in args[0].items():
|
if len(args) > 0:
|
||||||
# Some functions expect to be called with dataclass instances
|
for k, v in args[0].items():
|
||||||
# But the js api returns dictionaries.
|
# Some functions expect to be called with dataclass instances
|
||||||
# Introspect the function and create the expected dataclass from dict dynamically
|
# But the js api returns dictionaries.
|
||||||
# Depending on the introspected argument_type
|
# Introspect the function and create the expected dataclass from dict dynamically
|
||||||
arg_class = api.get_method_argtype(method_name, k)
|
# Depending on the introspected argument_type
|
||||||
|
arg_class = api.get_method_argtype(method_name, k)
|
||||||
|
|
||||||
# TODO: rename from_dict into something like construct_checked_value
|
# TODO: rename from_dict into something like construct_checked_value
|
||||||
# from_dict really takes Anything and returns an instance of the type/class
|
# from_dict really takes Anything and returns an instance of the type/class
|
||||||
reconciled_arguments[k] = from_dict(arg_class, v)
|
reconciled_arguments[k] = from_dict(arg_class, v)
|
||||||
|
|
||||||
reconciled_arguments["op_key"] = op_key
|
reconciled_arguments["op_key"] = op_key
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -112,8 +107,16 @@ class Webview:
|
|||||||
def thread_task(stop_event: threading.Event) -> None:
|
def thread_task(stop_event: threading.Event) -> None:
|
||||||
ctx: AsyncContext = get_async_ctx()
|
ctx: AsyncContext = get_async_ctx()
|
||||||
ctx.should_cancel = lambda: stop_event.is_set()
|
ctx.should_cancel = lambda: stop_event.is_set()
|
||||||
|
# If the API call has set log_group in metadata,
|
||||||
|
# create the log file under that group.
|
||||||
|
log_group = metadata.get("logging", {}).get("group", None)
|
||||||
|
if log_group is not None:
|
||||||
|
log.warning(
|
||||||
|
f"Using log group {log_group} for {method_name} with op_key {op_key}"
|
||||||
|
)
|
||||||
|
breakpoint()
|
||||||
log_file = log_manager.create_log_file(
|
log_file = log_manager.create_log_file(
|
||||||
wrap_method, op_key=op_key
|
wrap_method, op_key=op_key, group=log_group
|
||||||
).get_file_path()
|
).get_file_path()
|
||||||
|
|
||||||
with log_file.open("ab") as log_f:
|
with log_file.open("ab") as log_f:
|
||||||
@@ -129,7 +132,6 @@ class Webview:
|
|||||||
handler = setup_logging(
|
handler = setup_logging(
|
||||||
log.getEffectiveLevel(), log_file=handler_stream
|
log.getEffectiveLevel(), log_file=handler_stream
|
||||||
)
|
)
|
||||||
log.info("Starting thread for webview API call")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Original logic: call the wrapped API method.
|
# Original logic: call the wrapped API method.
|
||||||
@@ -204,14 +206,6 @@ class Webview:
|
|||||||
_webview_lib.webview_set_title(self._handle, _encode_c_string(value))
|
_webview_lib.webview_set_title(self._handle, _encode_c_string(value))
|
||||||
self._title = value
|
self._title = value
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@icon.setter
|
|
||||||
def icon(self, value: str) -> None:
|
|
||||||
_webview_lib.webview_set_icon(self._handle, _encode_c_string(value))
|
|
||||||
self._icon = value
|
|
||||||
|
|
||||||
def destroy(self) -> None:
|
def destroy(self) -> None:
|
||||||
for name in list(self._callbacks.keys()):
|
for name in list(self._callbacks.keys()):
|
||||||
@@ -237,9 +231,7 @@ class Webview:
|
|||||||
name,
|
name,
|
||||||
method,
|
method,
|
||||||
)
|
)
|
||||||
c_callback = _webview_lib.CFUNCTYPE(
|
c_callback = _webview_lib.binding_callback_t(wrapper)
|
||||||
None, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p
|
|
||||||
)(wrapper)
|
|
||||||
|
|
||||||
if name in self._callbacks:
|
if name in self._callbacks:
|
||||||
msg = f"Callback {name} already exists. Skipping binding."
|
msg = f"Callback {name} already exists. Skipping binding."
|
||||||
@@ -261,9 +253,7 @@ class Webview:
|
|||||||
success = False
|
success = False
|
||||||
self.return_(seq.decode(), 0 if success else 1, json.dumps(result))
|
self.return_(seq.decode(), 0 if success else 1, json.dumps(result))
|
||||||
|
|
||||||
c_callback = _webview_lib.CFUNCTYPE(
|
c_callback = _webview_lib.binding_callback_t(wrapper)
|
||||||
None, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p
|
|
||||||
)(wrapper)
|
|
||||||
self._callbacks[name] = c_callback
|
self._callbacks[name] = c_callback
|
||||||
_webview_lib.webview_bind(
|
_webview_lib.webview_bind(
|
||||||
self._handle, _encode_c_string(name), c_callback, None
|
self._handle, _encode_c_string(name), c_callback, None
|
||||||
|
|||||||
@@ -8,13 +8,23 @@ pkgs.clangStdenv.mkDerivation {
|
|||||||
# We disallow remote connections from the UI on Linux
|
# We disallow remote connections from the UI on Linux
|
||||||
# TODO: Disallow remote connections on MacOS
|
# TODO: Disallow remote connections on MacOS
|
||||||
|
|
||||||
src = pkgs.fetchFromGitHub {
|
src = pkgs.fetchFromGitea {
|
||||||
owner = "clan-lol";
|
domain = "git.clan.lol";
|
||||||
|
owner = "clan";
|
||||||
repo = "webview";
|
repo = "webview";
|
||||||
rev = "7d24f0192765b7e08f2d712fae90c046d08f318e";
|
rev = "ef481aca8e531f6677258ca911c61aaaf71d2214";
|
||||||
hash = "sha256-yokVI9tFiEEU5M/S2xAeJOghqqiCvTelLo8WLKQZsSY=";
|
hash = "sha256-KF9ESpo40z6VXyYsZCLWJAIh0RFe1Zy/Qw4k7cTpoYU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# @Mic92: Where is this revision coming from? I can't see it in any of the branches.
|
||||||
|
# I removed the icon python code for now
|
||||||
|
# src = pkgs.fetchFromGitHub {
|
||||||
|
# owner = "clan-lol";
|
||||||
|
# repo = "webview";
|
||||||
|
# rev = "7d24f0192765b7e08f2d712fae90c046d08f318e";
|
||||||
|
# hash = "sha256-yokVI9tFiEEU5M/S2xAeJOghqqiCvTelLo8WLKQZsSY=";
|
||||||
|
# };
|
||||||
|
|
||||||
outputs = [
|
outputs = [
|
||||||
"out"
|
"out"
|
||||||
"dev"
|
"dev"
|
||||||
|
|||||||
Reference in New Issue
Block a user