From 4d65d12add1ca744b9bcf817117544bd6d3ea664 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Fri, 9 Oct 2026 10:01:34 +0800 Subject: [PATCH] [fix] apply settings without reconnecting signaling --- .../config_center/signal_server_settings.h | 29 +++++++++++++++++ .../src/gui/application/gui_application.cpp | 31 ++++++++++++++++++- apps/desktop/src/gui/runtime/runtime_state.h | 2 +- .../linux/headless/headless_settings.cpp | 7 ++++- deps/submodules/minirtc | 2 +- 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 apps/desktop/src/config_center/signal_server_settings.h diff --git a/apps/desktop/src/config_center/signal_server_settings.h b/apps/desktop/src/config_center/signal_server_settings.h new file mode 100644 index 00000000..1134d9ef --- /dev/null +++ b/apps/desktop/src/config_center/signal_server_settings.h @@ -0,0 +1,29 @@ +/* + * @Author: DI JUNKUN + * @Date: 2026-10-09 + * Copyright (c) 2026 by DI JUNKUN, All Rights Reserved. + */ + +#ifndef _SIGNAL_SERVER_SETTINGS_H_ +#define _SIGNAL_SERVER_SETTINGS_H_ + +#include + +#include "config_center.h" + +namespace crossdesk { + +// Include the identity namespace as well as the effective endpoint. Editing +// an inactive self-hosted endpoint must not disconnect the public server. +inline auto GetSignalServerSettings(const ConfigCenter& config) { + const bool self_hosted = config.IsSelfHosted(); + return std::make_tuple( + self_hosted, + self_hosted ? config.GetSignalServerHost() : config.GetDefaultServerHost(), + self_hosted ? config.GetSignalServerPort() + : config.GetDefaultSignalServerPort()); +} + +} // namespace crossdesk + +#endif \ No newline at end of file diff --git a/apps/desktop/src/gui/application/gui_application.cpp b/apps/desktop/src/gui/application/gui_application.cpp index 80d8683d..89f424d2 100644 --- a/apps/desktop/src/gui/application/gui_application.cpp +++ b/apps/desktop/src/gui/application/gui_application.cpp @@ -62,6 +62,7 @@ #endif #include "rd_log.h" #include "server_window_state.h" +#include "signal_server_settings.h" #include "ui/announcement_text.h" #include "ui/ui_localization.h" #include "update_checker.h" @@ -3496,6 +3497,7 @@ void GuiApplication::SyncServerWindow() { } void GuiApplication::SaveSettingsFromUi() { + const auto previous_server = GetSignalServerSettings(*config_center_); auto& main = ui_->main; language_button_value_ = localization::detail::ClampLanguageIndex(main->get_language_index()); @@ -3530,10 +3532,18 @@ void GuiApplication::SaveSettingsFromUi() { reload_recent_connections_ = true; #ifdef _WIN32 if (!HasActiveSession()) { + const auto previous_capture_method = config_center_->GetScreenCaptureMethod(); const auto capture_method = static_cast( std::clamp(main->get_capture_method_index(), 0, 3)); if (config_center_->SetScreenCaptureMethod(capture_method) != 0) { LOG_ERROR("Failed to save screen capture method"); + } else if (capture_method != previous_capture_method) { + // Reconfigure only capture; its backend does not own signaling. + devices_.StopScreenCapturer(); + screen_capturer_is_started_ = false; + if (devices_.InitializeScreenCapturer() != 0) { + LOG_ERROR("Failed to apply screen capture method"); + } } } main->set_capture_method_index( @@ -3563,7 +3573,8 @@ void GuiApplication::SaveSettingsFromUi() { } config_center_->SetSelfHosted(enable_self_hosted_); - ApplySettingsFromConfig(!HasActiveSession()); + ApplySettingsFromConfig(previous_server != + GetSignalServerSettings(*config_center_)); } void GuiApplication::ApplySettingsFromConfig(bool reconnect) { @@ -3603,6 +3614,24 @@ void GuiApplication::ApplySettingsFromConfig(bool reconnect) { // Tick recreates the peer after asynchronous cleanup, using the committed // configuration. Keep the application and its console running throughout. CloseAllRemoteSessions(); + } else { + const bool hardware = config_center_->IsHardwareVideoCodec(); + const bool av1 = config_center_->GetVideoEncodeFormat() == + ConfigCenter::VIDEO_ENCODE_FORMAT::AV1; + const auto turn = static_cast(config_center_->GetTurnMode()); + if (hardware != params_.hardware_acceleration || av1 != params_.av1_encoding || + turn != params_.turn_mode) { + // Update the listening peer for incoming connections and the template + // copied by ConnectTo for outgoing connections. Existing sessions retain + // the codec/ICE snapshot with which they negotiated. + if (!peer_ || UpdateConnectionSettings(peer_, hardware, av1, turn) == 0) { + params_.hardware_acceleration = hardware; + params_.av1_encoding = av1; + params_.turn_mode = turn; + } else { + LOG_ERROR("Failed to apply connection settings without reconnecting"); + } + } } } diff --git a/apps/desktop/src/gui/runtime/runtime_state.h b/apps/desktop/src/gui/runtime/runtime_state.h index 4a7006fc..bdeccaba 100644 --- a/apps/desktop/src/gui/runtime/runtime_state.h +++ b/apps/desktop/src/gui/runtime/runtime_state.h @@ -80,7 +80,7 @@ struct PeerState { std::string file_label_ = kFileStream; std::string file_feedback_label_ = kFileFeedbackStream; std::string clipboard_label_ = kClipboardStream; - Params params_; + Params params_{}; }; // OS-specific service and permission state is kept separate from transport diff --git a/apps/desktop/src/platform/linux/headless/headless_settings.cpp b/apps/desktop/src/platform/linux/headless/headless_settings.cpp index 32f33581..6ba3761d 100644 --- a/apps/desktop/src/platform/linux/headless/headless_settings.cpp +++ b/apps/desktop/src/platform/linux/headless/headless_settings.cpp @@ -10,6 +10,7 @@ #include #include "config_center.h" +#include "signal_server_settings.h" namespace crossdesk { namespace { @@ -142,11 +143,15 @@ SettingResult ApplyConsoleSetting(ConfigCenter& config, const std::string& key, return {true, SettingEffect::none, "console_settings_unchanged"}; } } + const auto previous_server = GetSignalServerSettings(config); status = save(); if (status != 0) return {false, SettingEffect::none, "console_settings_save_failed"}; - if (network && ((key != "server_host" && key != "server_port") || config.IsSelfHosted())) { + if (previous_server != GetSignalServerSettings(config)) { effect = SettingEffect::reconnect; message = "console_settings_reconnect"; + } else if (key == "codec" || key == "hardware" || key == "turn") { + effect = SettingEffect::next_connection; + message = "console_settings_next_connection"; } return {true, effect, message}; } diff --git a/deps/submodules/minirtc b/deps/submodules/minirtc index d3bac046..ec6e20c2 160000 --- a/deps/submodules/minirtc +++ b/deps/submodules/minirtc @@ -1 +1 @@ -Subproject commit d3bac046d116166b51c72cdc586e10b0d0d80d0f +Subproject commit ec6e20c24290bd2088ea4b26c8ebca3788383b1c