privacy_mode: win10 magnifier

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-04-25 12:28:28 +08:00
parent 85cd066cd7
commit c269d1c831
37 changed files with 2163 additions and 119 deletions

View File

@@ -226,6 +226,7 @@ impl sciter::EventHandler for Handler {
fn save_custom_image_quality(i32, i32);
fn refresh_video();
fn get_toggle_option(String);
fn is_privacy_mode_supported();
fn toggle_option(String);
fn get_remember();
fn peer_platform();
@@ -496,7 +497,7 @@ impl Handler {
}
#[inline]
fn save_config(&self, config: PeerConfig) {
pub(super) fn save_config(&self, config: PeerConfig) {
self.lc.write().unwrap().save_config(config);
}
@@ -505,7 +506,7 @@ impl Handler {
}
#[inline]
fn load_config(&self) -> PeerConfig {
pub(super) fn load_config(&self) -> PeerConfig {
load_config(&self.id)
}
@@ -523,6 +524,10 @@ impl Handler {
self.lc.read().unwrap().get_toggle_option(&name)
}
fn is_privacy_mode_supported(&self) -> bool {
self.lc.read().unwrap().is_privacy_mode_supported()
}
fn refresh_video(&mut self) {
self.send(Data::Message(LoginConfigHandler::refresh()));
}
@@ -2217,9 +2222,10 @@ impl Remote {
self.handler.msgbox("error", "Connection Error", &c);
return false;
}
Some(misc::Union::option_response(resp)) => {
self.handler
.msgbox("custom-error", "Option Error", &resp.error);
Some(misc::Union::back_notification(notification)) => {
if !self.handle_back_notification(notification).await {
return false;
}
}
_ => {}
},
@@ -2245,6 +2251,123 @@ impl Remote {
true
}
async fn handle_back_notification(&mut self, notification: BackNotification) -> bool {
match notification.union {
Some(back_notification::Union::block_input_state(state)) => {
self.handle_back_msg_block_input(
state.enum_value_or(back_notification::BlockInputState::StateUnknown),
)
.await;
}
Some(back_notification::Union::privacy_mode_state(state)) => {
if !self
.handle_back_msg_privacy_mode(
state.enum_value_or(back_notification::PrivacyModeState::StateUnknown),
)
.await
{
return false;
}
}
_ => {}
}
true
}
#[inline(always)]
fn update_block_input_state(&mut self, on: bool) {
self.handler.call("updateBlockInputState", &make_args!(on));
}
async fn handle_back_msg_block_input(&mut self, state: back_notification::BlockInputState) {
match state {
back_notification::BlockInputState::OnSucceeded => {
self.update_block_input_state(true);
}
back_notification::BlockInputState::OnFailed => {
self.handler
.msgbox("custom-error", "Block user input", "Failed");
self.update_block_input_state(false);
}
back_notification::BlockInputState::OffSucceeded => {
self.update_block_input_state(false);
}
back_notification::BlockInputState::OffFailed => {
self.handler
.msgbox("custom-error", "Unblock user input", "Failed");
}
_ => {}
}
}
#[inline(always)]
fn update_privacy_mode(&mut self, on: bool) {
let mut config = self.handler.load_config();
config.privacy_mode = on;
self.handler.save_config(config);
self.handler.call("updatePrivacyMode", &[]);
}
async fn handle_back_msg_privacy_mode(
&mut self,
state: back_notification::PrivacyModeState,
) -> bool {
match state {
back_notification::PrivacyModeState::OnByOther => {
self.handler.msgbox(
"error",
"Connecting...",
"Someone turns on privacy mode, exit",
);
return false;
}
back_notification::PrivacyModeState::NotSupported => {
self.handler
.msgbox("custom-error", "Privacy mode", "Unsupported");
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OnSucceeded => {
self.update_privacy_mode(true);
}
back_notification::PrivacyModeState::OnFailedDenied => {
self.handler
.msgbox("custom-error", "Privacy mode", "Peer denied");
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OnFailedPlugin => {
self.handler
.msgbox("custom-error", "Privacy mode", "Please install plugins");
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OnFailed => {
self.handler
.msgbox("custom-error", "Privacy mode", "Failed");
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OffSucceeded => {
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OffByPeer => {
self.handler
.msgbox("custom-error", "Privacy mode", "Peer exit");
self.update_privacy_mode(false);
}
back_notification::PrivacyModeState::OffFailed => {
self.handler
.msgbox("custom-error", "Privacy mode", "Failed to turn off");
}
back_notification::PrivacyModeState::OffUnknown => {
self.handler
.msgbox("custom-error", "Privacy mode", "Turned off");
// log::error!("Privacy mode is turned off with unknown reason");
self.update_privacy_mode(false);
}
_ => {}
}
true
}
fn check_clipboard_file_context(&mut self) {
#[cfg(windows)]
{
@@ -2333,6 +2456,7 @@ impl Interface for Handler {
} else if !self.is_port_forward() {
if pi.displays.is_empty() {
self.lc.write().unwrap().handle_peer_info(username, pi);
self.call("updatePrivacyMode", &[]);
self.msgbox("error", "Remote Error", "No Display");
return;
}
@@ -2371,6 +2495,7 @@ impl Interface for Handler {
}
}
self.lc.write().unwrap().handle_peer_info(username, pi);
self.call("updatePrivacyMode", &[]);
self.call("updatePi", &make_args!(pi_sciter));
if self.is_file_transfer() {
self.call2("closeSuccess", &make_args!());