[feat] add privacy unlock controls and remote relocking

This commit is contained in:
dijunkun
2026-10-27 10:22:25 +08:00
parent d1e4a31efb
commit ea3a2e1faa
41 changed files with 470 additions and 72 deletions
@@ -162,6 +162,7 @@ class GuiRuntime : protected gui_detail::GuiState {
DisconnectLockPolicy disconnect_lock_;
std::mutex privacy_commands_mutex_;
std::deque<std::pair<std::string, PrivacyCommand>> privacy_commands_;
bool privacy_settings_changed_ = false;
uint32_t last_privacy_revision_ = 0;
uint64_t last_privacy_status_tick_ = 0;
ClipboardController clipboard_;
@@ -316,6 +316,12 @@ void PeerEventHandler::OnReceiveDataBuffer(
std::lock_guard lock(props->privacy_status_mutex_);
if (!props->privacy_status_received_ ||
static_cast<int32_t>(remote_action.ps.revision - props->privacy_status_.revision) >= 0) {
if (props->privacy_status_received_ &&
static_cast<int32_t>(remote_action.ps.local_unlock_revision -
props->privacy_status_.local_unlock_revision) > 0)
props->privacy_unlock_notice_ = true;
if (remote_action.ps.state == PrivacyState::on)
props->privacy_unlock_notice_ = false;
props->privacy_status_ = remote_action.ps;
props->privacy_status_received_ = true;
props->privacy_status_tick_ = SDL_GetTicks();
@@ -10,6 +10,7 @@
#include <shared_mutex>
#include "rd_log.h"
#include "localization.h"
#include "runtime/gui_runtime.h"
namespace crossdesk {
@@ -71,6 +72,14 @@ void GuiRuntime::QueuePrivacyCommand(const std::string& remote_id,
}
void GuiRuntime::HandlePrivacy() {
const auto sync_text = [this] {
const int language = localization::detail::ClampLanguageIndex(
static_cast<int>(config_center_->GetLanguage()));
privacy_.SetText({localization::privacy_screen_unlock_hint[language],
localization::privacy_screen_locked_hint[language],
config_center_->IsPrivacyLocalUnlockAllowed()});
};
sync_text();
std::deque<std::pair<std::string, PrivacyCommand>> commands;
{
std::lock_guard lock(privacy_commands_mutex_);
@@ -87,6 +96,16 @@ void GuiRuntime::HandlePrivacy() {
if (command.flag == PrivacyCommandFlag::enable) {
if (privacy_sessions_.CanEnable())
privacy_.Enable(command.block_local_input);
} else if (command.flag == PrivacyCommandFlag::lock) {
if (privacy_sessions_.CanEnable()) {
if (config_center_->SetPrivacyLocalUnlock(false) == 0) {
privacy_settings_changed_ = true;
sync_text();
privacy_.Enable(true, true);
} else {
privacy_.RejectCommand("Could not save the local privacy unlock setting; try again");
}
}
} else if (command.flag == PrivacyCommandFlag::disable) {
privacy_.Disable();
}
@@ -193,6 +193,7 @@ struct RemoteSession {
std::mutex privacy_status_mutex_;
PrivacyStatus privacy_status_{};
bool privacy_status_received_ = false;
bool privacy_unlock_notice_ = false;
bool privacy_desktop_available_ = true;
bool privacy_command_pending_ = false;
uint64_t privacy_command_tick_ = 0;