Merge pull request #4557 from 21pages/wakelock2

keep server device awake if have connection
This commit is contained in:
RustDesk 2023-06-05 23:27:55 +08:00 committed by GitHub
commit 12fc280ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 344 additions and 11 deletions

275
Cargo.lock generated
View File

@ -188,6 +188,43 @@ version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "apple-bindgen"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38f109ee76f68b4767848cb5dc93bfcc7c425deca849c4c81fa11cdce525e3d2"
dependencies = [
"apple-sdk",
"bindgen 0.63.0",
"derive_more",
"regex",
"serde 1.0.163",
"thiserror",
"toml 0.6.0",
]
[[package]]
name = "apple-sdk"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a04f192a700686ee70008ff4e4eb76fe7d11814ab93b7ee9d48c36b9a9f0bd2a"
dependencies = [
"plist",
"serde 1.0.163",
"serde_json 1.0.96",
]
[[package]]
name = "apple-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b3a1c3342678cd72676d0c1644fde496c1f65ea41f51465f54a89cad3bdf34"
dependencies = [
"apple-bindgen",
"apple-sdk",
"objc",
]
[[package]]
name = "arboard"
version = "3.2.0"
@ -445,6 +482,28 @@ dependencies = [
"which",
]
[[package]]
name = "bindgen"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"proc-macro2 1.0.56",
"quote 1.0.27",
"regex",
"rustc-hash",
"shlex",
"syn 1.0.109",
"which",
]
[[package]]
name = "bindgen"
version = "0.64.0"
@ -1012,12 +1071,44 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "const_fn"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935"
[[package]]
name = "const_format"
version = "0.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c990efc7a285731f9a4378d81aff2f0e85a2c8781a05ef0f8baa8dac54d0ff48"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e026b6ce194a874cb9cf32cd5772d1ef9767cc8fcb5765948d74f37a9d8b2bf6"
dependencies = [
"proc-macro2 1.0.56",
"quote 1.0.27",
"unicode-xid 0.2.4",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "convert_case"
version = "0.5.0"
@ -1473,6 +1564,19 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case 0.4.0",
"proc-macro2 1.0.56",
"quote 1.0.27",
"rustc_version",
"syn 1.0.109",
]
[[package]]
name = "detect-desktop-environment"
version = "0.2.0"
@ -2015,7 +2119,7 @@ dependencies = [
"cbindgen",
"chrono",
"clap 4.2.7",
"convert_case",
"convert_case 0.5.0",
"delegate",
"enum-iterator",
"enum_dispatch",
@ -2378,6 +2482,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "git2"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "glib"
version = "0.10.3"
@ -3063,6 +3180,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "is_debug"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06d198e9919d9822d5f7083ba8530e04de87841eaf21ead9af8f2304efd57c89"
[[package]]
name = "itertools"
version = "0.9.0"
@ -3170,6 +3293,21 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "keepawake"
version = "0.4.2"
source = "git+https://github.com/segevfiner/keepawake-rs#ade0b2baa1440807c8089e9ed24e5d722468651e"
dependencies = [
"anyhow",
"apple-sys",
"cfg-if 1.0.0",
"core-foundation 0.9.3",
"shadow-rs",
"windows 0.48.0",
"winres",
"zbus",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@ -3248,6 +3386,18 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "libgit2-sys"
version = "0.14.2+1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.7.4"
@ -3362,6 +3512,18 @@ dependencies = [
"x11 2.21.0",
]
[[package]]
name = "libz-sys"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "line-wrap"
version = "0.1.1"
@ -3746,6 +3908,15 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "nom8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
dependencies = [
"memchr",
]
[[package]]
name = "ntapi"
version = "0.4.1"
@ -3877,6 +4048,15 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
@ -4341,7 +4521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
dependencies = [
"once_cell",
"toml_edit",
"toml_edit 0.19.8",
]
[[package]]
@ -4374,7 +4554,7 @@ version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid",
"unicode-xid 0.1.0",
]
[[package]]
@ -5003,6 +5183,7 @@ dependencies = [
"impersonate_system",
"include_dir",
"jni 0.21.1",
"keepawake",
"lazy_static",
"libloading 0.8.0",
"libpulse-binding",
@ -5381,6 +5562,19 @@ dependencies = [
"digest",
]
[[package]]
name = "shadow-rs"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427f07ab5f873000cf55324882e12a88c0a7ea7025df4fc1e7e35e688877a583"
dependencies = [
"const_format",
"git2",
"is_debug",
"time 0.3.21",
"tzdb",
]
[[package]]
name = "shared_memory"
version = "0.12.4"
@ -5587,7 +5781,7 @@ checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid",
"unicode-xid 0.1.0",
]
[[package]]
@ -5890,6 +6084,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc"
dependencies = [
"itoa 1.0.6",
"libc",
"num_threads",
"serde 1.0.163",
"time-core",
"time-macros",
@ -6009,6 +6205,18 @@ dependencies = [
"serde 1.0.163",
]
[[package]]
name = "toml"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb9d890e4dc9298b70f740f615f2e05b9db37dce531f6b24fb77ac993f9f217"
dependencies = [
"serde 1.0.163",
"serde_spanned",
"toml_datetime 0.5.1",
"toml_edit 0.18.1",
]
[[package]]
name = "toml"
version = "0.7.3"
@ -6017,8 +6225,17 @@ checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
dependencies = [
"serde 1.0.163",
"serde_spanned",
"toml_datetime",
"toml_edit",
"toml_datetime 0.6.1",
"toml_edit 0.19.8",
]
[[package]]
name = "toml_datetime"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
dependencies = [
"serde 1.0.163",
]
[[package]]
@ -6030,6 +6247,19 @@ dependencies = [
"serde 1.0.163",
]
[[package]]
name = "toml_edit"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b"
dependencies = [
"indexmap",
"nom8",
"serde 1.0.163",
"serde_spanned",
"toml_datetime 0.5.1",
]
[[package]]
name = "toml_edit"
version = "0.19.8"
@ -6039,7 +6269,7 @@ dependencies = [
"indexmap",
"serde 1.0.163",
"serde_spanned",
"toml_datetime",
"toml_datetime 0.6.1",
"winnow",
]
@ -6127,6 +6357,25 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "tz-rs"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4"
dependencies = [
"const_fn",
]
[[package]]
name = "tzdb"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec758958f2fb5069cd7fae385be95cc8eceb8cdfd270c7d14de6034f0108d99e"
dependencies = [
"iana-time-zone",
"tz-rs",
]
[[package]]
name = "uds_windows"
version = "1.0.2"
@ -6185,6 +6434,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "untrusted"
version = "0.7.1"
@ -6238,6 +6493,12 @@ dependencies = [
"getrandom",
]
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"

View File

@ -114,6 +114,7 @@ objc_id = "0.1"
tray-icon = { git = "https://github.com/rustdesk-org/tray-icon" }
tao = { git = "https://github.com/rustdesk-org/tao", branch = "muda" }
image = "0.24"
keepawake = { git = "https://github.com/segevfiner/keepawake-rs" }
[target.'cfg(target_os = "linux")'.dependencies]
psimple = { package = "libpulse-simple-binding", version = "2.27" }

View File

@ -776,9 +776,9 @@ pub fn resolutions(name: &str) -> Vec<Resolution> {
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
1920x1080 60.01*+ 60.01 59.97 59.96 59.93
1680x1050 59.95 59.88
1600x1024 60.17
1920x1080 60.01*+ 60.01 59.97 59.96 59.93
1680x1050 59.95 59.88
1600x1024 60.17
XWAYLAND0 connected primary 1920x984+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
Virtual1 connected primary 1920x984+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
@ -1060,3 +1060,18 @@ mod desktop {
}
}
}
pub struct WakeLock(Option<keepawake::AwakeHandle>);
impl WakeLock {
pub fn new(display: bool, idle: bool, sleep: bool) -> Self {
WakeLock(
keepawake::Builder::new()
.display(display)
.idle(idle)
.sleep(sleep)
.create()
.ok(),
)
}
}

View File

@ -701,3 +701,18 @@ pub fn elevate(args: Vec<&str>, prompt: &str) -> ResultType<bool> {
}
}
}
pub struct WakeLock(Option<keepawake::AwakeHandle>);
impl WakeLock {
pub fn new(display: bool, idle: bool, sleep: bool) -> Self {
WakeLock(
keepawake::Builder::new()
.display(display)
.idle(idle)
.sleep(sleep)
.create()
.ok(),
)
}
}

View File

@ -40,7 +40,9 @@ use winapi::{
winbase::*,
wingdi::*,
winnt::{
TokenElevation, HANDLE, PROCESS_QUERY_LIMITED_INFORMATION, TOKEN_ELEVATION, TOKEN_QUERY,
TokenElevation, ES_AWAYMODE_REQUIRED, ES_CONTINUOUS, ES_DISPLAY_REQUIRED,
ES_SYSTEM_REQUIRED, HANDLE, PROCESS_QUERY_LIMITED_INFORMATION, TOKEN_ELEVATION,
TOKEN_QUERY,
},
winreg::HKEY_CURRENT_USER,
winuser::*,
@ -2121,6 +2123,30 @@ pub fn is_process_consent_running() -> ResultType<bool> {
.output()?;
Ok(output.status.success() && !output.stdout.is_empty())
}
pub struct WakeLock;
// Failed to compile keepawake-rs on i686
impl WakeLock {
pub fn new(display: bool, idle: bool, sleep: bool) -> Self {
let mut flag = ES_CONTINUOUS;
if display {
flag |= ES_DISPLAY_REQUIRED;
}
if idle {
flag |= ES_SYSTEM_REQUIRED;
}
if sleep {
flag |= ES_AWAYMODE_REQUIRED;
}
unsafe { SetThreadExecutionState(flag) };
WakeLock {}
}
}
impl Drop for WakeLock {
fn drop(&mut self) {
unsafe { SetThreadExecutionState(ES_CONTINUOUS) };
}
}
pub fn uninstall_service(show_new_window: bool) -> ResultType<()> {
let filter = format!(" /FI \"PID ne {}\"", get_current_pid());

View File

@ -506,6 +506,8 @@ fn check_get_displays_changed_msg() -> Option<Message> {
}
fn run(sp: GenericService) -> ResultType<()> {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let _wake_lock = get_wake_lock();
#[cfg(all(windows, feature = "virtual_display_driver"))]
ensure_close_virtual_device()?;
@ -1060,3 +1062,16 @@ fn start_uac_elevation_check() {
}
});
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn get_wake_lock() -> crate::platform::WakeLock {
let (display, idle, sleep) = if cfg!(windows) {
(true, false, false)
} else if cfg!(linux) {
(false, false, true)
} else {
//macos
(true, false, false)
};
crate::platform::WakeLock::new(display, idle, sleep)
}