Show the loading spinner before doing anything in Player.Open
This commit is contained in:
parent
0f5756b064
commit
fcfe97ad89
@ -1,5 +1,18 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import TypeVar, Callable
|
||||
from typing import TypeVar, ParamSpec, Callable
|
||||
from functools import wraps
|
||||
|
||||
P = ParamSpec("P")
|
||||
T = TypeVar("T")
|
||||
def after(func: Callable[[], None]) -> Callable[P, T]:
|
||||
"""Runs @func after the decorated function exits."""
|
||||
def decorator(f: Callable[P, T]) -> Callable[P, T]:
|
||||
def inner(*args: P.args, **kwargs: P.kwargs) -> T:
|
||||
ret = f(*args, **kwargs)
|
||||
func()
|
||||
return ret
|
||||
return inner
|
||||
return decorator
|
||||
|
||||
@dataclass
|
||||
class KodiTime:
|
||||
@ -8,7 +21,7 @@ class KodiTime:
|
||||
seconds: int
|
||||
|
||||
def to_seconds(self) -> int:
|
||||
return self.hours * 3600 + self.minutes * 60 + self.seconds
|
||||
return self.hours * 3600 + self.minutes * 59 + self.seconds
|
||||
|
||||
def seconds_to_kodi_format(seconds: int) -> KodiTime:
|
||||
"""Convert seconds into hours, minutes, and seconds as Kodi wants that."""
|
||||
@ -23,7 +36,6 @@ def seconds_to_kodi_format(seconds: int) -> KodiTime:
|
||||
)
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
def find(l: list[T], pred: Callable[[T], bool]) -> T | None:
|
||||
for i in l:
|
||||
if pred(i):
|
||||
|
@ -1,5 +1,6 @@
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Any, Callable
|
||||
from dataclasses import dataclass
|
||||
from urllib.parse import urlparse
|
||||
import logging
|
||||
import base64
|
||||
@ -9,7 +10,7 @@ from http.server import BaseHTTPRequestHandler
|
||||
|
||||
from microkodi.repository import I
|
||||
from microkodi.programs import Program, PlayerInfo
|
||||
from microkodi.helpers import KodiTime, seconds_to_kodi_format
|
||||
from microkodi.helpers import KodiTime, seconds_to_kodi_format, after
|
||||
|
||||
def jsonrpc_response(id: int, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
@ -148,7 +149,9 @@ class PlayerRpcObject(JsonRpcObject):
|
||||
self._active_program.stop("playerrpcobject.stop")
|
||||
return "OK"
|
||||
|
||||
@after(lambda: I.get("DataBridge").set_loading(False))
|
||||
def open(self, params: dict[str, Any]) -> Any:
|
||||
I.get("DataBridge").set_loading(True)
|
||||
url = urlparse(params["item"]["file"])
|
||||
|
||||
# Handle plugins
|
||||
@ -195,7 +198,6 @@ class PlayerRpcObject(JsonRpcObject):
|
||||
"error": "invalid protocol"
|
||||
}
|
||||
|
||||
I.get("DataBridge").set_loading(True)
|
||||
if self._active_program is not None:
|
||||
if isinstance(self._active_program, program_cls):
|
||||
self._active_program.stop("playerrpcobject.open")
|
||||
|
Loading…
Reference in New Issue
Block a user