功能:完善终端认证恢复、选择页及策略和指标采集

This commit is contained in:
songyiming committed 2026-11-10 17:51:39 +08:00
1 parent d87fa47e24
commit eef485306f
22 files changed
+904 -151

No files matched your search

+43 -10
View File
@@ -65,11 +65,30 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
auto* refresh=new QTimer(this); refresh->setInterval(15000);
connect(refresh,&QTimer::timeout,this,[this]{ if (fsm_.isIn(State::kDesktopList)) refreshDesktopList(); });
refresh->start();
desktopService_.setPolicyHandler([refresh](int seconds){ refresh->setInterval(seconds*1000); });
}
deviceAuthTimer_ = new QTimer(this);
deviceAuthTimer_->setSingleShot(true);
connect(deviceAuthTimer_, &QTimer::timeout, this, &MainWindow::authenticateDevice);
deviceAuthMessage_ = QStringLiteral("正在连接管理平台,请稍候…");
// Paint the product page before even a synchronous configuration failure.
// Device authentication has no username/password recovery flow.
fsm_.transitionTo(State::kDesktopList, QStringLiteral("请选择要进入的云桌面"));
QTimer::singleShot(0, this, &MainWindow::authenticateDevice);
}
void MainWindow::authenticateDevice() {
if (deviceAuthenticated_ || deviceAuthInFlight_) return;
deviceAuthTimer_->stop();
deviceAuthInFlight_ = true;
const QString deviceUser = QString::fromStdString(config_.sn).trimmed();
desktopService_.login(deviceUser.isEmpty() ? QStringLiteral("terminal") : deviceUser,
QStringLiteral("kiosk"), [this](const AuthResult& result) {
deviceAuthInFlight_ = false;
deviceAuthenticated_ = result.ok;
if (result.ok) {
deviceAuthRetryMs_ = 2000;
qInfo() << "vdi_device_auth result=ready";
currentUser_ = result.displayName;
if (desktopListPage_) {
desktopListPage_->setCurrentUser(currentUser_);
@@ -77,14 +96,19 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
if (fsm_.isIn(State::kDesktopList)) refreshDesktopList();
return;
}
// A real platform authentication failure must still return to the
// login page. The normal device-authenticated boot path never shows
// that page, so the first painted kiosk frame is the desktop list.
// A cold boot may precede Wi-Fi, clock synchronization or the API.
// Stay on the selection page and never substitute local authorization.
deviceAuthMessage_ = QStringLiteral("%1;正在自动重试,无需重启盒子")
.arg(result.message.isEmpty()
? QStringLiteral("管理平台暂不可用")
: result.message);
qWarning() << "vdi_device_auth result=waiting retry_ms=" << deviceAuthRetryMs_;
if (fsm_.isIn(State::kDesktopList)) {
fsm_.transitionTo(State::kConfig, result.message);
refreshDesktopList();
}
deviceAuthTimer_->start(deviceAuthRetryMs_);
deviceAuthRetryMs_ = qMin(deviceAuthRetryMs_ * 2, 30000);
});
fsm_.transitionTo(State::kDesktopList, QStringLiteral("请选择要进入的云桌面"));
}
MainWindow::~MainWindow() {
@@ -155,11 +179,6 @@ void MainWindow::setupUi() {
auto* list = new DesktopListPage(this);
desktopListPage_ = list;
list->setStyleSheet(
QStringLiteral("QWidget { background: #0f1420; color: #e6e9ef; }"
"QPushButton { background: #232d44; border: 1px solid #2b3654; "
"border-radius: 6px; color: #e6e9ef; }"
"QPushButton:hover { background: #2b3654; }"));
stack_->addWidget(list);
connect(list, &DesktopListPage::desktopSelected, this, &MainWindow::onDesktopSelected);
connect(list, &DesktopListPage::editRequested, this, &MainWindow::onEditDesktopRequested);
@@ -169,6 +188,9 @@ void MainWindow::setupUi() {
statusBar_ = new QStatusBar(this);
statusBar_->setStyleSheet(QStringLiteral("QStatusBar { background: #161d2e; color: #8a94a6; }"));
setStatusBar(statusBar_);
// Product feedback is shown in the page/overlay; internal FSM names are
// retained in diagnostics rather than displayed along the screen edge.
statusBar_->hide();
connectionTimer_ = new QTimer(this);
connectionTimer_->setSingleShot(true);
@@ -502,6 +524,15 @@ void MainWindow::showDesktopList() {
}
void MainWindow::refreshDesktopList() {
if (!deviceAuthenticated_) {
desktops_.clear();
if (desktopListPage_) {
desktopListPage_->setDesktops(desktops_);
desktopListPage_->setBusy(true);
desktopListPage_->setStatus(deviceAuthMessage_);
}
return;
}
desktopService_.listDesktops([this](std::vector<DesktopInfo> list, const QString& error) {
if (error.isEmpty()) {
desktops_ = list;
@@ -510,6 +541,7 @@ void MainWindow::refreshDesktopList() {
}
if (desktopListPage_) {
desktopListPage_->setDesktops(desktops_);
desktopListPage_->setBusy(!fsm_.isIn(State::kDesktopList));
if (!error.isEmpty()) {
desktopListPage_->setStatus(error, true);
} else {
@@ -536,6 +568,7 @@ void MainWindow::onLoginRequested(const QString& username, const QString& passwo
}
void MainWindow::onDesktopSelected(const QString& desktopId) {
if (!deviceAuthenticated_) return;
if (!fsm_.canConnect()) {
if (desktopListPage_) {
desktopListPage_->setBusy(false);