mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
1.Enable random password; 2.Request user to input password when password is incorrect
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ int Render::ConnectionStatusWindow() {
|
|||||||
connection_status_window_height_));
|
connection_status_window_height_));
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
||||||
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
||||||
@@ -32,43 +32,93 @@ int Render::ConnectionStatusWindow() {
|
|||||||
|
|
||||||
if (ConnectionStatus::Connecting == connection_status_) {
|
if (ConnectionStatus::Connecting == connection_status_) {
|
||||||
text = "Connecting...";
|
text = "Connecting...";
|
||||||
|
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
||||||
|
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||||
|
// Cancel
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
} else if (ConnectionStatus::Connected == connection_status_) {
|
} else if (ConnectionStatus::Connected == connection_status_) {
|
||||||
text = "Connected";
|
text = "Connected";
|
||||||
} else if (ConnectionStatus::Disconnected == connection_status_) {
|
} else if (ConnectionStatus::Disconnected == connection_status_) {
|
||||||
text = "Disonnected";
|
text = "Disonnected";
|
||||||
|
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
||||||
|
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||||
|
// Cancel
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
} else if (ConnectionStatus::Failed == connection_status_) {
|
} else if (ConnectionStatus::Failed == connection_status_) {
|
||||||
text = "Failed";
|
text = "Failed";
|
||||||
|
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
||||||
|
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||||
|
// Cancel
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
} else if (ConnectionStatus::Closed == connection_status_) {
|
} else if (ConnectionStatus::Closed == connection_status_) {
|
||||||
text = "Closed";
|
text = "Closed";
|
||||||
|
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
||||||
|
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||||
|
// Cancel
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
} else if (ConnectionStatus::IncorrectPassword == connection_status_) {
|
} else if (ConnectionStatus::IncorrectPassword == connection_status_) {
|
||||||
text = "Incorrect password";
|
text = "Please input password";
|
||||||
|
auto window_width = ImGui::GetWindowSize().x;
|
||||||
|
auto window_height = ImGui::GetWindowSize().y;
|
||||||
|
ImGui::SetCursorPosX((window_width - IPUT_WINDOW_WIDTH / 2) * 0.5f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.4f);
|
||||||
|
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2);
|
||||||
|
ImGui::InputText("##password", (char *)remote_password_.c_str(), 7,
|
||||||
|
ImGuiInputTextFlags_CharsNoBlank);
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX(window_width * 0.28f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.75f);
|
||||||
|
// OK
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::ok[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = true;
|
||||||
|
JoinConnection(peer_reserved_ ? peer_reserved_ : peer_, remote_id_,
|
||||||
|
remote_password_.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
remote_password_ = "";
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) {
|
} else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) {
|
||||||
text = "No such transmissionId";
|
text = "No such transmissionId";
|
||||||
|
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
||||||
|
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||||
|
// Cancel
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
connect_button_pressed_ = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto window_width = ImGui::GetWindowSize().x;
|
auto window_width = ImGui::GetWindowSize().x;
|
||||||
auto window_height = ImGui::GetWindowSize().y;
|
auto window_height = ImGui::GetWindowSize().y;
|
||||||
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
|
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
|
||||||
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
|
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
|
||||||
ImGui::SetCursorPosY(window_height * 0.3f);
|
ImGui::SetCursorPosY(window_height * 0.2f);
|
||||||
ImGui::Text("%s", text.c_str());
|
ImGui::Text("%s", text.c_str());
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
|
|
||||||
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
// Cancel
|
|
||||||
if (ImGui::Button(
|
|
||||||
localization::cancel[localization_language_index_].c_str())) {
|
|
||||||
connect_button_pressed_ = false;
|
|
||||||
}
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
ImGui::PopStyleColor();
|
// ImGui::PopStyleColor();
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_CN 100
|
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_CN 100
|
||||||
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_EN 147
|
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_EN 147
|
||||||
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_CN 151
|
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_CN 151
|
||||||
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_EN 201
|
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_EN 198
|
||||||
#define SETTINGS_SELECT_WINDOW_WIDTH 73
|
#define SETTINGS_SELECT_WINDOW_WIDTH 73
|
||||||
#define SETTINGS_OK_BUTTON_PADDING_CN 55
|
#define SETTINGS_OK_BUTTON_PADDING_CN 55
|
||||||
#define SETTINGS_OK_BUTTON_PADDING_EN 78
|
#define SETTINGS_OK_BUTTON_PADDING_EN 78
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <random>
|
||||||
|
|
||||||
#include "IconsFontAwesome6.h"
|
#include "IconsFontAwesome6.h"
|
||||||
#include "layout_style.h"
|
#include "layout_style.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
@@ -107,14 +109,32 @@ int Render::LocalWindow() {
|
|||||||
ImGui::Text("%s",
|
ImGui::Text("%s",
|
||||||
localization::password[localization_language_index_].c_str());
|
localization::password[localization_language_index_].c_str());
|
||||||
|
|
||||||
strncpy(input_password_tmp_, input_password_, sizeof(input_password_));
|
|
||||||
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH);
|
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH);
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
if (!password_inited_) {
|
||||||
|
char a[] = {
|
||||||
|
"1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"};
|
||||||
|
std::mt19937 generator(
|
||||||
|
std::chrono::system_clock::now().time_since_epoch().count());
|
||||||
|
std::uniform_int_distribution<int> distribution(0, strlen(a) - 1);
|
||||||
|
|
||||||
|
random_password_.clear();
|
||||||
|
for (int i = 0, len = strlen(a); i < 6; i++) {
|
||||||
|
random_password_ += a[distribution(generator)];
|
||||||
|
}
|
||||||
|
password_inited_ = true;
|
||||||
|
if (random_password_ != password_saved_) {
|
||||||
|
password_saved_ = random_password_;
|
||||||
|
SaveSettingsIntoCacheFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::InputTextWithHint(
|
ImGui::InputTextWithHint(
|
||||||
"##server_pwd",
|
"##server_pwd",
|
||||||
localization::max_password_len[localization_language_index_].c_str(),
|
localization::max_password_len[localization_language_index_].c_str(),
|
||||||
input_password_, IM_ARRAYSIZE(input_password_),
|
(char *)random_password_.c_str(), random_password_.length() + 1,
|
||||||
show_password_ ? ImGuiInputTextFlags_CharsNoBlank
|
show_password_ ? ImGuiInputTextFlags_CharsNoBlank
|
||||||
: ImGuiInputTextFlags_CharsNoBlank |
|
: ImGuiInputTextFlags_CharsNoBlank |
|
||||||
ImGuiInputTextFlags_Password);
|
ImGuiInputTextFlags_Password);
|
||||||
@@ -135,25 +155,22 @@ int Render::LocalWindow() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
||||||
if (!regenerate_password_) {
|
|
||||||
if (ImGui::Button(ICON_FA_ARROWS_ROTATE, ImVec2(35, 38))) {
|
if (ImGui::Button(
|
||||||
|
regenerate_password_ ? ICON_FA_SPINNER : ICON_FA_ARROWS_ROTATE,
|
||||||
|
ImVec2(35, 38))) {
|
||||||
regenerate_password_ = true;
|
regenerate_password_ = true;
|
||||||
|
password_inited_ = false;
|
||||||
|
regenerate_password_start_time_ = ImGui::GetTime();
|
||||||
|
LeaveConnection(peer_);
|
||||||
|
is_create_connection_ = false;
|
||||||
}
|
}
|
||||||
} else {
|
if (ImGui::GetTime() - regenerate_password_start_time_ > 0.3f) {
|
||||||
regenerate_password_frame_count_++;
|
|
||||||
if (ImGui::Button(ICON_FA_SPINNER, ImVec2(35, 38))) {
|
|
||||||
}
|
|
||||||
if (regenerate_password_frame_count_ == 15) {
|
|
||||||
regenerate_password_frame_count_ = 0;
|
|
||||||
regenerate_password_ = false;
|
regenerate_password_ = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
if (strcmp(input_password_tmp_, input_password_)) {
|
|
||||||
SaveSettingsIntoCacheFile();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ int Render::SaveSettingsIntoCacheFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fseek(cd_cache_file_, 0, SEEK_SET);
|
fseek(cd_cache_file_, 0, SEEK_SET);
|
||||||
strncpy(cd_cache_.password, input_password_, sizeof(input_password_));
|
strncpy(cd_cache_.password, password_saved_.c_str(),
|
||||||
|
password_saved_.length());
|
||||||
memcpy(&cd_cache_.language, &language_button_value_,
|
memcpy(&cd_cache_.language, &language_button_value_,
|
||||||
sizeof(language_button_value_));
|
sizeof(language_button_value_));
|
||||||
memcpy(&cd_cache_.video_quality, &video_quality_button_value_,
|
memcpy(&cd_cache_.video_quality, &video_quality_button_value_,
|
||||||
@@ -53,7 +54,7 @@ int Render::LoadSettingsIntoCacheFile() {
|
|||||||
fseek(cd_cache_file_, 0, SEEK_SET);
|
fseek(cd_cache_file_, 0, SEEK_SET);
|
||||||
fread(&cd_cache_, sizeof(cd_cache_), 1, cd_cache_file_);
|
fread(&cd_cache_, sizeof(cd_cache_), 1, cd_cache_file_);
|
||||||
fclose(cd_cache_file_);
|
fclose(cd_cache_file_);
|
||||||
strncpy(input_password_, cd_cache_.password, sizeof(cd_cache_.password));
|
password_saved_ = cd_cache_.password;
|
||||||
language_button_value_ = cd_cache_.language;
|
language_button_value_ = cd_cache_.language;
|
||||||
video_quality_button_value_ = cd_cache_.video_quality;
|
video_quality_button_value_ = cd_cache_.video_quality;
|
||||||
video_encode_format_button_value_ = cd_cache_.video_encode_format;
|
video_encode_format_button_value_ = cd_cache_.video_encode_format;
|
||||||
@@ -274,8 +275,8 @@ int Render::Run() {
|
|||||||
while (!exit_) {
|
while (!exit_) {
|
||||||
if (SignalStatus::SignalConnected == signal_status_ &&
|
if (SignalStatus::SignalConnected == signal_status_ &&
|
||||||
!is_create_connection_) {
|
!is_create_connection_) {
|
||||||
is_create_connection_ =
|
is_create_connection_ = CreateConnection(peer_, mac_addr_str_.c_str(),
|
||||||
CreateConnection(peer_, mac_addr_str_.c_str(), input_password_)
|
password_saved_.c_str())
|
||||||
? false
|
? false
|
||||||
: true;
|
: true;
|
||||||
LOG_INFO("Connected with signal server, create p2p connection");
|
LOG_INFO("Connected with signal server, create p2p connection");
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ class Render {
|
|||||||
std::string settings_button_label_ = "Setting";
|
std::string settings_button_label_ = "Setting";
|
||||||
char input_password_tmp_[7] = "";
|
char input_password_tmp_[7] = "";
|
||||||
char input_password_[7] = "";
|
char input_password_[7] = "";
|
||||||
|
std::string random_password_ = "";
|
||||||
|
std::string password_saved_ = "";
|
||||||
|
std::string remote_password_ = "";
|
||||||
std::string local_id_ = "";
|
std::string local_id_ = "";
|
||||||
char remote_id_[20] = "";
|
char remote_id_[20] = "";
|
||||||
char client_password_[20] = "";
|
char client_password_[20] = "";
|
||||||
@@ -163,11 +166,12 @@ class Render {
|
|||||||
bool control_mouse_ = false;
|
bool control_mouse_ = false;
|
||||||
bool local_id_copied_ = false;
|
bool local_id_copied_ = false;
|
||||||
bool show_password_ = true;
|
bool show_password_ = true;
|
||||||
|
bool password_inited_ = false;
|
||||||
bool regenerate_password_ = false;
|
bool regenerate_password_ = false;
|
||||||
bool streaming_ = false;
|
bool streaming_ = false;
|
||||||
|
|
||||||
double copy_start_time_ = 0;
|
double copy_start_time_ = 0;
|
||||||
int regenerate_password_frame_count_ = 0;
|
double regenerate_password_start_time_ = 0;
|
||||||
|
|
||||||
int fps_ = 0;
|
int fps_ = 0;
|
||||||
uint32_t start_time_;
|
uint32_t start_time_;
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
render->connection_established_ = false;
|
render->connection_established_ = false;
|
||||||
render->control_mouse_ = false;
|
render->control_mouse_ = false;
|
||||||
render->exit_video_window_ = false;
|
render->exit_video_window_ = false;
|
||||||
|
render->remote_password_.clear();
|
||||||
if (render->dst_buffer_) {
|
if (render->dst_buffer_) {
|
||||||
memset(render->dst_buffer_, 0, 1280 * 720 * 3);
|
memset(render->dst_buffer_, 0, 1280 * 720 * 3);
|
||||||
SDL_UpdateTexture(render->stream_texture_, NULL, render->dst_buffer_,
|
SDL_UpdateTexture(render->stream_texture_, NULL, render->dst_buffer_,
|
||||||
|
|||||||
Reference in New Issue
Block a user