mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-24 13:41:02 +03:00
refact: terminal, win, run as admin (#12300)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -138,7 +138,7 @@ pub fn session_add_sync(
|
||||
is_shared_password: bool,
|
||||
conn_token: Option<String>,
|
||||
) -> SyncReturn<String> {
|
||||
if let Err(e) = session_add(
|
||||
let add_res = session_add(
|
||||
&session_id,
|
||||
&id,
|
||||
is_file_transfer,
|
||||
@@ -151,7 +151,14 @@ pub fn session_add_sync(
|
||||
password,
|
||||
is_shared_password,
|
||||
conn_token,
|
||||
) {
|
||||
);
|
||||
// We can't put the remove call together with `std::env::var("IS_TERMINAL_ADMIN")`.
|
||||
// Because there are some `bail!` in `session_add()`, we must make sure `IS_TERMINAL_ADMIN` is removed at last.
|
||||
if is_terminal {
|
||||
std::env::remove_var("IS_TERMINAL_ADMIN");
|
||||
}
|
||||
|
||||
if let Err(e) = add_res {
|
||||
SyncReturn(format!("Failed to add session with id {}, {}", &id, e))
|
||||
} else {
|
||||
SyncReturn("".to_owned())
|
||||
@@ -1067,6 +1074,35 @@ pub fn main_get_env(key: String) -> SyncReturn<String> {
|
||||
SyncReturn(std::env::var(key).unwrap_or_default())
|
||||
}
|
||||
|
||||
// Dart does not support changing environment variables.
|
||||
// `Platform.environment['MY_VAR'] = 'VAR';` will throw an error
|
||||
// `Unsupported operation: Cannot modify unmodifiable map`.
|
||||
//
|
||||
// And we need to share the environment variables between rust and dart isolates sometimes.
|
||||
pub fn main_set_env(key: String, value: Option<String>) -> SyncReturn<()> {
|
||||
let is_valid_key = !key.is_empty() && !key.contains('=') && !key.contains('\0');
|
||||
debug_assert!(is_valid_key, "Invalid environment variable key: {}", key);
|
||||
if !is_valid_key {
|
||||
log::error!("Invalid environment variable key: {}", key);
|
||||
return SyncReturn(());
|
||||
}
|
||||
|
||||
match value {
|
||||
Some(v) => {
|
||||
let is_valid_value = !v.contains('\0');
|
||||
debug_assert!(is_valid_value, "Invalid environment variable value: {}", v);
|
||||
if !is_valid_value {
|
||||
log::error!("Invalid environment variable value: {}", v);
|
||||
return SyncReturn(());
|
||||
}
|
||||
std::env::set_var(key, v);
|
||||
}
|
||||
None => std::env::remove_var(key),
|
||||
}
|
||||
|
||||
SyncReturn(())
|
||||
}
|
||||
|
||||
pub fn main_set_local_option(key: String, value: String) {
|
||||
let is_texture_render_key = key.eq(config::keys::OPTION_TEXTURE_RENDER);
|
||||
let is_d3d_render_key = key.eq(config::keys::OPTION_ALLOW_D3D_RENDER);
|
||||
|
||||
Reference in New Issue
Block a user