Skip to content

Commit

Permalink
feat:添加运行结束自动关机功能
Browse files Browse the repository at this point in the history
添加config.json的自动关机开关项目;
运行结束后60S关机;
  • Loading branch information
iceNo9 committed Nov 5, 2023
1 parent 0654db2 commit 0f698d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Honkai_Star_Rail.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def stop(self):
return [{}]

def end(self):
if sra_config_obj.auto_shutdown:
os.system("shutdown -s -t 60")
try:
plugin_manager.hook.end(SRA=self)
except:
Expand Down Expand Up @@ -256,6 +258,12 @@ def set_config(self, start = True):
options = [_('没打开'), _('打开了'), _('这是什么')]
option = questionary.select(title, options).ask()
sra_config_obj.auto_battle_persistence = options.index(option)

title = _("需要锄大地结束后自动关机么?:")
options = [_('不需要'), _('需要')]
option = questionary.select(title, options).ask()
sra_config_obj.auto_shutdown = bool(options.index(option))

sra_config_obj.start = True
raise Exception(_("请重新运行"))

Expand Down
13 changes: 12 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def set_config(e):
language = list(filter(lambda key: language_dict[key] == language, language_dict))[0]

fighting_list = [_('没打开'), _('打开了'), _('这是什么')]
shutdown_list = [_('不需要'), _('需要')]
fighting = fighting_list[sra_config_obj.auto_battle_persistence]
shutdown = shutdown_list[sra_config_obj.auto_shutdown]

github_proxy_list = ['https://ghproxy.com/', 'https://ghproxy.net/', "不设置代理"]
github_proxy = sra_config_obj.github_proxy
Expand Down Expand Up @@ -300,7 +302,14 @@ def set_config(e):
value=fighting,
width=200,
)

shutdown_dd = ft.Dropdown(
label= _("需要锄大地结束后自动关机么?"),
hint_text= _("设置自动关机?"),
options=[ft.dropdown.Option(i) for i in shutdown_list],
value=shutdown,
width=200,
)

open_map_tf = ft.TextField(label=_("打开地图按钮"), value=open_map, width=200)
def save(e):
sra_config_obj.github_proxy = "" if github_proxy_dd.value == "不设置代理" else github_proxy_dd.value
Expand All @@ -310,6 +319,7 @@ def save(e):
sra_config_obj.level = level_dd.value
sra_config_obj.language = language_dict[language_dd.value]
sra_config_obj.auto_battle_persistence = fighting_list.index(fighting_dd.value)
sra_config_obj.auto_shutdown = bool(shutdown_list.index(shutdown_dd.value))
sra_config_obj.start = True
to_page_main(page)
page.clean()
Expand All @@ -324,6 +334,7 @@ def save(e):
open_map_tf,
language_dd,
fighting_dd,
shutdown_dd,
ft.ElevatedButton(_("保存"), on_click=save),
)

Expand Down
3 changes: 2 additions & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ class SRAData(metaclass=SRADataMeta):
"""是否在打印遗器信息时显示拓展信息"""
ndigits_for_relic: int = 2
"""在打印遗器信息时的小数精度"""

auto_shutdown: bool = False
"""是否自动关机"""

def __init__(self) -> None:
...
Expand Down

0 comments on commit 0f698d4

Please sign in to comment.