Skip to content

Commit be4d00f

Browse files
committed
fix: failed to parse event type 'custom'
1 parent fdd8268 commit be4d00f

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

Plugin/Manager.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PluginManager:
1717
functions: Dict[str, Callable] = {}
1818
# record_functions: List[Callable] = []
1919
plugins: List[PluginInterface] = []
20-
resources_paths: List[str] = []
20+
# resources_paths: List[str] = []
2121

2222

2323
@staticmethod
@@ -40,17 +40,17 @@ def discover_plugin():
4040
entry: os.DirEntry
4141
if entry.is_dir():
4242
manifest = PluginManager.load_manifest(entry.path)
43-
if manifest and manifest['enabled']:
43+
if manifest:
4444
if entry.path not in sys.path:
4545
sys.path.append(entry.path)
4646
if manifest.get('entry', None) is not None and manifest.get('plugin_class', None) is not None:
4747
loader = SourceFileLoader(manifest['plugin_class'], os.path.join(entry.path, manifest["entry"]))
4848
plugin_module = loader.load_module()
4949
plugin_class = getattr(plugin_module, manifest['plugin_class'])
5050
PluginManager.plugins.append(plugin_class(manifest))
51-
if manifest.get('resources_path') is not None:
52-
for path in manifest['resources_path']['theme']:
53-
PluginManager.resources_paths.append(os.path.join(entry.path, path))
51+
# if manifest.get('resources_path') is not None:
52+
# for path in manifest['resources_path']['theme']:
53+
# PluginManager.resources_paths.append(os.path.join(entry.path, path))
5454

5555
logger.info(f'Discovered Plugin {[plugin_ins.meta.name for plugin_ins in PluginManager.plugins]}')
5656

@@ -67,7 +67,7 @@ def register_plugin():
6767
# PluginManager.record_functions.extend(funcs_rec)
6868
logger.info(f'Registered functions: {PluginManager.functions.keys()}')
6969
# logger.info(f'Registered record functions: {PluginManager.record_functions}')
70-
logger.info(f'Additional Resources: {PluginManager.resources_paths}')
70+
# logger.info(f'Additional Resources: {PluginManager.resources_paths}')
7171

7272
@staticmethod
7373
@logger.catch
@@ -76,7 +76,7 @@ def call(function_name: str, json_object: JsonObject):
7676
if func:
7777
return func(json_object)
7878
else:
79-
logger.warning(f'Cannot find function {function_name} in registered plugins')
79+
logger.error(f'Cannot find function {function_name} in registered plugins')
8080
return None
8181

8282
@staticmethod
@@ -95,6 +95,6 @@ def reload():
9595
PluginManager.functions = {}
9696
PluginManager.record_functions = []
9797
PluginManager.plugins = []
98-
PluginManager.resources_paths = []
98+
# PluginManager.resources_paths = []
9999
PluginManager.discover_plugin()
100100
PluginManager.register_plugin()

UIFunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(self, app):
112112
# Config
113113
self.choice_theme.addItems(['Default'])
114114
self.choice_theme.addItems(list_themes())
115-
self.choice_theme.addItems(PluginManager.resources_paths)
115+
# self.choice_theme.addItems(PluginManager.resources_paths)
116116
self.stimes.setValue(int(self.config.value("Config/LoopTimes")))
117117
self.mouse_move_interval_ms.setValue(int(self.config.value("Config/Precision")))
118118
self.choice_theme.setCurrentText(self.config.value("Config/Theme"))

Util/Parser.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,20 @@ def parse(script_path: str, *args) -> JsonObject:
4444
label_maps: Dict[str, JsonObject] = {}
4545
pending_dict: Dict[JsonObject, str] = {} # 如果对象要跳转到未收入的label,则暂存该对象等待遍历完成后(labelmaps完全更新)再添加内容
4646

47-
head_object = ScriptParser.link_objects(objects, None, label_maps, pending_dict)
48-
if len(pending_dict) > 0:
49-
for json_object, target_label in pending_dict.items():
50-
target_object = label_maps.get(target_label, None)
51-
if target_object:
52-
json_object.next_object = target_object
53-
else:
54-
logger.error(f'Could not find label {target_label}')
55-
return head_object
47+
try:
48+
head_object = ScriptParser.link_objects(objects, None, label_maps, pending_dict)
49+
if len(pending_dict) > 0:
50+
for json_object, target_label in pending_dict.items():
51+
target_object = label_maps.get(target_label, None)
52+
if target_object:
53+
json_object.next_object = target_object
54+
else:
55+
logger.error(f'Could not find label {target_label}')
56+
return head_object
57+
except Exception as e:
58+
logger.error(e)
59+
logger.error('无法解析脚本,请检查是否存在语法问题')
60+
return None
5661

5762
@staticmethod
5863
@logger.catch
@@ -111,6 +116,8 @@ def parse(script_path: str, *args) -> JsonObject:
111116
content = json5.load(f)
112117
except Exception as e:
113118
logger.error(e)
119+
logger.error('无法解析脚本,请检查是否存在语法问题')
120+
return None
114121

115122
logger.debug('Script content')
116123
logger.debug(content)

Util/RunScriptClass.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ def wait_if_pause(self):
7777
else:
7878
self.resume()
7979

80-
@logger.catch
8180
def run(self):
82-
logger.debug('Run script at thread' + str(threading.current_thread()))
81+
logger.debug('Run script at thread' + str(QThread.currentThread()))
8382

8483
if not self.script_path:
8584
self.tnumrdSignal.emit('script not found, please record first!')
@@ -88,7 +87,11 @@ def run(self):
8887

8988
self.btnSignal.emit(False)
9089
self.playtuneSignal.emit('start.wav')
91-
self.run_script_from_path(self.script_path)
90+
try:
91+
self.run_script_from_path(self.script_path)
92+
except Exception as e:
93+
logger.error(e)
94+
self.logSignal.emit('An error occurred during execution! Please check logs!')
9295
self.statusSignal.emit(True)
9396
self.playtuneSignal.emit('end.wav')
9497

@@ -136,7 +139,7 @@ def run_script_from_path(self, script_path: str):
136139
self.logSignal.emit('==============\nAn error occurred during runtime')
137140
self.logSignal.emit(str(e))
138141
self.logSignal.emit('==============')
139-
self.logSignal.emit('failed')
142+
self.logSignal.emit('script run failed, please check your log file')
140143
finally:
141144
self.btnSignal.emit(True)
142145

@@ -173,10 +176,11 @@ def run_object(self, json_object: JsonObject):
173176
return json_object.next_object
174177
else:
175178
return json_object.next_object_if_false
176-
elif object_type == 'goto':
179+
elif object_type == 'goto' or object_type == 'custom':
177180
pass
178181
elif object_type == 'subroutine':
179-
self.run_script_from_path(json_object.content['path'])
182+
for path in json_object.content['path']:
183+
self.run_script_from_path(path)
180184
else:
181185
# Not supposed to happen
182186
logger.error(f'Unexpected event type when running {json_object.content}')

0 commit comments

Comments
 (0)