refactor(gui): move membership summary to window title

This commit is contained in:
chengma
2026-07-23 14:51:05 +08:00
parent fd82d3b047
commit c734e3fe79
5 changed files with 84 additions and 66 deletions
+30 -41
View File
@@ -130,28 +130,10 @@ class MainWindow(QMainWindow):
settings_tab = self._settings_tab()
if hasattr(settings_tab, "settingsSaved"):
settings_tab.settingsSaved.connect(self._on_settings_saved)
subscription_label_text = (
"会员:正在验证"
if SUBSCRIPTION_CHECK_ENABLED
else "会员:订阅检测已暂停"
)
self._subscription_label = QLabel(subscription_label_text)
self._subscription_label.setObjectName("subscriptionStatusLabel")
self._subscription_label.setAccessibleName("会员状态")
self._subscription_label.setStyleSheet("color: #0969da;")
header = QWidget()
header.setObjectName("appHeader")
header.setAccessibleName("会员状态栏")
header_layout = QHBoxLayout(header)
header_layout.setContentsMargins(18, 4, 18, 2)
header_layout.setSpacing(0)
header_layout.addStretch(1)
header_layout.addWidget(self._subscription_label)
central = QWidget()
central_layout = QVBoxLayout(central)
central_layout.setContentsMargins(0, 0, 0, 0)
central_layout.setSpacing(0)
central_layout.addWidget(header)
central_layout.addWidget(self.tabs, 1)
self.setCentralWidget(central)
self.show_status("就绪", level="muted")
@@ -244,16 +226,17 @@ class MainWindow(QMainWindow):
def begin_subscription_check(self):
"""Refresh membership state without blocking the Qt GUI thread."""
self._set_membership_window_title()
if not SUBSCRIPTION_CHECK_ENABLED:
self._set_product_access(True)
self._set_subscription_label("会员:订阅检测已暂停", "muted")
self.show_status("会员订阅检测已暂停", level="muted")
return
self._subscription_request_token += 1
token = self._subscription_request_token
if self._subscription_worker is not None:
self._subscription_worker.cancel()
self._set_product_access(not SUBSCRIPTION_ENFORCEMENT_ENABLED)
self._set_subscription_label("会员:正在验证", "info")
self.show_status("正在验证会员状态", level="info")
worker = SubscriptionCheckWorker(
config=self.config,
cmhub_config_path=self.config.get("cmhub_config_path"),
@@ -309,26 +292,22 @@ class MainWindow(QMainWindow):
self._subscription_status = status
if status.state == subscription.STATUS_ACTIVE:
expiry = subscription.format_expiry(status.expires_at)
self._set_subscription_label(
"%s · %s · 有效至%s" % (status.account_name, status.plan_name, expiry),
"success",
self._set_membership_window_title(
status.account_name,
status.plan_name,
"有效至%s" % expiry,
)
elif status.state == subscription.STATUS_GRACE:
expiry = subscription.format_expiry(status.grace_expires_at) or subscription.format_expiry(status.expires_at)
self._set_subscription_label(
"%s · %s · 宽限至%s" % (status.account_name, status.plan_name, expiry),
"warning",
)
elif SUBSCRIPTION_ENFORCEMENT_ENABLED:
self._set_subscription_label(
"会员:%s" % status.user_message,
self._subscription_level(status),
expiry = subscription.format_expiry(
status.grace_expires_at
) or subscription.format_expiry(status.expires_at)
self._set_membership_window_title(
status.account_name,
status.plan_name,
"宽限至%s" % expiry,
)
else:
self._set_subscription_label(
"会员观察:%s(当前不影响使用)" % status.user_message,
self._subscription_level(status),
)
self._set_membership_window_title()
access_allowed = (
status.allows_product_workflows
@@ -363,11 +342,21 @@ class MainWindow(QMainWindow):
return "warning"
return "danger"
def _set_subscription_label(self, text, level):
color = _status_level_color(level)
self._subscription_label.setText(str(text))
self._subscription_label.setStyleSheet("color: %s;" % color)
self._subscription_label.setToolTip(str(text))
def _set_membership_window_title(
self,
account_name="",
plan_name="",
expiry_text="",
):
account = " ".join(str(account_name or "").split())
plan = " ".join(str(plan_name or "").split())
expiry = " ".join(str(expiry_text or "").split())
if account and plan and expiry:
self.setWindowTitle(
"%s | %s · %s · %s" % (display_name(), account, plan, expiry)
)
return
self.setWindowTitle(display_name())
def _set_product_access(self, enabled):
for index, title in enumerate(TAB_TITLES):