fix plugin state

This commit is contained in:
jxxghp 2023-08-03 17:58:00 +08:00
parent 51016d636b
commit 79a57b0576
12 changed files with 51 additions and 11 deletions

View File

@ -185,6 +185,9 @@ class PluginManager(metaclass=Singleton):
conf.update({"installed": True}) conf.update({"installed": True})
else: else:
conf.update({"installed": False}) conf.update({"installed": False})
# 运行状态
if hasattr(plugin, "get_state"):
conf.update({"state": plugin.get_state()})
# 名称 # 名称
if hasattr(plugin, "plugin_name"): if hasattr(plugin, "plugin_name"):
conf.update({"plugin_name": plugin.plugin_name}) conf.update({"plugin_name": plugin.plugin_name})

View File

@ -95,6 +95,13 @@ class _PluginBase(metaclass=ABCMeta):
""" """
pass pass
@abstractmethod
def get_state(self) -> bool:
"""
获取插件运行状态
"""
pass
@abstractmethod @abstractmethod
def stop_service(self): def stop_service(self):
""" """

View File

@ -113,6 +113,9 @@ class AutoSignIn(_PluginBase):
self._scheduler.print_jobs() self._scheduler.print_jobs()
self._scheduler.start() self._scheduler.start()
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
""" """

View File

@ -173,6 +173,9 @@ class ChineseSubFinder(_PluginBase):
"remote_path": "" "remote_path": ""
} }
def get_state(self) -> bool:
return self._enabled
def get_page(self) -> List[dict]: def get_page(self) -> List[dict]:
pass pass

View File

@ -60,6 +60,9 @@ class CustomHosts(_PluginBase):
"enable": self._enabled "enable": self._enabled
}) })
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
pass pass

View File

@ -27,18 +27,21 @@ class DirMonitor(_PluginBase):
# 私有属性 # 私有属性
_monitor = None _monitor = None
_enable = False _enabled = False
def init_plugin(self, config: dict = None): def init_plugin(self, config: dict = None):
# 读取配置 # 读取配置
if config: if config:
self._enable = config.get("enable") self._enabled = config.get("enabled")
# 停止现有任务 # 停止现有任务
self.stop_service() self.stop_service()
# TODO 启动任务 # TODO 启动任务
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
pass pass

View File

@ -102,6 +102,9 @@ class DoubanRank(_PluginBase):
self._scheduler.print_jobs() self._scheduler.print_jobs()
self._scheduler.start() self._scheduler.start()
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
pass pass

View File

@ -97,6 +97,9 @@ class DoubanSync(_PluginBase):
self._scheduler.print_jobs() self._scheduler.print_jobs()
self._scheduler.start() self._scheduler.start()
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
""" """

View File

@ -36,7 +36,7 @@ class LibraryScraper(_PluginBase):
_scheduler = None _scheduler = None
_scraper = None _scraper = None
# 限速开关 # 限速开关
_enable = False _enabled = False
_cron = None _cron = None
_mode = None _mode = None
_scraper_path = None _scraper_path = None
@ -47,7 +47,7 @@ class LibraryScraper(_PluginBase):
def init_plugin(self, config: dict = None): def init_plugin(self, config: dict = None):
# 读取配置 # 读取配置
if config: if config:
self._enable = config.get("enable") self._enabled = config.get("enabled")
self._cron = config.get("cron") self._cron = config.get("cron")
self._mode = config.get("mode") self._mode = config.get("mode")
self._scraper_path = config.get("scraper_path") self._scraper_path = config.get("scraper_path")
@ -57,7 +57,7 @@ class LibraryScraper(_PluginBase):
self.stop_service() self.stop_service()
# 启动定时任务 & 立即运行一次 # 启动定时任务 & 立即运行一次
if self._enable: if self._enabled:
self._scheduler = BackgroundScheduler(timezone=settings.TZ) self._scheduler = BackgroundScheduler(timezone=settings.TZ)
if self._cron: if self._cron:
logger.info(f"媒体库刮削服务启动,周期:{self._cron}") logger.info(f"媒体库刮削服务启动,周期:{self._cron}")
@ -68,6 +68,9 @@ class LibraryScraper(_PluginBase):
self._scheduler.print_jobs() self._scheduler.print_jobs()
self._scheduler.start() self._scheduler.start()
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
pass pass

View File

@ -114,6 +114,9 @@ class SiteStatistic(_PluginBase):
self._scheduler.print_jobs() self._scheduler.print_jobs()
self._scheduler.start() self._scheduler.start()
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
""" """

View File

@ -31,7 +31,7 @@ class SpeedLimiter(_PluginBase):
# 私有属性 # 私有属性
_scheduler = None _scheduler = None
_enable: bool = False _enabled: bool = False
_notify: bool = False _notify: bool = False
_bandwidth: int = 0 _bandwidth: int = 0
_interval: int = 60 _interval: int = 60
@ -39,7 +39,7 @@ class SpeedLimiter(_PluginBase):
def init_plugin(self, config: dict = None): def init_plugin(self, config: dict = None):
# 读取配置 # 读取配置
if config: if config:
self._enable = config.get("enable") self._enabled = config.get("enabled")
self._notify = config.get("notify") self._notify = config.get("notify")
try: try:
# 总带宽 # 总带宽
@ -52,7 +52,7 @@ class SpeedLimiter(_PluginBase):
self.stop_service() self.stop_service()
# 启动限速任务 # 启动限速任务
if self._enable: if self._enabled:
self._scheduler = BackgroundScheduler(timezone=settings.TZ) self._scheduler = BackgroundScheduler(timezone=settings.TZ)
self._scheduler.add_job(func=self.__check_playing_sessions, self._scheduler.add_job(func=self.__check_playing_sessions,
trigger='interval', trigger='interval',
@ -61,6 +61,9 @@ class SpeedLimiter(_PluginBase):
self._scheduler.start() self._scheduler.start()
logger.info("播放限速服务启动") logger.info("播放限速服务启动")
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
pass pass

View File

@ -29,11 +29,14 @@ class TorrentRemover(_PluginBase):
# 私有属性 # 私有属性
downloader = None downloader = None
_enable = False _enabled = False
def init_plugin(self, config: dict = None): def init_plugin(self, config: dict = None):
if config: if config:
self._enable = config.get("enable") self._enabled = config.get("enabled")
def get_state(self) -> bool:
return self._enabled
@staticmethod @staticmethod
def get_command() -> List[Dict[str, Any]]: def get_command() -> List[Dict[str, Any]]:
@ -56,7 +59,7 @@ class TorrentRemover(_PluginBase):
""" """
联动删除下载器中的下载任务 联动删除下载器中的下载任务
""" """
if not self._enable: if not self._enabled:
return return
event_info = event.event_data event_info = event.event_data
if not event_info: if not event_info: