Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

xiaodingding/KeymouseGo

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (5)
Tags (20)
master
dev
v6
x1
pynput
v5.2.1
v5.2
v5.1.1
v5.1
v5.0
v4.1
v4.0
v3.2.2
v3.2.1
v3.2
v3.1
v3.0
v2.2
v2.1
v2.0
v1.5
v1.4
v1.3
v1.2
v1.1
master
Branches (5)
Tags (20)
master
dev
v6
x1
pynput
v5.2.1
v5.2
v5.1.1
v5.1
v5.0
v4.1
v4.0
v3.2.2
v3.2.1
v3.2
v3.1
v3.0
v2.2
v2.1
v2.0
v1.5
v1.4
v1.3
v1.2
v1.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (5)
Tags (20)
master
dev
v6
x1
pynput
v5.2.1
v5.2
v5.1.1
v5.1
v5.0
v4.1
v4.0
v3.2.2
v3.2.1
v3.2
v3.1
v3.0
v2.2
v2.1
v2.0
v1.5
v1.4
v1.3
v1.2
v1.1
KeymouseGo
/
Plugin
/
Manager.py
KeymouseGo
/
Plugin
/
Manager.py
Manager.py 3.93 KB
Copy Edit Raw Blame History
monomux authored 2025年03月11日 22:06 +08:00 . fix: failed to parse event type 'custom'
import os
import sys
from typing import Dict, Callable, List, Any
from loguru import logger
from Plugin.Interface import PluginInterface
from Util.Parser import JsonObject
from importlib.machinery import SourceFileLoader
import json5
def to_abs_path(*args):
return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
*args)
class PluginManager:
functions: Dict[str, Callable] = {}
# record_functions: List[Callable] = []
plugins: List[PluginInterface] = []
# resources_paths: List[str] = []
@staticmethod
def load_manifest(path: str) -> Dict:
manifest = None
manifest_path = os.path.join(path, 'manifest.json5')
if os.path.exists(manifest_path):
with open(manifest_path, 'r', encoding='utf-8') as f:
manifest = json5.load(f)
return manifest
# 在目录plugins下搜寻启用的有效插件,同时生成实例
@staticmethod
@logger.catch
def discover_plugin():
if not os.path.exists(to_abs_path('plugins')):
os.mkdir(to_abs_path('plugins'))
with os.scandir(to_abs_path('plugins')) as it:
for entry in it:
entry: os.DirEntry
if entry.is_dir():
manifest = PluginManager.load_manifest(entry.path)
if manifest:
if entry.path not in sys.path:
sys.path.append(entry.path)
if manifest.get('entry', None) is not None and manifest.get('plugin_class', None) is not None:
loader = SourceFileLoader(manifest['plugin_class'], os.path.join(entry.path, manifest["entry"]))
plugin_module = loader.load_module()
plugin_class = getattr(plugin_module, manifest['plugin_class'])
PluginManager.plugins.append(plugin_class(manifest))
# if manifest.get('resources_path') is not None:
# for path in manifest['resources_path']['theme']:
# PluginManager.resources_paths.append(os.path.join(entry.path, path))
logger.info(f'Discovered Plugin {[plugin_ins.meta.name for plugin_ins in PluginManager.plugins]}')
# 调用实例的注册方法
@staticmethod
@logger.catch
def register_plugin():
for plugin_ins in PluginManager.plugins:
funcs = plugin_ins.register_functions()
# funcs_rec = plugin_ins.register_record_functions()
if funcs:
PluginManager.functions.update(funcs)
# if funcs_rec:
# PluginManager.record_functions.extend(funcs_rec)
logger.info(f'Registered functions: {PluginManager.functions.keys()}')
# logger.info(f'Registered record functions: {PluginManager.record_functions}')
# logger.info(f'Additional Resources: {PluginManager.resources_paths}')
@staticmethod
@logger.catch
def call(function_name: str, json_object: JsonObject):
func = PluginManager.functions.get(function_name, None)
if func:
return func(json_object)
else:
logger.error(f'Cannot find function {function_name} in registered plugins')
return None
@staticmethod
def call_group(function_group: List[str], json_object: JsonObject):
for function_name in function_group:
PluginManager.call(function_name, json_object)
# @staticmethod
# def call_record(event: Dict[str, Any]):
# for functions in PluginManager.record_functions:
# functions(event)
@staticmethod
def reload():
# 暂时采用全部重新加载的方案
PluginManager.functions = {}
PluginManager.record_functions = []
PluginManager.plugins = []
# PluginManager.resources_paths = []
PluginManager.discover_plugin()
PluginManager.register_plugin()
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiaodingding/KeymouseGo.git
git@gitee.com:xiaodingding/KeymouseGo.git
xiaodingding
KeymouseGo
KeymouseGo
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /