vdi-cloud/terminal/kiosk-shell/src/desktop_service.cpp
宋一鸣 ec1566a80e 功能:支持按桌面配置连接参数与多种地址
变更详情:桌面连接可配置化——每卡设置、地址支持 IP/域名/VPN 隧道

- 新增 DesktopStore:~/.config/vdi-terminal/desktops.json 持久化连接参数,
  首次启动生成三张默认卡(待分配),老盒子自动从 client.conf 迁移 server 地址
- 新增 DesktopSettingsDialog:按桌面编辑协议/地址/应用名/分辨率/帧率,
  置顶显示避免被全屏 kiosk 遮挡
- 桌面列表每张卡增加“设置”按钮;管理菜单 Ctrl+Alt+Shift+M 增加入口
- DesktopService 改为从 store 读取;地址为空的桌面显示待分配且不可连接
- 修复:默认卡未按 endpoint 重算状态导致迁移后仍显示待分配
- 实测真机通过:Windows 自动迁移可连接、对话框显示与保存正常
2026-10-29 14:05:35 +08:00

77 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "desktop_service.h"
#include "desktop_store.h"
namespace vdi {
void DesktopService::login(const QString& username, const QString& password, AuthCallback callback) {
// 本地演示认证:账号与密码非空即通过。
// 正式版本替换为 /api/v1/terminal/session/login(SN+用户身份校验)。
AuthResult result;
if (username.trimmed().isEmpty() || password.isEmpty()) {
result.ok = false;
result.message = QStringLiteral("请输入用户名和密码");
} else {
result.ok = true;
result.displayName = username.trimmed();
currentUser_ = username.trimmed();
}
if (callback) {
callback(result);
}
}
void DesktopService::listDesktops(DesktopListCallback callback) {
// 桌面与连接参数来自本地连接配置(现场可配);
// 正式版本替换为 /api/v1/terminal/session/desktops(按用户绑定返回)。
std::vector<DesktopInfo> desktops = DesktopStore::load();
if (callback) {
callback(std::move(desktops), QString());
}
}
void DesktopService::createTicket(const QString& desktopId, TicketCallback callback) {
// 本地演示票据:由连接配置构造。
// 正式版本替换为 /api/v1/terminal/session/connect-ticket(短期一次性票据)。
ConnectionTicket ticket;
ticket.desktopId = desktopId;
QString error;
listDesktops([&ticket, &error, desktopId](std::vector<DesktopInfo> list, const QString& err) {
if (!err.isEmpty()) {
error = err;
return;
}
for (const DesktopInfo& d : list) {
if (d.id != desktopId) {
continue;
}
if (d.state != DesktopState::kAvailable) {
error = QStringLiteral("桌面 %1 尚未配置连接地址,请先在“设置”中完成配置")
.arg(d.name);
return;
}
ticket.protocol = d.protocol;
ticket.endpoint = d.endpoint;
ticket.app = d.app;
ticket.width = d.width;
ticket.height = d.height;
ticket.fps = d.fps;
return;
}
if (error.isEmpty() && ticket.endpoint.isEmpty()) {
error = QStringLiteral("桌面不存在");
}
});
if (callback) {
callback(ticket, error);
}
}
void DesktopService::logout() {
currentUser_.clear();
}
} // namespace vdi