Skip to content

Commit

Permalink
#252 升级flet 关闭窗口时清理定时器
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Apr 6, 2024
1 parent 61706c3 commit 0b6540f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pyautogui==0.9.54
onnxruntime==1.17.0
opencv-python==4.9.0.80
keyboard==0.13.5
flet==0.20.2
flet==0.21.2
pyinstaller==6.1.0
schedule==1.2.1
tenacity==8.2.3
Expand Down
10 changes: 10 additions & 0 deletions src/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from basic import os_utils
from basic.i18_utils import gt, update_default_lang
from basic.log_utils import log
from gui import log_view, calibrator_view, version, one_stop_view, scheduler, snack_bar
from gui.settings import gui_config, settings_game_config_view, settings_trailblaze_power_view, \
settings_echo_of_war_view, \
Expand Down Expand Up @@ -313,6 +314,15 @@ def run_app(page: ft.Page):
StarRailOneDragon(page, ctx)
snack_bar.show_message('本脚本开源免费 如有付费请立即申请退款', page)

def window_event(e):
if e.data == "close":
scheduler.shutdown()
log.info('定时器已关闭')
page.window_destroy()

page.window_prevent_close = True
page.on_window_event = window_event


if __name__ == '__main__':
if os_utils.is_debug():
Expand Down
11 changes: 11 additions & 0 deletions src/gui/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from basic.log_utils import log


_is_shutdown: bool = False


def start():
t = threading.Thread(target=_run_schedule)
t.start()
Expand Down Expand Up @@ -49,8 +52,16 @@ def by_hour(hour_num: int, func: Callable, tag: Optional[str] = None):

def _run_schedule():
while True:
if _is_shutdown:
break
try:
schedule.run_pending()
except Exception:
log.error('定时任务出错', exc_info=True)
time.sleep(1)


def shutdown():
schedule.clear()
global _is_shutdown
_is_shutdown = True

0 comments on commit 0b6540f

Please sign in to comment.