mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 12:15:34 +08:00
[feat] split remote id into chunks of three characters separated by space
This commit is contained in:
@@ -48,16 +48,17 @@ int Render::LocalWindow() {
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||
|
||||
std::string client_id_show = "";
|
||||
std::string client_id_display = "";
|
||||
for (int i = 0; i < sizeof(client_id_); i++) {
|
||||
client_id_show += client_id_[i];
|
||||
client_id_display += client_id_[i];
|
||||
if (i == 2 || i == 5) {
|
||||
client_id_show += " ";
|
||||
client_id_display += " ";
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::InputText(
|
||||
"##local_id", (char *)client_id_show.c_str(), sizeof(client_id_show),
|
||||
"##local_id", (char *)client_id_display.c_str(),
|
||||
sizeof(client_id_display),
|
||||
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
#include "rd_log.h"
|
||||
#include "render.h"
|
||||
|
||||
static int InputTextCallback(ImGuiInputTextCallbackData *data) {
|
||||
if (data->CursorPos == 3 || data->CursorPos == 7) {
|
||||
data->InsertChars(data->CursorPos, " ");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Render::RemoteWindow() {
|
||||
ImGui::SetNextWindowPos(ImVec2(local_window_width_ - 1, title_bar_height_),
|
||||
ImGuiCond_Always);
|
||||
@@ -47,9 +54,12 @@ int Render::RemoteWindow() {
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||
bool enter_pressed = ImGui::InputText(
|
||||
"##remote_id_", remote_id_, IM_ARRAYSIZE(remote_id_),
|
||||
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank |
|
||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
"##remote_id_", remote_id_display_, IM_ARRAYSIZE(remote_id_display_),
|
||||
ImGuiInputTextFlags_CharsUppercase |
|
||||
ImGuiInputTextFlags_EnterReturnsTrue |
|
||||
ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CharsNoBlank,
|
||||
InputTextCallback);
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) ||
|
||||
@@ -59,7 +69,11 @@ int Render::RemoteWindow() {
|
||||
int ret = -1;
|
||||
if (signal_connected_) {
|
||||
if (!connection_established_) {
|
||||
if (0 == strcmp(remote_id_, client_id_) && !peer_reserved_) {
|
||||
remote_id_ = remote_id_display_;
|
||||
remote_id_.erase(remove_if(remote_id_.begin(), remote_id_.end(),
|
||||
static_cast<int (*)(int)>(&isspace)),
|
||||
remote_id_.end());
|
||||
if (0 == strcmp(remote_id_.c_str(), client_id_) && !peer_reserved_) {
|
||||
peer_reserved_ = CreatePeer(¶ms_);
|
||||
if (peer_reserved_) {
|
||||
LOG_INFO("Create peer[reserved] instance successful");
|
||||
@@ -72,7 +86,7 @@ int Render::RemoteWindow() {
|
||||
}
|
||||
}
|
||||
ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_,
|
||||
remote_id_, remote_password_.c_str());
|
||||
remote_id_.c_str(), remote_password_.c_str());
|
||||
if (0 == ret) {
|
||||
is_client_mode_ = true;
|
||||
rejoin_ = false;
|
||||
|
||||
@@ -499,7 +499,8 @@ int Render::Run() {
|
||||
LOG_INFO("Return to main interface");
|
||||
streaming_ = false;
|
||||
LOG_INFO("[{}] Leave connection [{}]", client_id_, remote_id_);
|
||||
LeaveConnection(peer_reserved_ ? peer_reserved_ : peer_, remote_id_);
|
||||
LeaveConnection(peer_reserved_ ? peer_reserved_ : peer_,
|
||||
remote_id_.c_str());
|
||||
rejoin_ = false;
|
||||
memset(audio_buffer_, 0, 960);
|
||||
connection_established_ = false;
|
||||
|
||||
@@ -122,8 +122,8 @@ class Render {
|
||||
char input_password_[7] = "";
|
||||
std::string random_password_ = "";
|
||||
std::string remote_password_ = "";
|
||||
std::string local_id_ = "";
|
||||
char remote_id_[20] = "";
|
||||
char remote_id_display_[12] = "";
|
||||
std::string remote_id_ = "";
|
||||
char client_password_[20] = "";
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user