mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] allow user to set customized password
This commit is contained in:
@@ -51,8 +51,10 @@ static std::vector<std::string> enable_turn = {u8"启用中继服务:",
|
|||||||
static std::vector<std::string> ok = {u8"确认", "OK"};
|
static std::vector<std::string> ok = {u8"确认", "OK"};
|
||||||
static std::vector<std::string> cancel = {u8"取消", "Cancel"};
|
static std::vector<std::string> cancel = {u8"取消", "Cancel"};
|
||||||
|
|
||||||
static std::vector<std::string> input_password = {u8"请输入密码",
|
static std::vector<std::string> new_password = {u8"请输入新密码:",
|
||||||
"Please input password"};
|
"Please input new password:"};
|
||||||
|
static std::vector<std::string> input_password = {u8"请输入密码:",
|
||||||
|
"Please input password:"};
|
||||||
static std::vector<std::string> validate_password = {u8"验证密码中...",
|
static std::vector<std::string> validate_password = {u8"验证密码中...",
|
||||||
"Validate password ..."};
|
"Validate password ..."};
|
||||||
static std::vector<std::string> reinput_password = {
|
static std::vector<std::string> reinput_password = {
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ int Render::ConnectionStatusWindow() {
|
|||||||
ImGui::SetKeyboardFocusHere();
|
ImGui::SetKeyboardFocusHere();
|
||||||
focus_on_input_widget_ = false;
|
focus_on_input_widget_ = false;
|
||||||
}
|
}
|
||||||
bool enter_pressed =
|
bool enter_pressed = ImGui::InputText(
|
||||||
ImGui::InputText("##password", (char *)remote_password_.c_str(), 7,
|
"##password", remote_password_, IM_ARRAYSIZE(remote_password_),
|
||||||
ImGuiInputTextFlags_CharsNoBlank |
|
ImGuiInputTextFlags_CharsNoBlank |
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ int Render::ConnectionStatusWindow() {
|
|||||||
|
|
||||||
if (ImGui::Button(
|
if (ImGui::Button(
|
||||||
localization::cancel[localization_language_index_].c_str())) {
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
remote_password_ = "";
|
memset(remote_password_, 0, sizeof(remote_password_));
|
||||||
show_connection_status_window_ = false;
|
show_connection_status_window_ = false;
|
||||||
focus_on_input_widget_ = true;
|
focus_on_input_widget_ = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,17 +48,16 @@ int Render::LocalWindow() {
|
|||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||||
|
|
||||||
std::string client_id_display = "";
|
char client_id_display[12] = "";
|
||||||
for (int i = 0; i < sizeof(client_id_); i++) {
|
for (int i = 0, j = 0; i < sizeof(client_id_) + 2; i++, j++) {
|
||||||
client_id_display += client_id_[i];
|
client_id_display[j] = client_id_[i];
|
||||||
if (i == 2 || i == 5) {
|
if (i == 2 || i == 5) {
|
||||||
client_id_display += " ";
|
client_id_display[++j] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::InputText(
|
ImGui::InputText(
|
||||||
"##local_id", (char *)client_id_display.c_str(),
|
"##local_id", client_id_display, IM_ARRAYSIZE(client_id_display),
|
||||||
sizeof(client_id_display),
|
|
||||||
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
|
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
@@ -142,8 +141,9 @@ int Render::LocalWindow() {
|
|||||||
random_password_ += a[distribution(generator)];
|
random_password_ += a[distribution(generator)];
|
||||||
}
|
}
|
||||||
password_inited_ = true;
|
password_inited_ = true;
|
||||||
if (random_password_ != password_saved_) {
|
if (0 != strcmp(random_password_.c_str(), password_saved_)) {
|
||||||
password_saved_ = random_password_;
|
strncpy(password_saved_, random_password_.c_str(),
|
||||||
|
sizeof(password_saved_));
|
||||||
LOG_INFO("Generate new password and save into cache file");
|
LOG_INFO("Generate new password and save into cache file");
|
||||||
SaveSettingsIntoCacheFile();
|
SaveSettingsIntoCacheFile();
|
||||||
}
|
}
|
||||||
@@ -154,10 +154,12 @@ int Render::LocalWindow() {
|
|||||||
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(),
|
||||||
(char *)password_saved_.c_str(), password_saved_.length() + 1,
|
password_saved_, IM_ARRAYSIZE(password_saved_),
|
||||||
show_password_ ? ImGuiInputTextFlags_CharsNoBlank
|
show_password_
|
||||||
|
? ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_ReadOnly
|
||||||
: ImGuiInputTextFlags_CharsNoBlank |
|
: ImGuiInputTextFlags_CharsNoBlank |
|
||||||
ImGuiInputTextFlags_Password);
|
ImGuiInputTextFlags_Password |
|
||||||
|
ImGuiInputTextFlags_ReadOnly);
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -166,20 +168,27 @@ int Render::LocalWindow() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
if (ImGui::Button(show_password_ ? ICON_FA_EYE : ICON_FA_EYE_SLASH,
|
auto l_x = ImGui::GetCursorScreenPos().x;
|
||||||
ImVec2(35, 38))) {
|
auto l_y = ImGui::GetCursorScreenPos().y;
|
||||||
|
if (ImGui::Button(ICON_FA_EYE, ImVec2(22, 38))) {
|
||||||
show_password_ = !show_password_;
|
show_password_ = !show_password_;
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor(3);
|
|
||||||
|
if (!show_password_) {
|
||||||
|
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||||
|
draw_list->AddLine(ImVec2(l_x + 3.0f, l_y + 12.5f),
|
||||||
|
ImVec2(l_x + 20.3f, l_y + 26.5f),
|
||||||
|
IM_COL32(239, 240, 242, 255), 2.0f);
|
||||||
|
draw_list->AddLine(ImVec2(l_x + 3.0f, l_y + 11.0f),
|
||||||
|
ImVec2(l_x + 20.3f, l_y + 25.0f),
|
||||||
|
IM_COL32(0, 0, 0, 255), 1.5f);
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
|
||||||
|
|
||||||
if (ImGui::Button(
|
if (ImGui::Button(
|
||||||
regenerate_password_ ? ICON_FA_SPINNER : ICON_FA_ARROWS_ROTATE,
|
regenerate_password_ ? ICON_FA_SPINNER : ICON_FA_ARROWS_ROTATE,
|
||||||
ImVec2(35, 38))) {
|
ImVec2(22, 38))) {
|
||||||
regenerate_password_ = true;
|
regenerate_password_ = true;
|
||||||
password_inited_ = false;
|
password_inited_ = false;
|
||||||
regenerate_password_start_time_ = ImGui::GetTime();
|
regenerate_password_start_time_ = ImGui::GetTime();
|
||||||
@@ -190,11 +199,104 @@ int Render::LocalWindow() {
|
|||||||
regenerate_password_ = false;
|
regenerate_password_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button(ICON_FA_PEN, ImVec2(22, 38))) {
|
||||||
|
show_reset_password_window_ = true;
|
||||||
|
}
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
if (show_reset_password_window_) {
|
||||||
|
const ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||||
|
|
||||||
|
ImGui::SetNextWindowPos(
|
||||||
|
ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
|
||||||
|
connection_status_window_width_) /
|
||||||
|
2,
|
||||||
|
(viewport->WorkSize.y - viewport->WorkPos.y -
|
||||||
|
connection_status_window_height_) /
|
||||||
|
2));
|
||||||
|
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(connection_status_window_width_,
|
||||||
|
connection_status_window_height_));
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
||||||
|
|
||||||
|
ImGui::Begin("ResetPasswordWindow", nullptr,
|
||||||
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||||
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
|
||||||
|
ImGuiWindowFlags_NoSavedSettings);
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
|
auto window_width = ImGui::GetWindowSize().x;
|
||||||
|
auto window_height = ImGui::GetWindowSize().y;
|
||||||
|
std::string text =
|
||||||
|
localization::new_password[localization_language_index_];
|
||||||
|
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
ImGui::SetCursorPosX((window_width - text_width / 2) * 0.5f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.2f);
|
||||||
|
ImGui::Text("%s", text.c_str());
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX((window_width - IPUT_WINDOW_WIDTH / 2) * 0.5f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.4f);
|
||||||
|
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2);
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||||
|
|
||||||
|
if (focus_on_input_widget_) {
|
||||||
|
ImGui::SetKeyboardFocusHere();
|
||||||
|
focus_on_input_widget_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enter_pressed = ImGui::InputText(
|
||||||
|
"##new_password", new_password_, IM_ARRAYSIZE(new_password_),
|
||||||
|
ImGuiInputTextFlags_CharsNoBlank |
|
||||||
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
|
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX(window_width * 0.315f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.75f);
|
||||||
|
|
||||||
|
// OK
|
||||||
|
if (enter_pressed ||
|
||||||
|
ImGui::Button(
|
||||||
|
localization::ok[localization_language_index_].c_str())) {
|
||||||
|
show_reset_password_window_ = false;
|
||||||
|
LOG_INFO("Generate new password and save into cache file");
|
||||||
|
strncpy(password_saved_, new_password_, sizeof(password_saved_));
|
||||||
|
memset(new_password_, 0, sizeof(new_password_));
|
||||||
|
SaveSettingsIntoCacheFile();
|
||||||
|
LeaveConnection(peer_, client_id_);
|
||||||
|
is_create_connection_ = false;
|
||||||
|
focus_on_input_widget_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button(
|
||||||
|
localization::cancel[localization_language_index_].c_str())) {
|
||||||
|
show_reset_password_window_ = false;
|
||||||
|
focus_on_input_widget_ = true;
|
||||||
|
memset(new_password_, 0, sizeof(new_password_));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ int Render::RemoteWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_,
|
ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_,
|
||||||
remote_id_.c_str(), remote_password_.c_str());
|
remote_id_.c_str(), remote_password_);
|
||||||
if (0 == ret) {
|
if (0 == ret) {
|
||||||
is_client_mode_ = true;
|
is_client_mode_ = true;
|
||||||
rejoin_ = false;
|
rejoin_ = false;
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ int Render::SaveSettingsIntoCacheFile() {
|
|||||||
memset(&cd_cache_.client_id, 0, sizeof(cd_cache_.client_id));
|
memset(&cd_cache_.client_id, 0, sizeof(cd_cache_.client_id));
|
||||||
strncpy(cd_cache_.client_id, client_id_, sizeof(client_id_));
|
strncpy(cd_cache_.client_id, client_id_, sizeof(client_id_));
|
||||||
memset(&cd_cache_.password, 0, sizeof(cd_cache_.password));
|
memset(&cd_cache_.password, 0, sizeof(cd_cache_.password));
|
||||||
strncpy(cd_cache_.password, password_saved_.c_str(),
|
strncpy(cd_cache_.password, password_saved_, sizeof(password_saved_));
|
||||||
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_,
|
||||||
@@ -107,7 +106,7 @@ int Render::LoadSettingsFromCacheFile() {
|
|||||||
cd_cache_file_ = fopen("cache.cd", "r+");
|
cd_cache_file_ = fopen("cache.cd", "r+");
|
||||||
if (!cd_cache_file_) {
|
if (!cd_cache_file_) {
|
||||||
LOG_INFO("Init cache file by using default settings");
|
LOG_INFO("Init cache file by using default settings");
|
||||||
password_saved_ = "";
|
memset(password_saved_, 0, sizeof(password_saved_));
|
||||||
language_button_value_ = 0;
|
language_button_value_ = 0;
|
||||||
video_quality_button_value_ = 0;
|
video_quality_button_value_ = 0;
|
||||||
video_encode_format_button_value_ = 1;
|
video_encode_format_button_value_ = 1;
|
||||||
@@ -129,8 +128,8 @@ int Render::LoadSettingsFromCacheFile() {
|
|||||||
|
|
||||||
memset(&client_id_, 0, sizeof(client_id_));
|
memset(&client_id_, 0, sizeof(client_id_));
|
||||||
strncpy(client_id_, cd_cache_.client_id, sizeof(client_id_));
|
strncpy(client_id_, cd_cache_.client_id, sizeof(client_id_));
|
||||||
password_saved_ = cd_cache_.password;
|
strncpy(password_saved_, cd_cache_.password, sizeof(password_saved_));
|
||||||
if (!password_saved_.empty() && 6 == password_saved_.length()) {
|
if (0 != strcmp(password_saved_, "") && 7 == sizeof(password_saved_)) {
|
||||||
password_inited_ = true;
|
password_inited_ = true;
|
||||||
}
|
}
|
||||||
language_button_value_ = cd_cache_.language;
|
language_button_value_ = cd_cache_.language;
|
||||||
@@ -442,8 +441,7 @@ int Render::Run() {
|
|||||||
"Failed" != connection_status_str_) {
|
"Failed" != connection_status_str_) {
|
||||||
LOG_INFO("Connected with signal server, create p2p connection");
|
LOG_INFO("Connected with signal server, create p2p connection");
|
||||||
is_create_connection_ =
|
is_create_connection_ =
|
||||||
CreateConnection(peer_, client_id_, password_saved_.c_str()) ? false
|
CreateConnection(peer_, client_id_, password_saved_) ? false : true;
|
||||||
: true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inited_ ||
|
if (!inited_ ||
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ class Render {
|
|||||||
char input_password_tmp_[7] = "";
|
char input_password_tmp_[7] = "";
|
||||||
char input_password_[7] = "";
|
char input_password_[7] = "";
|
||||||
std::string random_password_ = "";
|
std::string random_password_ = "";
|
||||||
std::string remote_password_ = "";
|
char remote_password_[7] = "";
|
||||||
|
char new_password_[7] = "";
|
||||||
char remote_id_display_[12] = "";
|
char remote_id_display_[12] = "";
|
||||||
std::string remote_id_ = "";
|
std::string remote_id_ = "";
|
||||||
char client_password_[20] = "";
|
char client_password_[20] = "";
|
||||||
@@ -202,6 +203,7 @@ class Render {
|
|||||||
bool regenerate_password_ = false;
|
bool regenerate_password_ = false;
|
||||||
bool show_about_window_ = false;
|
bool show_about_window_ = false;
|
||||||
bool show_connection_status_window_ = false;
|
bool show_connection_status_window_ = false;
|
||||||
|
bool show_reset_password_window_ = false;
|
||||||
bool focus_on_input_widget_ = true;
|
bool focus_on_input_widget_ = true;
|
||||||
bool window_maximized_ = false;
|
bool window_maximized_ = false;
|
||||||
bool streaming_ = false;
|
bool streaming_ = false;
|
||||||
@@ -253,7 +255,7 @@ class Render {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
char client_id_[10] = "";
|
char client_id_[10] = "";
|
||||||
std::string password_saved_ = "";
|
char password_saved_[7] = "";
|
||||||
int language_button_value_ = 0;
|
int language_button_value_ = 0;
|
||||||
int video_quality_button_value_ = 0;
|
int video_quality_button_value_ = 0;
|
||||||
int video_encode_format_button_value_ = 0;
|
int video_encode_format_button_value_ = 0;
|
||||||
|
|||||||
@@ -183,15 +183,15 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
render->show_connection_status_window_ = true;
|
render->show_connection_status_window_ = true;
|
||||||
if (ConnectionStatus::Connecting == status) {
|
if (ConnectionStatus::Connecting == status) {
|
||||||
render->connection_status_str_ = "Connecting";
|
render->connection_status_str_ = "Connecting";
|
||||||
|
} else if (ConnectionStatus::Gathering == status) {
|
||||||
|
render->connection_status_str_ = "Gathering";
|
||||||
} else if (ConnectionStatus::Connected == status) {
|
} else if (ConnectionStatus::Connected == status) {
|
||||||
render->connection_status_str_ = "Connected";
|
render->connection_status_str_ = "Connected";
|
||||||
render->connection_established_ = true;
|
render->connection_established_ = true;
|
||||||
|
|
||||||
if (render->peer_reserved_ || !render->is_client_mode_) {
|
if (render->peer_reserved_ || !render->is_client_mode_) {
|
||||||
render->start_screen_capture_ = true;
|
render->start_screen_capture_ = true;
|
||||||
render->start_mouse_control_ = true;
|
render->start_mouse_control_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (ConnectionStatus::Disconnected == status) {
|
} else if (ConnectionStatus::Disconnected == status) {
|
||||||
render->connection_status_str_ = "Disconnected";
|
render->connection_status_str_ = "Disconnected";
|
||||||
render->password_validating_time_ = 0;
|
render->password_validating_time_ = 0;
|
||||||
@@ -212,7 +212,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
}
|
}
|
||||||
render->exit_video_window_ = false;
|
render->exit_video_window_ = false;
|
||||||
if (!render->rejoin_) {
|
if (!render->rejoin_) {
|
||||||
render->remote_password_.clear();
|
memset(render->remote_password_, 0, sizeof(render->remote_password_));
|
||||||
}
|
}
|
||||||
if (render->dst_buffer_) {
|
if (render->dst_buffer_) {
|
||||||
memset(render->dst_buffer_, 0, 1280 * 720 * 3);
|
memset(render->dst_buffer_, 0, 1280 * 720 * 3);
|
||||||
|
|||||||
2
thirdparty/projectx
vendored
2
thirdparty/projectx
vendored
Submodule thirdparty/projectx updated: fd392922d7...d78dc4585f
Reference in New Issue
Block a user