tmp commit
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
2988744034
commit
35ec3ffef6
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -2776,6 +2776,7 @@ dependencies = [
|
|||||||
"confy",
|
"confy",
|
||||||
"directories-next",
|
"directories-next",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
|
"dlopen",
|
||||||
"env_logger 0.10.0",
|
"env_logger 0.10.0",
|
||||||
"filetime",
|
"filetime",
|
||||||
"flexi_logger",
|
"flexi_logger",
|
||||||
@ -5118,7 +5119,6 @@ dependencies = [
|
|||||||
"dbus-crossroads",
|
"dbus-crossroads",
|
||||||
"default-net",
|
"default-net",
|
||||||
"dispatch",
|
"dispatch",
|
||||||
"dlopen",
|
|
||||||
"enigo",
|
"enigo",
|
||||||
"errno",
|
"errno",
|
||||||
"evdev",
|
"evdev",
|
||||||
@ -6451,7 +6451,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"hbb_common",
|
"hbb_common",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libloading",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -65,7 +65,6 @@ flutter_rust_bridge = { version = "1.61.1", optional = true }
|
|||||||
errno = "0.3"
|
errno = "0.3"
|
||||||
rdev = { git = "https://github.com/fufesou/rdev" }
|
rdev = { git = "https://github.com/fufesou/rdev" }
|
||||||
url = { version = "2.1", features = ["serde"] }
|
url = { version = "2.1", features = ["serde"] }
|
||||||
dlopen = "0.1"
|
|
||||||
crossbeam-queue = "0.3"
|
crossbeam-queue = "0.3"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features=false }
|
reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features=false }
|
||||||
|
@ -34,6 +34,7 @@ tokio-socks = { git = "https://github.com/open-trade/tokio-socks" }
|
|||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
dlopen = "0.1"
|
||||||
|
|
||||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||||
mac_address = "1.1"
|
mac_address = "1.1"
|
||||||
|
@ -1141,6 +1141,8 @@ pub struct LocalConfig {
|
|||||||
// Various data for flutter ui
|
// Various data for flutter ui
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
ui_flutter: HashMap<String, String>,
|
ui_flutter: HashMap<String, String>,
|
||||||
|
#[serde(default)]
|
||||||
|
virtual_display_num: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalConfig {
|
impl LocalConfig {
|
||||||
@ -1243,6 +1245,19 @@ impl LocalConfig {
|
|||||||
config.store();
|
config.store();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_virtual_display_num() -> usize {
|
||||||
|
LOCAL_CONFIG.read().unwrap().virtual_display_num
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_virtual_display_num(virtual_display_num: usize) {
|
||||||
|
let mut lock = LOCAL_CONFIG.write().unwrap();
|
||||||
|
if lock.virtual_display_num == virtual_display_num {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lock.virtual_display_num = virtual_display_num;
|
||||||
|
lock.store();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
|
@ -44,6 +44,8 @@ pub use libc;
|
|||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub use sysinfo;
|
pub use sysinfo;
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub use dlopen;
|
||||||
|
|
||||||
#[cfg(feature = "quic")]
|
#[cfg(feature = "quic")]
|
||||||
pub type Stream = quic::Connection;
|
pub type Stream = quic::Connection;
|
||||||
|
@ -7,5 +7,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
libloading = "0.7"
|
|
||||||
hbb_common = { path = "../hbb_common" }
|
hbb_common = { path = "../hbb_common" }
|
||||||
|
@ -2,18 +2,21 @@
|
|||||||
pub mod win10;
|
pub mod win10;
|
||||||
|
|
||||||
use hbb_common::{bail, lazy_static, ResultType};
|
use hbb_common::{bail, lazy_static, ResultType};
|
||||||
use std::{path::Path, sync::Mutex};
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
// If device is uninstalled though "Device Manager" Window.
|
// If device is uninstalled though "Device Manager" Window.
|
||||||
// Rustdesk is unable to handle device any more...
|
// Rustdesk is unable to handle device any more...
|
||||||
static ref H_SW_DEVICE: Mutex<u64> = Mutex::new(0);
|
static ref H_SW_DEVICE: Mutex<u64> = Mutex::new(0);
|
||||||
static ref MONITOR_PLUGIN: Mutex<Vec<u32>> = Mutex::new(Vec::new());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn get_dirver_install_path() -> &'static str {
|
pub fn get_driver_install_path() -> &'static str {
|
||||||
win10::DRIVER_INSTALL_PATH
|
win10::DRIVER_INSTALL_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,68 +140,48 @@ pub fn close_device() {
|
|||||||
unsafe {
|
unsafe {
|
||||||
win10::idd::DeviceClose(*H_SW_DEVICE.lock().unwrap() as win10::idd::HSWDEVICE);
|
win10::idd::DeviceClose(*H_SW_DEVICE.lock().unwrap() as win10::idd::HSWDEVICE);
|
||||||
*H_SW_DEVICE.lock().unwrap() = 0;
|
*H_SW_DEVICE.lock().unwrap() = 0;
|
||||||
MONITOR_PLUGIN.lock().unwrap().clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn plug_in_monitor() -> ResultType<()> {
|
pub fn plug_in_monitor(_monitor_index: u32, _edid: u32, _retries: u32) -> ResultType<()> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let monitor_index = 0 as u32;
|
if win10::idd::MonitorPlugIn(_monitor_index as _, _edid as _, _retries as _)
|
||||||
let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap();
|
== win10::idd::FALSE
|
||||||
for i in 0..plug_in_monitors.len() {
|
{
|
||||||
if let Some(d) = plug_in_monitors.get(i) {
|
bail!("{}", win10::get_last_msg()?);
|
||||||
if *d == monitor_index {
|
}
|
||||||
return Ok(());
|
}
|
||||||
}
|
Ok(())
|
||||||
};
|
}
|
||||||
}
|
|
||||||
if win10::idd::MonitorPlugIn(monitor_index, 0, 30) == win10::idd::FALSE {
|
#[no_mangle]
|
||||||
bail!("{}", win10::get_last_msg()?);
|
pub fn plug_out_monitor(_monitor_index: u32) -> ResultType<()> {
|
||||||
}
|
#[cfg(windows)]
|
||||||
(*plug_in_monitors).push(monitor_index);
|
unsafe {
|
||||||
}
|
if win10::idd::MonitorPlugOut(_monitor_index) == win10::idd::FALSE {
|
||||||
Ok(())
|
bail!("{}", win10::get_last_msg()?);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#[no_mangle]
|
Ok(())
|
||||||
pub fn plug_out_monitor() -> ResultType<()> {
|
}
|
||||||
#[cfg(windows)]
|
|
||||||
unsafe {
|
#[cfg(windows)]
|
||||||
let monitor_index = 0 as u32;
|
type PMonitorMode = win10::idd::PMonitorMode;
|
||||||
if win10::idd::MonitorPlugOut(monitor_index) == win10::idd::FALSE {
|
#[cfg(not(windows))]
|
||||||
bail!("{}", win10::get_last_msg()?);
|
type PMonitorMode = *mut std::ffi::c_void;
|
||||||
}
|
|
||||||
let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap();
|
#[no_mangle]
|
||||||
for i in 0..plug_in_monitors.len() {
|
pub fn update_monitor_modes(
|
||||||
if let Some(d) = plug_in_monitors.get(i) {
|
_monitor_index: u32,
|
||||||
if *d == monitor_index {
|
_mode_count: u32,
|
||||||
plug_in_monitors.remove(i);
|
_modes: PMonitorMode,
|
||||||
break;
|
) -> ResultType<()> {
|
||||||
}
|
#[cfg(windows)]
|
||||||
};
|
unsafe {
|
||||||
}
|
if win10::idd::FALSE
|
||||||
}
|
== win10::idd::MonitorModesUpdate(_monitor_index as _, _mode_count as _, _modes)
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn update_monitor_modes() -> ResultType<()> {
|
|
||||||
#[cfg(windows)]
|
|
||||||
unsafe {
|
|
||||||
let monitor_index = 0 as u32;
|
|
||||||
let mut modes = vec![win10::idd::MonitorMode {
|
|
||||||
width: 1920,
|
|
||||||
height: 1080,
|
|
||||||
sync: 60,
|
|
||||||
}];
|
|
||||||
if win10::idd::FALSE
|
|
||||||
== win10::idd::MonitorModesUpdate(
|
|
||||||
monitor_index as win10::idd::UINT,
|
|
||||||
modes.len() as win10::idd::UINT,
|
|
||||||
modes.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
bail!("{}", win10::get_last_msg()?);
|
bail!("{}", win10::get_last_msg()?);
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,18 @@ fn prompt_input() -> u8 {
|
|||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn plug_in() {
|
fn plug_in(monitor_index: u32) {
|
||||||
println!("Plug in monitor begin");
|
println!("Plug in monitor begin");
|
||||||
if let Err(e) = virtual_display::plug_in_monitor() {
|
if let Err(e) = virtual_display::plug_in_monitor(monitor_index as _) {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
} else {
|
} else {
|
||||||
println!("Plug in monitor done");
|
println!("Plug in monitor done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn plug_out() {
|
fn plug_out(monitor_index: u32) {
|
||||||
println!("Plug out monitor begin");
|
println!("Plug out monitor begin");
|
||||||
if let Err(e) = virtual_display::plug_out_monitor() {
|
if let Err(e) = virtual_display::plug_out_monitor(monitor_index as _) {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
} else {
|
} else {
|
||||||
println!("Plug out monitor done");
|
println!("Plug out monitor done");
|
||||||
@ -38,7 +38,8 @@ fn plug_out() {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
loop {
|
loop {
|
||||||
match prompt_input() as char {
|
let chr = prompt_input();
|
||||||
|
match chr as char {
|
||||||
'x' => break,
|
'x' => break,
|
||||||
'i' => {
|
'i' => {
|
||||||
println!("Install or update driver begin");
|
println!("Install or update driver begin");
|
||||||
@ -81,8 +82,12 @@ fn main() {
|
|||||||
virtual_display::close_device();
|
virtual_display::close_device();
|
||||||
println!("Close device done");
|
println!("Close device done");
|
||||||
}
|
}
|
||||||
'1' => plug_in(),
|
'1' => plug_in(0),
|
||||||
'4' => plug_out(),
|
'2' => plug_in(1),
|
||||||
|
'3' => plug_in(2),
|
||||||
|
'4' => plug_out(0),
|
||||||
|
'5' => plug_out(1),
|
||||||
|
'6' => plug_out(2),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,93 @@
|
|||||||
use hbb_common::{bail, ResultType};
|
use hbb_common::{anyhow, dlopen::symbor::Library, log, ResultType};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
const LIB_NAME_VIRTUAL_DISPLAY: &str = "dylib_virtual_display";
|
const LIB_NAME_VIRTUAL_DISPLAY: &str = "dylib_virtual_display";
|
||||||
|
|
||||||
|
pub type DWORD = ::std::os::raw::c_ulong;
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct _MonitorMode {
|
||||||
|
pub width: DWORD,
|
||||||
|
pub height: DWORD,
|
||||||
|
pub sync: DWORD,
|
||||||
|
}
|
||||||
|
pub type MonitorMode = _MonitorMode;
|
||||||
|
pub type PMonitorMode = *mut MonitorMode;
|
||||||
|
|
||||||
|
pub type GetDriverInstallPath = fn() -> &'static str;
|
||||||
|
pub type IsDeviceCreated = fn() -> bool;
|
||||||
|
pub type CloseDevice = fn();
|
||||||
|
pub type DownLoadDriver = fn() -> ResultType<()>;
|
||||||
|
pub type CreateDevice = fn() -> ResultType<()>;
|
||||||
|
pub type InstallUpdateDriver = fn(&mut bool) -> ResultType<()>;
|
||||||
|
pub type UninstallDriver = fn(&mut bool) -> ResultType<()>;
|
||||||
|
pub type PlugInMonitor = fn(u32) -> ResultType<()>;
|
||||||
|
pub type PlugOutMonitor = fn(u32) -> ResultType<()>;
|
||||||
|
pub type UpdateMonitorModes = fn(u32, u32, PMonitorMode) -> ResultType<()>;
|
||||||
|
|
||||||
|
macro_rules! make_lib_wrapper {
|
||||||
|
($($field:ident : $tp:ty),+) => {
|
||||||
|
struct LibWrapper {
|
||||||
|
_lib: Option<Library>,
|
||||||
|
$($field: Option<$tp>),+
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LibWrapper {
|
||||||
|
fn new() -> Self {
|
||||||
|
let lib = match Library::open(get_lib_name()) {
|
||||||
|
Ok(lib) => Some(lib),
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$(let $field = if let Some(lib) = &lib {
|
||||||
|
match unsafe { lib.symbol::<$tp>(stringify!($field)) } {
|
||||||
|
Ok(m) => Some(*m),
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to load func {}, {}", stringify!($field), e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};)+
|
||||||
|
|
||||||
|
Self {
|
||||||
|
_lib: lib,
|
||||||
|
$( $field ),+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for LibWrapper {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
make_lib_wrapper!(
|
||||||
|
get_driver_install_path: GetDriverInstallPath,
|
||||||
|
is_device_created: IsDeviceCreated,
|
||||||
|
close_device: CloseDevice,
|
||||||
|
download_driver: DownLoadDriver,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
install_update_driver: InstallUpdateDriver,
|
||||||
|
uninstall_driver: UninstallDriver,
|
||||||
|
plug_in_monitor: PlugInMonitor,
|
||||||
|
plug_out_monitor: PlugOutMonitor,
|
||||||
|
update_monitor_modes: UpdateMonitorModes
|
||||||
|
);
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref LIB_VIRTUAL_DISPLAY: Arc<Mutex<Result<libloading::Library, libloading::Error>>> = {
|
static ref LIB_WRAPPER: Arc<Mutex<LibWrapper>> = Default::default();
|
||||||
Arc::new(Mutex::new(unsafe { libloading::Library::new(get_lib_name()) }))
|
static ref MONITOR_INDICES: Mutex<HashSet<u32>> = Mutex::new(HashSet::new());
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
@ -24,102 +105,90 @@ fn get_lib_name() -> String {
|
|||||||
format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY)
|
format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_reload_lib() {
|
|
||||||
let mut lock = LIB_VIRTUAL_DISPLAY.lock().unwrap();
|
|
||||||
if lock.is_err() {
|
|
||||||
*lock = unsafe { libloading::Library::new(get_lib_name()) };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn get_dirver_install_path() -> ResultType<&'static str> {
|
pub fn get_driver_install_path() -> Option<&'static str> {
|
||||||
try_reload_lib();
|
Some(LIB_WRAPPER.lock().unwrap().get_driver_install_path?())
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
|
||||||
Ok(lib) => unsafe {
|
|
||||||
match lib.get::<libloading::Symbol<fn() -> &'static str>>(b"get_dirver_install_path") {
|
|
||||||
Ok(func) => Ok(func()),
|
|
||||||
Err(e) => bail!("Failed to load func get_dirver_install_path, {}", e),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_device_created() -> bool {
|
pub fn is_device_created() -> bool {
|
||||||
try_reload_lib();
|
LIB_WRAPPER
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
.lock()
|
||||||
Ok(lib) => unsafe {
|
.unwrap()
|
||||||
match lib.get::<libloading::Symbol<fn() -> bool>>(b"is_device_created") {
|
.is_device_created
|
||||||
Ok(func) => func(),
|
.map(|f| f())
|
||||||
Err(..) => false,
|
.unwrap_or(false)
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(..) => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_device() {
|
pub fn close_device() {
|
||||||
try_reload_lib();
|
let _r = LIB_WRAPPER.lock().unwrap().close_device.map(|f| f());
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
|
||||||
Ok(lib) => unsafe {
|
|
||||||
match lib.get::<libloading::Symbol<fn()>>(b"close_device") {
|
|
||||||
Ok(func) => func(),
|
|
||||||
Err(..) => {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(..) => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! def_func_result {
|
pub fn download_driver() -> ResultType<()> {
|
||||||
($func:ident, $name: tt) => {
|
LIB_WRAPPER
|
||||||
pub fn $func() -> ResultType<()> {
|
.lock()
|
||||||
try_reload_lib();
|
.unwrap()
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
.download_driver
|
||||||
Ok(lib) => unsafe {
|
.ok_or(anyhow::Error::msg("download_driver method not found"))?()
|
||||||
match lib.get::<libloading::Symbol<fn() -> ResultType<()>>>($name.as_bytes()) {
|
}
|
||||||
Ok(func) => func(),
|
|
||||||
Err(e) => bail!("Failed to load func {}, {}", $name, e),
|
pub fn create_device() -> ResultType<()> {
|
||||||
}
|
LIB_WRAPPER
|
||||||
},
|
.lock()
|
||||||
Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e),
|
.unwrap()
|
||||||
}
|
.create_device
|
||||||
}
|
.ok_or(anyhow::Error::msg("create_device method not found"))?()
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_update_driver(reboot_required: &mut bool) -> ResultType<()> {
|
pub fn install_update_driver(reboot_required: &mut bool) -> ResultType<()> {
|
||||||
try_reload_lib();
|
LIB_WRAPPER
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
.lock()
|
||||||
Ok(lib) => unsafe {
|
.unwrap()
|
||||||
match lib.get::<libloading::Symbol<fn(&mut bool) -> ResultType<()>>>(
|
.install_update_driver
|
||||||
b"install_update_driver",
|
.ok_or(anyhow::Error::msg("install_update_driver method not found"))?(reboot_required)
|
||||||
) {
|
|
||||||
Ok(func) => func(reboot_required),
|
|
||||||
Err(e) => bail!("Failed to load func install_update_driver, {}", e),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uninstall_driver(reboot_required: &mut bool) -> ResultType<()> {
|
pub fn uninstall_driver(reboot_required: &mut bool) -> ResultType<()> {
|
||||||
try_reload_lib();
|
LIB_WRAPPER
|
||||||
match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() {
|
.lock()
|
||||||
Ok(lib) => unsafe {
|
.unwrap()
|
||||||
match lib
|
.uninstall_driver
|
||||||
.get::<libloading::Symbol<fn(&mut bool) -> ResultType<()>>>(b"uninstall_driver")
|
.ok_or(anyhow::Error::msg("uninstall_driver method not found"))?(reboot_required)
|
||||||
{
|
|
||||||
Ok(func) => func(reboot_required),
|
|
||||||
Err(e) => bail!("Failed to load func uninstall_driver, {}", e),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def_func_result!(download_driver, "download_driver");
|
#[cfg(windows)]
|
||||||
def_func_result!(create_device, "create_device");
|
pub fn plug_in_monitor(monitor_index: u32) -> ResultType<()> {
|
||||||
def_func_result!(plug_in_monitor, "plug_in_monitor");
|
let mut lock = MONITOR_INDICES.lock().unwrap();
|
||||||
def_func_result!(plug_out_monitor, "plug_out_monitor");
|
if lock.contains(&monitor_index) {
|
||||||
def_func_result!(update_monitor_modes, "update_monitor_modes");
|
return Ok(());
|
||||||
|
}
|
||||||
|
let f = LIB_WRAPPER
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.plug_in_monitor
|
||||||
|
.ok_or(anyhow::Error::msg("plug_in_monitor method not found"))?;
|
||||||
|
f(monitor_index)?;
|
||||||
|
lock.insert(monitor_index);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn plug_out_monitor(monitor_index: u32) -> ResultType<()> {
|
||||||
|
let f = LIB_WRAPPER
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.plug_out_monitor
|
||||||
|
.ok_or(anyhow::Error::msg("plug_out_monitor method not found"))?;
|
||||||
|
f(monitor_index)?;
|
||||||
|
MONITOR_INDICES.lock().unwrap().remove(&monitor_index);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn update_monitor_modes(monitor_index: u32, modes: &[MonitorMode]) -> ResultType<()> {
|
||||||
|
let f = LIB_WRAPPER
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.update_monitor_modes
|
||||||
|
.ok_or(anyhow::Error::msg("update_monitor_modes method not found"))?;
|
||||||
|
f(monitor_index, modes.len() as _, modes.as_ptr() as _)
|
||||||
|
}
|
||||||
|
@ -3,18 +3,19 @@ use crate::{
|
|||||||
flutter_ffi::EventToUI,
|
flutter_ffi::EventToUI,
|
||||||
ui_session_interface::{io_loop, InvokeUiSession, Session},
|
ui_session_interface::{io_loop, InvokeUiSession, Session},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "flutter_texture_render")]
|
|
||||||
use dlopen::{
|
|
||||||
symbor::{Library, Symbol},
|
|
||||||
Error as LibError,
|
|
||||||
};
|
|
||||||
use flutter_rust_bridge::StreamSink;
|
use flutter_rust_bridge::StreamSink;
|
||||||
#[cfg(feature = "flutter_texture_render")]
|
|
||||||
use hbb_common::libc::c_void;
|
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
bail, config::LocalConfig, get_version_number, log, message_proto::*,
|
bail, config::LocalConfig, get_version_number, log, message_proto::*,
|
||||||
rendezvous_proto::ConnType, ResultType,
|
rendezvous_proto::ConnType, ResultType,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "flutter_texture_render")]
|
||||||
|
use hbb_common::{
|
||||||
|
dlopen::{
|
||||||
|
symbor::{Library, Symbol},
|
||||||
|
Error as LibError,
|
||||||
|
},
|
||||||
|
libc::c_void,
|
||||||
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
#[cfg(not(feature = "flutter_texture_render"))]
|
#[cfg(not(feature = "flutter_texture_render"))]
|
||||||
|
@ -23,6 +23,8 @@ use super::{video_qos::VideoQoS, *};
|
|||||||
use crate::platform::windows::is_process_consent_running;
|
use crate::platform::windows::is_process_consent_running;
|
||||||
#[cfg(all(windows, feature = "privacy_win_mag"))]
|
#[cfg(all(windows, feature = "privacy_win_mag"))]
|
||||||
use crate::privacy_mode::privacy_win_mag;
|
use crate::privacy_mode::privacy_win_mag;
|
||||||
|
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||||
|
use hbb_common::config::LocalConfig;
|
||||||
#[cfg(all(windows, feature = "privacy_win_mag"))]
|
#[cfg(all(windows, feature = "privacy_win_mag"))]
|
||||||
use hbb_common::get_version_number;
|
use hbb_common::get_version_number;
|
||||||
use hbb_common::tokio::sync::{
|
use hbb_common::tokio::sync::{
|
||||||
@ -48,6 +50,9 @@ use std::{
|
|||||||
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||||
use virtual_display;
|
use virtual_display;
|
||||||
|
|
||||||
|
#[cfg(all(windows, feature = "virtual_display_driver"))]
|
||||||
|
const VIRTUAL_DISPLAY_INDEX_FOR_HEADLESS: u32 = 0;
|
||||||
|
|
||||||
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
|
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
|
||||||
pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str =
|
pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str =
|
||||||
"Wayland requires higher version of linux distro. Please try X11 desktop or change your OS.";
|
"Wayland requires higher version of linux distro. Please try X11 desktop or change your OS.";
|
||||||
@ -936,21 +941,20 @@ fn try_get_displays() -> ResultType<Vec<Display>> {
|
|||||||
if displays.len() == 0 {
|
if displays.len() == 0 {
|
||||||
log::debug!("no displays, create virtual display");
|
log::debug!("no displays, create virtual display");
|
||||||
// Try plugin monitor
|
// Try plugin monitor
|
||||||
if !virtual_display::is_device_created() {
|
if LocalConfig::get_virtual_display_num() > 0 {
|
||||||
if let Err(e) = virtual_display::create_device() {
|
if !virtual_display::is_device_created() {
|
||||||
log::debug!("Create device failed {}", e);
|
if let Err(e) = virtual_display::create_device() {
|
||||||
}
|
log::debug!("Create device failed {}", e);
|
||||||
}
|
|
||||||
if virtual_display::is_device_created() {
|
|
||||||
if let Err(e) = virtual_display::plug_in_monitor() {
|
|
||||||
log::debug!("Plug in monitor failed {}", e);
|
|
||||||
} else {
|
|
||||||
if let Err(e) = virtual_display::update_monitor_modes() {
|
|
||||||
log::debug!("Update monitor modes failed {}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if virtual_display::is_device_created() {
|
||||||
|
if let Err(e) = virtual_display::plug_in_monitor(VIRTUAL_DISPLAY_INDEX_FOR_HEADLESS)
|
||||||
|
{
|
||||||
|
log::debug!("Plug in monitor failed {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displays = Display::all()?;
|
||||||
}
|
}
|
||||||
displays = Display::all()?;
|
|
||||||
} else if displays.len() > 1 {
|
} else if displays.len() > 1 {
|
||||||
// to-do: do not close if in privacy mode.
|
// to-do: do not close if in privacy mode.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user