fix: 修复事件拉取函数的安全性问题并改进错误处理

修复多个文件中事件拉取函数的安全性问题,添加更健壮的fallback机制
在imageview.lua中改进错误信息显示,确保image变量转换为字符串
在pkg.lua中调整JSON序列化参数以生成更紧凑的输出
This commit is contained in:
2025-09-03 15:56:53 +08:00
parent 0ffb590516
commit 9b94ae16e2
4 changed files with 22 additions and 11 deletions

View File

@@ -592,13 +592,18 @@ end
function GUIManager:handleEvents()
while self.running do
-- Safely get the pullEvent function with fallback to rc.pullEvent
-- Safely get the pullEvent function with multiple fallbacks
local pullEventFunc = os.pullEvent
if type(pullEventFunc) ~= "function" then
-- Try using rc.pullEvent as fallback
pullEventFunc = rc and rc.pullEvent
if type(pullEventFunc) ~= "function" then
error("Neither os.pullEvent nor rc.pullEvent is available")
-- Try using rc.pullEvent as fallback if rc is available
if rc and type(rc.pullEvent) == "function" then
pullEventFunc = rc.pullEvent
else
-- In CC Tweaked, os.pullEventRaw is always available
pullEventFunc = os.pullEventRaw
if type(pullEventFunc) ~= "function" then
error("No valid event pulling function found. Ensure you're running in a CC Tweaked environment.")
end
end
end