vdi-cloud/terminal/kiosk-shell/src/desktop_service.cpp
宋一鸣 61127fb714 功能:实现桌面选择流程并接入 Moonlight 会话
变更详情:feat(kiosk-shell): 登录/桌面列表产品流程 + Moonlight 会话 + 看门狗进程组修复

- 登录页改为用户认证(本地演示认证,账号密码非空通过)
- 新增桌面列表页:Windows/Moonlight 可连接,Ubuntu/麒麟待分配
- 新增 DesktopService 适配层(登录/桌面列表/连接票据,后续接 API)
- 新增 MoonlightSession:QProcess 参数数组直启 moonlight-qt,退出回列表
- 状态机扩展 AUTHENTICATING / DESKTOP_LIST
- 移除开机自动 RDP,收敛为 monitor -> kiosk-shell 单一自启链
- Monitor 按进程组结束整棵进程树,修复孤儿串流进程
- vdi-moonlight 启动器新增 vsync/frame-pacing/overlay 低延迟开关
2026-10-28 20:48:12 +08:00

98 lines
3.2 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"
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) {
// 本地演示数据:Windows 可用(Moonlight),Ubuntu/麒麟尚未分配连接信息。
// 正式版本替换为 /api/v1/terminal/session/desktops(按用户绑定返回)。
std::vector<DesktopInfo> desktops;
DesktopInfo windows;
windows.id = QStringLiteral("desk-win10-01");
windows.name = QStringLiteral("Windows 10");
windows.os = QStringLiteral("Windows 10 22H2 专业版");
windows.protocol = Protocol::kMoonlight;
windows.state = DesktopState::kAvailable;
windows.endpoint = QStringLiteral("192.168.1.70");
windows.app = QStringLiteral("Desktop");
desktops.push_back(windows);
DesktopInfo ubuntu;
ubuntu.id = QStringLiteral("desk-ubuntu-01");
ubuntu.name = QStringLiteral("Ubuntu");
ubuntu.os = QStringLiteral("Ubuntu 桌面");
ubuntu.protocol = Protocol::kRdp;
ubuntu.state = DesktopState::kUnassigned;
desktops.push_back(ubuntu);
DesktopInfo kylin;
kylin.id = QStringLiteral("desk-kylin-01");
kylin.name = QStringLiteral("麒麟");
kylin.os = QStringLiteral("银河麒麟桌面");
kylin.protocol = Protocol::kRdp;
kylin.state = DesktopState::kUnassigned;
desktops.push_back(kylin);
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;
std::vector<DesktopInfo> desktops;
QString error;
listDesktops([&desktops, &error](std::vector<DesktopInfo> list, const QString& err) {
desktops = std::move(list);
error = err;
});
for (const DesktopInfo& d : desktops) {
if (d.id == desktopId) {
if (d.state != DesktopState::kAvailable) {
error = QStringLiteral("桌面 %1 尚未分配连接信息").arg(d.name);
break;
}
ticket.protocol = d.protocol;
ticket.endpoint = d.endpoint;
ticket.app = d.app;
ticket.width = d.width;
ticket.height = d.height;
ticket.fps = d.fps;
error.clear();
break;
}
}
if (callback) {
callback(ticket, error);
}
}
void DesktopService::logout() {
currentUser_.clear();
}
} // namespace vdi