diff --git a/app/card/samplecardview1.py b/app/card/samplecardview1.py index 802f87a6..f1a9815d 100644 --- a/app/card/samplecardview1.py +++ b/app/card/samplecardview1.py @@ -54,7 +54,7 @@ def __init__(self, icon, title, action, parent=None): self.titleLabel.setObjectName('titleLabel') # self.contentLabel.setObjectName('contentLabel') - def showBottomTeachingTip(self): + def showSuccessTip(self): if not cfg.get_value(base64.b64decode("YXV0b191cGRhdGU=").decode("utf-8")): disclaimer(self) TeachingTip.create( @@ -68,16 +68,29 @@ def showBottomTeachingTip(self): parent=self ) + def showErrorTip(self, e): + TeachingTip.create( + target=self.iconWidget, + icon=InfoBarIcon.ERROR, + title='执行出错', + content=str(e), + isClosable=False, + tailPosition=TeachingTipTailPosition.BOTTOM, + duration=5000, + parent=self + ) + def createMenu(self, pos): menu = RoundMenu(parent=self) def create_triggered_function(task): def triggered_function(): - self.showBottomTeachingTip() try: task() + self.showSuccessTip() except Exception as e: log.warning(f"执行失败:{e}") + self.showErrorTip(e) return triggered_function for index, (key, value) in enumerate(self.action.items()): @@ -90,11 +103,12 @@ def triggered_function(): def mouseReleaseEvent(self, e): super().mouseReleaseEvent(e) if callable(self.action): - self.showBottomTeachingTip() try: self.action() + self.showSuccessTip() except Exception as e: log.warning(f"执行失败:{e}") + self.showErrorTip(e) elif isinstance(self.action, dict): self.createMenu(e.globalPos()) diff --git a/assets/docs/Changelog.md b/assets/docs/Changelog.md index bcf43772..b96a0260 100644 --- a/assets/docs/Changelog.md +++ b/assets/docs/Changelog.md @@ -9,6 +9,7 @@ - 循环模式每次启动前会重新加载配置文件 - 增加 “在多显示器上进行截屏” 选项(设置—杂项) [#392](https://github.com/moesnow/March7thAssistant/pull/392) - 支持自动获取通过米哈游启动器安装游戏的路径 +- 优化主程序缺失后的报错信息 ### 修复 - “日常任务” 会在每次启动时被错误清空 diff --git a/tasks/base/tasks.py b/tasks/base/tasks.py index f2ef9ec9..fe038563 100644 --- a/tasks/base/tasks.py +++ b/tasks/base/tasks.py @@ -15,6 +15,11 @@ def execute_command_in_new_environment(command, use_windows_terminal=False): """ 在新的环境中执行给定的命令。 """ + if getattr(sys, 'frozen', False): + if not os.path.exists("./March7th Assistant.exe"): + exception = Exception("未找到可执行文件:March7th Assistant.exe,\n请将`小助手文件夹`加入杀毒软件排除项/信任区后,\n使用 March7th Updater.exe 更新或手动更新一次") + raise exception + executable_path = os.path.abspath("./March7th Assistant.exe") if getattr(sys, 'frozen', False) else sys.executable main_script = [] if getattr(sys, 'frozen', False) else ["main.py"]