重构:桌面数据改为从本地连接配置读取
This commit is contained in:
parent
558fa587ff
commit
4ab108bf53
@ -1,5 +1,7 @@
|
||||
#include "desktop_service.h"
|
||||
|
||||
#include "desktop_store.h"
|
||||
|
||||
namespace vdi {
|
||||
|
||||
void DesktopService::login(const QString& username, const QString& password, AuthCallback callback) {
|
||||
@ -20,59 +22,34 @@ void DesktopService::login(const QString& username, const QString& password, Aut
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
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);
|
||||
break;
|
||||
error = QStringLiteral("桌面 %1 尚未配置连接地址,请先在“设置”中完成配置")
|
||||
.arg(d.name);
|
||||
return;
|
||||
}
|
||||
ticket.protocol = d.protocol;
|
||||
ticket.endpoint = d.endpoint;
|
||||
@ -80,10 +57,12 @@ void DesktopService::createTicket(const QString& desktopId, TicketCallback callb
|
||||
ticket.width = d.width;
|
||||
ticket.height = d.height;
|
||||
ticket.fps = d.fps;
|
||||
error.clear();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (error.isEmpty() && ticket.endpoint.isEmpty()) {
|
||||
error = QStringLiteral("桌面不存在");
|
||||
}
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback(ticket, error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user