mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
refactoring
This commit is contained in:
parent
e97a2ea251
commit
d3d885e180
@ -51,6 +51,11 @@ class BaseAtx(BasePlugin):
|
|||||||
yield {}
|
yield {}
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
async def cleanup(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# =====
|
||||||
|
|
||||||
async def power_on(self) -> bool:
|
async def power_on(self) -> bool:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -63,6 +68,8 @@ class BaseAtx(BasePlugin):
|
|||||||
async def power_reset_hard(self) -> bool:
|
async def power_reset_hard(self) -> bool:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
# =====
|
||||||
|
|
||||||
async def click_power(self) -> None:
|
async def click_power(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -72,9 +79,6 @@ class BaseAtx(BasePlugin):
|
|||||||
async def click_reset(self) -> None:
|
async def click_reset(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def cleanup(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def get_atx_class(name: str) -> Type[BaseAtx]:
|
def get_atx_class(name: str) -> Type[BaseAtx]:
|
||||||
|
|||||||
@ -43,6 +43,11 @@ class BaseHid(BasePlugin):
|
|||||||
async def reset(self) -> None:
|
async def reset(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
async def cleanup(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# =====
|
||||||
|
|
||||||
async def send_key_event(self, key: str, state: bool) -> None:
|
async def send_key_event(self, key: str, state: bool) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -58,9 +63,6 @@ class BaseHid(BasePlugin):
|
|||||||
async def clear_events(self) -> None:
|
async def clear_events(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def cleanup(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def get_hid_class(name: str) -> Type[BaseHid]:
|
def get_hid_class(name: str) -> Type[BaseHid]:
|
||||||
|
|||||||
@ -218,23 +218,6 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
|||||||
self.__lock.release()
|
self.__lock.release()
|
||||||
get_logger(0).info("Reset HID performed")
|
get_logger(0).info("Reset HID performed")
|
||||||
|
|
||||||
async def send_key_event(self, key: str, state: bool) -> None:
|
|
||||||
await self.__send_bool_event(_KeyEvent(key, state), self.__pressed_keys)
|
|
||||||
|
|
||||||
async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
|
|
||||||
await self.__send_int_event(_MouseMoveEvent(to_x, to_y))
|
|
||||||
|
|
||||||
async def send_mouse_button_event(self, button: str, state: bool) -> None:
|
|
||||||
await self.__send_bool_event(_MouseButtonEvent(button, state), self.__pressed_mouse_buttons)
|
|
||||||
|
|
||||||
async def send_mouse_wheel_event(self, delta_y: int) -> None:
|
|
||||||
await self.__send_int_event(_MouseWheelEvent(0, delta_y))
|
|
||||||
|
|
||||||
async def clear_events(self) -> None:
|
|
||||||
if not self.__stop_event.is_set():
|
|
||||||
async with self.__lock:
|
|
||||||
self.__unsafe_clear_events()
|
|
||||||
|
|
||||||
@aiotools.atomic
|
@aiotools.atomic
|
||||||
async def cleanup(self) -> None:
|
async def cleanup(self) -> None:
|
||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
@ -252,6 +235,25 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
|||||||
finally:
|
finally:
|
||||||
gpio.write(self.__reset_pin, False)
|
gpio.write(self.__reset_pin, False)
|
||||||
|
|
||||||
|
# =====
|
||||||
|
|
||||||
|
async def send_key_event(self, key: str, state: bool) -> None:
|
||||||
|
await self.__send_bool_event(_KeyEvent(key, state), self.__pressed_keys)
|
||||||
|
|
||||||
|
async def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
|
||||||
|
await self.__send_int_event(_MouseMoveEvent(to_x, to_y))
|
||||||
|
|
||||||
|
async def send_mouse_button_event(self, button: str, state: bool) -> None:
|
||||||
|
await self.__send_bool_event(_MouseButtonEvent(button, state), self.__pressed_mouse_buttons)
|
||||||
|
|
||||||
|
async def send_mouse_wheel_event(self, delta_y: int) -> None:
|
||||||
|
await self.__send_int_event(_MouseWheelEvent(0, delta_y))
|
||||||
|
|
||||||
|
async def clear_events(self) -> None:
|
||||||
|
if not self.__stop_event.is_set():
|
||||||
|
async with self.__lock:
|
||||||
|
self.__unsafe_clear_events()
|
||||||
|
|
||||||
async def __send_bool_event(self, event: _BoolEvent, pressed: Set[str]) -> None:
|
async def __send_bool_event(self, event: _BoolEvent, pressed: Set[str]) -> None:
|
||||||
if not self.__stop_event.is_set():
|
if not self.__stop_event.is_set():
|
||||||
async with self.__lock:
|
async with self.__lock:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user