Skip to content

Commit

Permalink
Merge pull request #126 from sanmusen214/dev
Browse files Browse the repository at this point in the history
Improve the ui of homepage
  • Loading branch information
sanmusen214 authored Nov 11, 2024
2 parents bce1e57 + 36ef7ea commit 58dfbbb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 55 deletions.
2 changes: 1 addition & 1 deletion DATA/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"button_save":"保存",
"button_save_and_run_gui":"保存并执行(GUI,实验性功能)",
"button_save_and_run_terminal":"保存并执行(终端)",
"button_check_version":"检查更新并下载(确保BAAH不在运行),下载完成后请关闭BAAH手动解压更新补丁",
"button_check_version":"检查更新并下载,下载完成后请关闭BAAH手动解压更新补丁(确保BAAH不在运行)",
"button_update_advance":"一键更新到最新版本(推荐)",
"button_select_all":"全选",
"button_select_none":"全不选",
Expand Down
2 changes: 1 addition & 1 deletion gui/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, task_enum: TaskName, json_key_name: str):
TaskStr(TaskName.MOMOTALK, "task_clear_momotalk"),
TaskStr(TaskName.CAFE, "task_cafe"),
# compatibility, just changed display name
TaskStr(TaskName.CAFE, "task_cafe_deprecated"),
TaskStr(TaskName.CAFE_ONLY_TOUCH, "task_cafe_deprecated"),
TaskStr(TaskName.TIMETABLE, "task_timetable"),
TaskStr(TaskName.CLUB, "task_club"),
TaskStr(TaskName.MANUFACTURE, "task_craft"),
Expand Down
29 changes: 1 addition & 28 deletions gui/pages/Setting_BAAH.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
import subprocess
from nicegui import ui, app
from gui.components.check_update import get_newest_version
from nicegui import ui


def set_BAAH(config, shared_softwareconfig):

def select_language(value):
shared_softwareconfig.softwareconfigdict["LANGUAGE"] = value
shared_softwareconfig.save_software_config()
if value == "zh_CN":
ui.notify("语言已切换为中文,重启生效")
else:
ui.notify("Language has been changed, restart to take effect")


with ui.column():
ui.link_target("BAAH")
ui.label(f"Blue Archive Aris Helper {config.NOWVERSION} ==> ({config.nowuserconfigname})").style('font-size: xx-large')

ui.toggle({"zh_CN":"中文", "en_US":"English", "jp_JP":"日本語"}, value=shared_softwareconfig.softwareconfigdict["LANGUAGE"], on_change=lambda e:select_language(e.value)).bind_value_from(shared_softwareconfig.softwareconfigdict, "LANGUAGE")

ui.label(config.get_text("BAAH_desc"))

ui.label(config.get_text("BAAH_get_version"))

# 下载更新包
ui.button(config.get_text("button_check_version"), on_click=lambda e, c=config:get_newest_version(c))

# 一键更新,唤起更新程序,结束gui进程
def update_advance():
try:
subprocess.Popen(["BAAH_UPDATE.exe"], creationflags=subprocess.CREATE_NEW_CONSOLE, close_fds=True)
app.shutdown()
except Exception as e:
ui.notify(f"Failed to start BAAH_UPDATE.exe: {e}", type="warning")
ui.button(config.get_text("button_update_advance"), on_click=update_advance)

web_url = {
"github": "https://github.com/sanmusen214/BAAH",
Expand Down
63 changes: 57 additions & 6 deletions gui/refactor_pages/home.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,79 @@
import subprocess
from .json_file_docker import get_json_list
from .json_file_docker import add_new_config

from nicegui import ui
from nicegui import ui, app

from ..components.check_update import get_newest_version
from ..components.exec_arg_parse import check_token_dialog
from ..define import gui_shared_config


def select_language(value):
gui_shared_config.softwareconfigdict["LANGUAGE"] = value
gui_shared_config.save_software_config()
if value == "zh_CN":
ui.notify("语言已切换为中文,重启生效")
else:
ui.notify("Language has been changed, restart to take effect")

@ui.refreshable
def render_json_list():
if check_token_dialog(render_json_list):

ui.label(f"Blue Archive Aris Helper {gui_shared_config.NOWVERSION}").style('font-size: xx-large')
# 语言切换
ui.toggle({"zh_CN":"中文", "en_US":"English", "jp_JP":"日本語"}, value=gui_shared_config.softwareconfigdict["LANGUAGE"], on_change=lambda e:select_language(e.value)).bind_value_from(gui_shared_config.softwareconfigdict, "LANGUAGE")

ui.label(gui_shared_config.get_text("BAAH_desc"))

ui.label(gui_shared_config.get_text("BAAH_get_version"))

# 下载更新包
ui.button(gui_shared_config.get_text("button_check_version"), on_click=lambda e, c=gui_shared_config:get_newest_version(c))

# 一键更新,唤起更新程序,结束gui进程
def update_advance():
try:
subprocess.Popen(["BAAH_UPDATE.exe"], creationflags=subprocess.CREATE_NEW_CONSOLE, close_fds=True)
app.shutdown()
except Exception as e:
ui.notify(f"Failed to start BAAH_UPDATE.exe: {e}", type="warning")
# 一键更新按钮
ui.button(gui_shared_config.get_text("button_update_advance"), on_click=update_advance)

# 网址
web_url = {
"github": "https://github.com/sanmusen214/BAAH",
"bilibili":"https://space.bilibili.com/7331920"
}

with ui.row():
ui.link("Github", web_url["github"], new_tab=True)
ui.input("Github").bind_value_from(web_url, "github").style('width: 400px')

with ui.row():
ui.link("Bilibili", web_url["bilibili"], new_tab=True)
ui.input("Bilibili").bind_value_from(web_url, "bilibili").style('width: 400px')

# 重要设置提醒
ui.label(gui_shared_config.get_text("BAAH_attention")).style('color: red; font-size: x-large')

# ============配置文件区域===========
ui.label(gui_shared_config.get_text("config_file")).style("font-size: xx-large")

# 配置文件名 卡片
for config_name in get_json_list():
with ui.link(target = f"/panel/{config_name}"):
with ui.card().props('flat bordered'):
ui.label(config_name).style("font-size: large;")
with ui.row():
for config_name in get_json_list():
with ui.link(target = f"/panel/{config_name}"):
with ui.card().props('flat bordered'):
ui.label(config_name).style("font-size: large;")

ui.button("+", on_click=add_new_config).style(
# 添加配置
user_config_name = {"val":""}
with ui.row():
ui.input("Name").bind_value(user_config_name, "val")
ui.button("+", on_click=lambda: add_new_config(user_config_name["val"])).style(
"width: 30px; height: 30px; line-height: 30px; text-align: center; cursor: pointer;")


Expand Down
28 changes: 12 additions & 16 deletions gui/refactor_pages/json_file_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@ def get_json_list():
alljson_list = get_json_list()


async def add_new_config():
async def add_new_config(configname):
"""
点击加号后,添加一个新的json配置文件到alljson_list和alljson_tab_list里,然后让Configger类去新建这个json文件
"""
response = await ui.run_javascript('''
return await window.prompt("请输入新配置名/Please input new config name")
''', timeout=60.0)
if not response:
print("未输入配置名/No config name input")
return
print("输入的配置名/Input config name:", response)
response = response.strip().replace(".json", "")
response = response + ".json"
if response in alljson_list:
await ui.alert("配置名已存在/Config name already exists")
configname = configname.strip()
if not configname:
ui.notify("配置名为空!/Config name is None!")
else:
# 创建一个新的json文件
with open(os.path.join(MyConfigger.USER_CONFIG_FOLDER, response), 'w') as f:
f.write("{}")
await ui.run_javascript('location.reload()')
configname = configname.replace(".json", "") + ".json"
if configname in alljson_list:
ui.notify("配置名已存在/Config name already exists")
else:
# 创建一个新的json文件
with open(os.path.join(MyConfigger.USER_CONFIG_FOLDER, configname), 'w') as f:
f.write("{}")
ui.run_javascript('window.location.reload()')
2 changes: 1 addition & 1 deletion modules/configs/MyConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MyConfigger:
"""
维护config字典,包含软件config,用户任务config,语言包
"""
NOWVERSION="1.7.0"
NOWVERSION="1.7.2"
USER_CONFIG_FOLDER="./BAAH_CONFIGS"
SOFTWARE_CONFIG_FOLDER="./DATA/CONFIGS"
LANGUAGE_PACKAGE_FOLDER="./DATA/i18n"
Expand Down
4 changes: 2 additions & 2 deletions modules/configs/defaultSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"AUTO_EVENT_STORY_PUSH":{"d":False},
"EXPLORE_RAINBOW_TEAMS":{"d":False},
"ENABLE_MAIL_NOTI":{"d":False},
"CAFE_TOUCH_WAY_DIFF":{"d":False},
"CAFE_TOUCH_WAY_DIFF":{"d":True},
"USE_VPN":{"d":False},
"VPN_CONFIG":{"d":{
"VPN_ACTIVITY":"com.github.kr328.clash/com.github.kr328.clash.MainActivity",
Expand Down Expand Up @@ -164,7 +164,7 @@
"USE_MEMORY_IMAGE":{"d":False},

# 时间表是否自动选择
"SMART_TIMETABLE":{"d":False},
"SMART_TIMETABLE":{"d":True},
# 时间表各项权重
"TIMETABLE_WEIGHT_OF_REWARD":{"d":10},
"TIMETABLE_WEIGHT_OF_HEART":{"d":20},
Expand Down

0 comments on commit 58dfbbb

Please sign in to comment.