mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
pikvm/pikvm#1537: /hid/inactivity api
This commit is contained in:
parent
f25e5ef2b4
commit
735c2e6395
@ -102,6 +102,11 @@ class HidApi:
|
|||||||
await self.__hid.reset()
|
await self.__hid.reset()
|
||||||
return make_json_response()
|
return make_json_response()
|
||||||
|
|
||||||
|
@exposed_http("GET", "/hid/inactivity")
|
||||||
|
async def __inactivity_handler(self, _: Request) -> Response:
|
||||||
|
secs = self.__hid.get_inactivity_seconds()
|
||||||
|
return make_json_response({"inactivity": secs})
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
async def get_keymaps(self) -> dict: # Ugly hack to generate hid_keymaps_state (see server.py)
|
async def get_keymaps(self) -> dict: # Ugly hack to generate hid_keymaps_state (see server.py)
|
||||||
|
|||||||
@ -72,7 +72,7 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
self.__j_active = jiggler_active
|
self.__j_active = jiggler_active
|
||||||
self.__j_interval = jiggler_interval
|
self.__j_interval = jiggler_interval
|
||||||
self.__j_absolute = True
|
self.__j_absolute = True
|
||||||
self.__j_activity_ts = 0
|
self.__j_activity_ts = self.__get_monotonic_seconds()
|
||||||
self.__j_last_x = 0
|
self.__j_last_x = 0
|
||||||
self.__j_last_y = 0
|
self.__j_last_y = 0
|
||||||
|
|
||||||
@ -143,6 +143,11 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
|
def get_inactivity_seconds(self) -> int:
|
||||||
|
return (self.__get_monotonic_seconds() - self.__j_activity_ts)
|
||||||
|
|
||||||
|
# =====
|
||||||
|
|
||||||
async def send_key_events(
|
async def send_key_events(
|
||||||
self,
|
self,
|
||||||
keys: Iterable[tuple[int, bool]],
|
keys: Iterable[tuple[int, bool]],
|
||||||
@ -249,7 +254,10 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
handler(*xy)
|
handler(*xy)
|
||||||
|
|
||||||
def __bump_activity(self) -> None:
|
def __bump_activity(self) -> None:
|
||||||
self.__j_activity_ts = int(time.monotonic())
|
self.__j_activity_ts = self.__get_monotonic_seconds()
|
||||||
|
|
||||||
|
def __get_monotonic_seconds(self) -> int:
|
||||||
|
return int(time.monotonic())
|
||||||
|
|
||||||
def _set_jiggler_absolute(self, absolute: bool) -> None:
|
def _set_jiggler_absolute(self, absolute: bool) -> None:
|
||||||
self.__j_absolute = absolute
|
self.__j_absolute = absolute
|
||||||
@ -271,7 +279,7 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
async def systask(self) -> None:
|
async def systask(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
if self.__j_active and (self.__j_activity_ts + self.__j_interval < int(time.monotonic())):
|
if self.__j_active and (self.__j_activity_ts + self.__j_interval < self.__get_monotonic_seconds()):
|
||||||
if self.__j_absolute:
|
if self.__j_absolute:
|
||||||
(x, y) = (self.__j_last_x, self.__j_last_y)
|
(x, y) = (self.__j_last_x, self.__j_last_y)
|
||||||
for move in [100, -100, 100, -100, 0]:
|
for move in [100, -100, 100, -100, 0]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user