Skip to content

Commit 3c6a2bc

Browse files
committed
feat: 标题栏版本号增加启动器类型tag
启动器分集成(exe打包)和源码两种运行方式,标题栏版本号无法区分当前是哪种环境,排查问题时不直观。新增主题色胶囊tag显示「集成/源码」,随主题色变化自动刷新。
1 parent ee00b66 commit 3c6a2bc

2 files changed

Lines changed: 74 additions & 20 deletions

File tree

src/one_dragon_qt/windows/window.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SplitTitleBar,
1818
isDarkTheme,
1919
qconfig,
20+
themeColor,
2021
)
2122
from qfluentwidgets.common.animation import BackgroundAnimationWidget
2223
from qfluentwidgets.components.widgets.frameless_window import FramelessWindow
@@ -123,6 +124,17 @@ def __init__(self, parent=None):
123124
btn_layout = QHBoxLayout()
124125
btn_layout.setContentsMargins(0, 0, 0, 0)
125126

127+
# 启动器类型 tag(集成/源码),使用主题色背景
128+
self.launchTagLabel = QLabel(self)
129+
self.launchTagLabel.setObjectName("launchTagLabel")
130+
self.launchTagLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
131+
self.launchTagLabel.setVisible(False)
132+
btn_layout.addWidget(
133+
self.launchTagLabel,
134+
0,
135+
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignBottom,
136+
)
137+
126138
self.launcherVersionButton = QPushButton("ⓘ 启动器版本 未知")
127139
self.launcherVersionButton.setObjectName("launcherVersionButton")
128140
self.launcherVersionButton.clicked.connect(lambda: self.copy_version(self.launcher_version))
@@ -157,10 +169,16 @@ def __init__(self, parent=None):
157169
self.issue_url: str = ""
158170
self.launcher_version: str = ""
159171
self.code_version: str = ""
172+
self.launch_tag: str = ""
173+
174+
# 主题色变化时刷新 tag 样式
175+
qconfig.themeColorChanged.connect(self._update_launch_tag_style)
176+
qconfig.themeChangedFinished.connect(self._update_launch_tag_style)
160177

161178
# 首页模式下需要添加阴影的控件列表
162179
self._home_shadow_targets: list[QWidget] = [
163180
self.titleLabel,
181+
self.launchTagLabel,
164182
self.launcherVersionButton,
165183
self.codeVersionButton,
166184
self.questionButton,
@@ -200,6 +218,31 @@ def setCodeVersion(self, version: str) -> None:
200218
if version:
201219
self.codeVersionButton.setVisible(True)
202220

221+
def setLaunchTag(self, tag: str) -> None:
222+
"""
223+
设置启动器类型 tag(集成/源码) 会更新UI
224+
@param tag: 启动器类型
225+
@return:
226+
"""
227+
self.launch_tag = tag
228+
if tag:
229+
self.launchTagLabel.setText(tag)
230+
self._update_launch_tag_style()
231+
self.launchTagLabel.setVisible(True)
232+
else:
233+
self.launchTagLabel.setVisible(False)
234+
235+
def _update_launch_tag_style(self) -> None:
236+
"""按当前主题色刷新 tag 样式(主题色或明暗主题变化时调用)"""
237+
if not self.launch_tag:
238+
return
239+
color = themeColor().name()
240+
self.launchTagLabel.setStyleSheet(
241+
f"color: white; background-color: {color}; "
242+
"border-radius: 8px; padding: 1px 8px; "
243+
"font: 11px 'Segoe UI', 'Microsoft YaHei';"
244+
)
245+
203246
def setInstallerVersion(self, version: str) -> None:
204247
"""
205248
设置安装器版本号 会更新UI

src/zzz_od/gui/app.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from qfluentwidgets import NavigationItemPosition, Theme, setTheme
77

88
from one_dragon.base.operation.one_dragon_context import ContextInstanceEventEnum
9-
from one_dragon.utils import app_utils
9+
from one_dragon.utils import app_utils, os_utils
1010
from one_dragon.utils.i18_utils import gt
1111
from one_dragon_qt.overlay.overlay_manager import OverlayManager
1212
from one_dragon_qt.services.styles_manager import OdQtStyleSheet
@@ -43,7 +43,11 @@ def __init__(self, ctx: ZContext, parent=None):
4343
def run(self):
4444
launcher_version = app_utils.get_launcher_version()
4545
code_version = self.ctx.git_service.get_current_version()
46-
versions = (launcher_version, code_version)
46+
47+
# 区分启动器类型:集成启动器(exe 打包运行)与源码启动器
48+
launch_tag = '集成' if os_utils.run_in_exe() else '源码'
49+
50+
versions = (launcher_version, code_version, launch_tag)
4751
self.get.emit(versions)
4852

4953
# 定义应用程序的主窗口类
@@ -61,11 +65,8 @@ def __init__(self, ctx: ZContext, parent=None):
6165
MainAppWindowBase.__init__(
6266
self,
6367
ctx=ctx,
64-
win_title="%s %s"
65-
% (
66-
gt(ctx.project_config.project_name),
67-
ctx.one_dragon_config.current_active_instance.name,
68-
),
68+
win_title=f"{gt(ctx.project_config.project_name)} "
69+
f"{ctx.one_dragon_config.current_active_instance.name}",
6970
project_config=ctx.project_config,
7071
app_icon="logo.ico",
7172
parent=parent,
@@ -123,15 +124,21 @@ def create_sub_interface(self):
123124
self.add_sub_interface(HomeInterface(self.ctx, parent=self))
124125

125126
# 游戏助手
126-
from zzz_od.gui.view.game_assistant.game_assistant_interface import GameAssistantInterface
127+
from zzz_od.gui.view.game_assistant.game_assistant_interface import (
128+
GameAssistantInterface,
129+
)
127130
self.add_sub_interface(GameAssistantInterface(self.ctx, parent=self))
128131

129132
# 一条龙
130-
from zzz_od.gui.view.one_dragon.zzz_one_dragon_interface import ZOneDragonInterface
133+
from zzz_od.gui.view.one_dragon.zzz_one_dragon_interface import (
134+
ZOneDragonInterface,
135+
)
131136
self.add_sub_interface(ZOneDragonInterface(self.ctx, parent=self))
132137

133138
# 应用运行
134-
from zzz_od.gui.view.standalone.zzz_standalone_app_interface import ZStandaloneAppInterface
139+
from zzz_od.gui.view.standalone.zzz_standalone_app_interface import (
140+
ZStandaloneAppInterface,
141+
)
135142
self.add_sub_interface(ZStandaloneAppInterface(self.ctx, parent=self))
136143

137144
# 画中画
@@ -147,7 +154,9 @@ def create_sub_interface(self):
147154
)
148155

149156
# 开发工具
150-
from zzz_od.gui.view.devtools.app_devtools_interface import AppDevtoolsInterface
157+
from zzz_od.gui.view.devtools.app_devtools_interface import (
158+
AppDevtoolsInterface,
159+
)
151160
self.add_sub_interface(
152161
AppDevtoolsInterface(self.ctx, parent=self),
153162
position=NavigationItemPosition.BOTTOM,
@@ -161,14 +170,18 @@ def create_sub_interface(self):
161170
)
162171

163172
# 多账号管理
164-
from zzz_od.gui.view.accounts.app_accounts_interface import AccountsInterface
173+
from zzz_od.gui.view.accounts.app_accounts_interface import (
174+
AccountsInterface,
175+
)
165176
self.add_sub_interface(
166177
AccountsInterface(self.ctx, parent=self),
167178
position=NavigationItemPosition.BOTTOM,
168179
)
169180

170181
# 设置
171-
from zzz_od.gui.view.setting.app_setting_interface import AppSettingInterface
182+
from zzz_od.gui.view.setting.app_setting_interface import (
183+
AppSettingInterface,
184+
)
172185
self.add_sub_interface(
173186
AppSettingInterface(self.ctx, parent=self),
174187
position=NavigationItemPosition.BOTTOM,
@@ -194,21 +207,19 @@ def _on_instance_active_signal(self) -> None:
194207
:return:
195208
"""
196209
self.setWindowTitle(
197-
"%s %s"
198-
% (
199-
gt(self.ctx.project_config.project_name),
200-
self.ctx.one_dragon_config.current_active_instance.name,
201-
)
210+
f"{gt(self.ctx.project_config.project_name)} "
211+
f"{self.ctx.one_dragon_config.current_active_instance.name}"
202212
)
203213

204-
def _update_version(self, versions: tuple[str, str]) -> None:
214+
def _update_version(self, versions: tuple[str, str, str]) -> None:
205215
"""
206216
更新版本显示
207-
@param ver:
217+
@param versions: (启动器版本, 代码版本, 启动器类型tag)
208218
@return:
209219
"""
210220
self.titleBar.setLauncherVersion(versions[0])
211221
self.titleBar.setCodeVersion(versions[1])
222+
self.titleBar.setLaunchTag(versions[2])
212223

213224
def _check_first_run(self):
214225
"""首次运行时显示防倒卖弹窗"""

0 commit comments

Comments
 (0)