mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-26 02:25:18 +08:00
[feat] display remote controller hostname instead of remote id
This commit is contained in:
@@ -668,7 +668,9 @@ class Render {
|
|||||||
|
|
||||||
/* ------ server mode ------ */
|
/* ------ server mode ------ */
|
||||||
std::unordered_map<std::string, ConnectionStatus> connection_status_;
|
std::unordered_map<std::string, ConnectionStatus> connection_status_;
|
||||||
|
std::unordered_map<std::string, std::string> connection_host_names_;
|
||||||
std::string selected_server_remote_id_ = "";
|
std::string selected_server_remote_id_ = "";
|
||||||
|
std::string selected_server_remote_hostname_ = "";
|
||||||
FileTransferState file_transfer_;
|
FileTransferState file_transfer_;
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -495,24 +495,39 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
|
|
||||||
std::string remote_id(user_id, user_id_size);
|
std::string remote_id(user_id, user_id_size);
|
||||||
// std::shared_lock lock(render->client_properties_mutex_);
|
// std::shared_lock lock(render->client_properties_mutex_);
|
||||||
if (render->client_properties_.find(remote_id) !=
|
if (remote_action.type == ControlType::host_infomation) {
|
||||||
render->client_properties_.end()) {
|
if (render->client_properties_.find(remote_id) !=
|
||||||
// local
|
render->client_properties_.end()) {
|
||||||
auto props = render->client_properties_.find(remote_id)->second;
|
// client mode
|
||||||
if (remote_action.type == ControlType::host_infomation &&
|
auto props = render->client_properties_.find(remote_id)->second;
|
||||||
props->remote_host_name_.empty()) {
|
if (props && props->remote_host_name_.empty()) {
|
||||||
props->remote_host_name_ = std::string(remote_action.i.host_name,
|
props->remote_host_name_ = std::string(remote_action.i.host_name,
|
||||||
remote_action.i.host_name_size);
|
remote_action.i.host_name_size);
|
||||||
LOG_INFO("Remote hostname: [{}]", props->remote_host_name_);
|
LOG_INFO("Remote hostname: [{}]", props->remote_host_name_);
|
||||||
|
|
||||||
|
for (int i = 0; i < remote_action.i.display_num; i++) {
|
||||||
|
props->display_info_list_.push_back(
|
||||||
|
DisplayInfo(remote_action.i.display_list[i],
|
||||||
|
remote_action.i.left[i], remote_action.i.top[i],
|
||||||
|
remote_action.i.right[i], remote_action.i.bottom[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FreeRemoteAction(remote_action);
|
||||||
|
} else {
|
||||||
|
// server mode
|
||||||
|
render->connection_host_names_[remote_id] = std::string(
|
||||||
|
remote_action.i.host_name, remote_action.i.host_name_size);
|
||||||
|
LOG_INFO("Remote hostname: [{}]",
|
||||||
|
render->connection_host_names_[remote_id]);
|
||||||
|
|
||||||
for (int i = 0; i < remote_action.i.display_num; i++) {
|
for (int i = 0; i < remote_action.i.display_num; i++) {
|
||||||
props->display_info_list_.push_back(
|
render->display_info_list_.push_back(
|
||||||
DisplayInfo(remote_action.i.display_list[i],
|
DisplayInfo(remote_action.i.display_list[i],
|
||||||
remote_action.i.left[i], remote_action.i.top[i],
|
remote_action.i.left[i], remote_action.i.top[i],
|
||||||
remote_action.i.right[i], remote_action.i.bottom[i]));
|
remote_action.i.right[i], remote_action.i.bottom[i]));
|
||||||
}
|
}
|
||||||
|
FreeRemoteAction(remote_action);
|
||||||
}
|
}
|
||||||
FreeRemoteAction(remote_action);
|
|
||||||
} else {
|
} else {
|
||||||
// remote
|
// remote
|
||||||
if (remote_action.type == ControlType::mouse && render->mouse_controller_) {
|
if (remote_action.type == ControlType::mouse && render->mouse_controller_) {
|
||||||
|
|||||||
@@ -106,44 +106,61 @@ int Render::RemoteClientInfoWindow() {
|
|||||||
|
|
||||||
float font_scale = localization_language_index_ == 0 ? 0.5f : 0.45f;
|
float font_scale = localization_language_index_ == 0 ? 0.5f : 0.45f;
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(localization_language_index_ == 0 ? 0.5f : 0.48f);
|
std::vector<std::string> remote_hostnames;
|
||||||
|
remote_hostnames.reserve(connection_host_names_.size());
|
||||||
std::vector<std::string> remote_ids;
|
for (const auto& kv : connection_host_names_) {
|
||||||
remote_ids.reserve(connection_status_.size());
|
remote_hostnames.push_back(kv.second);
|
||||||
for (const auto& kv : connection_status_) {
|
|
||||||
remote_ids.push_back(kv.first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selected_server_remote_id_.empty()) {
|
auto find_remote_id_by_hostname =
|
||||||
if (std::find(remote_ids.begin(), remote_ids.end(),
|
[this](const std::string& hostname) -> std::string {
|
||||||
selected_server_remote_id_) == remote_ids.end()) {
|
for (const auto& kv : connection_host_names_) {
|
||||||
|
if (kv.second == hostname) {
|
||||||
|
return kv.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!selected_server_remote_hostname_.empty()) {
|
||||||
|
if (std::find(remote_hostnames.begin(), remote_hostnames.end(),
|
||||||
|
selected_server_remote_hostname_) == remote_hostnames.end()) {
|
||||||
|
selected_server_remote_hostname_.clear();
|
||||||
selected_server_remote_id_.clear();
|
selected_server_remote_id_.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selected_server_remote_id_.empty() && !remote_ids.empty()) {
|
if (selected_server_remote_hostname_.empty() && !remote_hostnames.empty()) {
|
||||||
selected_server_remote_id_ = remote_ids.front();
|
selected_server_remote_hostname_ = remote_hostnames.front();
|
||||||
|
selected_server_remote_id_ =
|
||||||
|
find_remote_id_by_hostname(selected_server_remote_hostname_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SetWindowFontScale(font_scale);
|
||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
ImGui::Text("%s",
|
ImGui::Text("%s",
|
||||||
localization::controller[localization_language_index_].c_str());
|
localization::controller[localization_language_index_].c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
const char* selected_preview = "-";
|
const char* selected_preview = "-";
|
||||||
if (!selected_server_remote_id_.empty()) {
|
if (!selected_server_remote_hostname_.empty()) {
|
||||||
selected_preview = selected_server_remote_id_.c_str();
|
selected_preview = selected_server_remote_hostname_.c_str();
|
||||||
} else if (!remote_client_id_.empty()) {
|
} else if (!remote_client_id_.empty()) {
|
||||||
selected_preview = remote_client_id_.c_str();
|
selected_preview = remote_client_id_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetNextItemWidth(remote_client_info_window_width *
|
ImGui::SetNextItemWidth(remote_client_info_window_width *
|
||||||
(localization_language_index_ == 0 ? 0.65f : 0.6f));
|
(localization_language_index_ == 0 ? 0.68f : 0.62f));
|
||||||
|
ImGui::SetWindowFontScale(localization_language_index_ == 0 ? 0.45f : 0.4f);
|
||||||
|
ImGui::AlignTextToFramePadding();
|
||||||
if (ImGui::BeginCombo("##server_remote_id", selected_preview)) {
|
if (ImGui::BeginCombo("##server_remote_id", selected_preview)) {
|
||||||
ImGui::SetWindowFontScale(font_scale);
|
ImGui::SetWindowFontScale(localization_language_index_ == 0 ? 0.45f : 0.4f);
|
||||||
for (int i = 0; i < static_cast<int>(remote_ids.size()); i++) {
|
for (int i = 0; i < static_cast<int>(remote_hostnames.size()); i++) {
|
||||||
const bool selected = (remote_ids[i] == selected_server_remote_id_);
|
const bool selected =
|
||||||
if (ImGui::Selectable(remote_ids[i].c_str(), selected)) {
|
(remote_hostnames[i] == selected_server_remote_hostname_);
|
||||||
selected_server_remote_id_ = remote_ids[i];
|
if (ImGui::Selectable(remote_hostnames[i].c_str(), selected)) {
|
||||||
|
selected_server_remote_hostname_ = remote_hostnames[i];
|
||||||
|
selected_server_remote_id_ =
|
||||||
|
find_remote_id_by_hostname(selected_server_remote_hostname_);
|
||||||
}
|
}
|
||||||
if (selected) {
|
if (selected) {
|
||||||
ImGui::SetItemDefaultFocus();
|
ImGui::SetItemDefaultFocus();
|
||||||
@@ -167,7 +184,7 @@ int Render::RemoteClientInfoWindow() {
|
|||||||
localization::connection_status[localization_language_index_].c_str());
|
localization::connection_status[localization_language_index_].c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
switch (connection_status_[selected_server_remote_id_]) {
|
switch (status) {
|
||||||
case ConnectionStatus::Connected:
|
case ConnectionStatus::Connected:
|
||||||
ImGui::Text(
|
ImGui::Text(
|
||||||
"%s",
|
"%s",
|
||||||
|
|||||||
Reference in New Issue
Block a user