forked from QiuChenly/InjectLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
127 lines (107 loc) · 5.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import sys
import json
from src.utils.ui_helper import ensure_black_background, wait_for_enter
from src.ui.banner import print_banner
from src.app.scanner import scan_apps
from src.app.app_manager import AppManager
from src.ui.menu_manager import MenuManager
from src.utils.i18n import I18n, _
from src.ui.language_selector import change_language_with_menu, auto_set_language
from src.ui.sakura_animation import SakuraAnimation
from src.ui.panda_animation import PandaAnimation
def main():
try:
# 确保整个程序运行期间保持黑色背景
ensure_black_background()
# 加载配置
config_path = "config.json"
if os.path.exists(config_path):
with open(config_path, "r") as f:
config = json.load(f)
else:
config = {"Version": "1.0.0"}
proc_version = config.get("Version", "1.0.0")
# 使用自动语言检测设置语言
auto_set_language(config)
# 根据语言显示不同的欢迎动画
if I18n._current_language == I18n.JAPANESE:
# 日语:显示樱花花瓣雨动画
sakura_animation = SakuraAnimation(duration=5, num_petals=150, static_petals=500)
sakura_animation.play()
elif I18n._current_language == I18n.CHINESE:
# 中文:显示熊猫动画
panda_animation = PandaAnimation(duration=5)
panda_animation.play()
# 扫描安装的应用(不再显示重复的扫描提示)
installed_apps = scan_apps()
# 初始化应用管理器
app_manager = AppManager(config, installed_apps)
# 初始化菜单管理器
menu_manager = MenuManager(app_manager, proc_version, config)
# 主程序循环
while True:
# 确保每次循环都保持黑色背景
ensure_black_background()
# 显示主菜单
choice = menu_manager.show_main_menu()
# 处理特殊命令:直接选择应用
if choice and choice.startswith("SELECT:"):
try:
# 获取应用索引
app_idx = int(choice.split(":")[-1])
# 应用索引的检查已经在handle_app_selection中处理
app_manager.handle_app_selection(app_idx)
except (ValueError, IndexError) as e:
print(_("invalid_app_selection", "无效的应用选择"))
print(f"错误详情: {str(e)}")
wait_for_enter()
continue
# 处理标准菜单选项
elif choice in ['1', '2', '3', '4', '5']:
if choice == '1':
# 按关键字搜索应用
apps = menu_manager.handle_app_search()
if apps:
app_manager.add_selected_apps(apps)
print(_("apps_added_message").format(len(apps), app_manager.get_selected_count()))
wait_for_enter()
elif choice == '2':
# 浏览所有支持的应用
apps = menu_manager.handle_browse_all_apps()
if apps:
app_manager.add_selected_apps(apps)
print(_("apps_added_message").format(len(apps), app_manager.get_selected_count()))
wait_for_enter()
elif choice == '3':
# 处理已选择的应用
menu_manager.handle_process_apps()
elif choice == '4':
# 使用新的语言选择菜单
previous_language = config.get("Language", "en_US")
change_language_with_menu(config)
# 根据新选择的语言显示不同的欢迎动画
current_language = config.get("Language", "en_US")
if current_language != previous_language:
if current_language == I18n.JAPANESE:
# 日语:显示樱花花瓣雨动画
sakura_animation = SakuraAnimation(duration=5, num_petals=150, static_petals=500)
sakura_animation.play()
elif current_language == I18n.CHINESE:
# 中文:显示熊猫动画
panda_animation = PandaAnimation(duration=5)
panda_animation.play()
elif choice == '5':
# 退出程序
print("\n" + _("thank_you_message", "感谢使用,再见!"))
break
else:
print(_("invalid_choice", "无效的选择,请重新选择"))
wait_for_enter()
except KeyboardInterrupt:
print("\n" + _("user_interrupted", "用户手动退出程序,祝你使用愉快,再见."))
except Exception as e:
print(_("error_occurred", "发生错误: {0}").format(e))
wait_for_enter()
if __name__ == "__main__":
main()