mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 20:59:37 +08:00
pynput run as user
This commit is contained in:
parent
6c5b7b3b89
commit
ffb0fa4349
@ -494,12 +494,24 @@ fn start_pynput_service(rx: mpsc::Receiver<(PyMsg, bool)>) {
|
||||
}
|
||||
log::info!("pynput service: {}", py);
|
||||
std::thread::spawn(move || {
|
||||
log::error!(
|
||||
"pynput server exit: {:?}",
|
||||
let username = std::env::var("PYNPUT_USERNAME").unwrap_or("".to_owned());
|
||||
let userid = std::env::var("PYNPUT_USERID").unwrap_or("".to_owned());
|
||||
let status = if username.is_empty() {
|
||||
std::process::Command::new("python3")
|
||||
.arg("./pynput_service.py")
|
||||
.arg(IPC_FILE)
|
||||
.status()
|
||||
.arg(&py)
|
||||
.arg(IPC_FILE).status()
|
||||
} else {
|
||||
std::process::Command::new("sudo").args(vec![
|
||||
&format!("XDG_RUNTIME_DIR=/run/user/{}", userid) as &str,
|
||||
"-u",
|
||||
&username,
|
||||
"python3",
|
||||
&py,
|
||||
IPC_FILE,
|
||||
]).status()
|
||||
};
|
||||
log::info!(
|
||||
"pynput server exit: {:?}", status
|
||||
);
|
||||
unsafe {
|
||||
PYNPUT_EXIT = true;
|
||||
|
@ -22,6 +22,7 @@ server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
server.bind(server_address)
|
||||
server.listen(1)
|
||||
clientsocket, address = server.accept()
|
||||
os.system('chmod a+rw %s'%server_address)
|
||||
print("Got pynput connection")
|
||||
|
||||
|
||||
|
@ -243,7 +243,7 @@ pub fn start_os_service() {
|
||||
log::info!("Exit");
|
||||
}
|
||||
|
||||
fn get_active_userid() -> String {
|
||||
pub fn get_active_userid() -> String {
|
||||
get_value_of_seat0(1)
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,16 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()>
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
||||
static ref ENIGO: Arc<Mutex<Enigo>> = {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if crate::platform::is_root() {
|
||||
std::env::set_var("PYNPUT_USERNAME", crate::platform::linux::get_active_username());
|
||||
std::env::set_var("PYNPUT_USERID", crate::platform::linux::get_active_userid());
|
||||
}
|
||||
}
|
||||
Arc::new(Mutex::new(Enigo::new()))
|
||||
};
|
||||
static ref KEYS_DOWN: Arc<Mutex<HashMap<u64, Instant>>> = Default::default();
|
||||
static ref LATEST_INPUT: Arc<Mutex<Input>> = Default::default();
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ impl Handler {
|
||||
Key::Kp8 => Some(ControlKey::Numpad8),
|
||||
Key::Kp9 => Some(ControlKey::Numpad9),
|
||||
Key::KpDivide => Some(ControlKey::Divide),
|
||||
Key::KpMultiply => Some(ControlKey::Subtract),
|
||||
Key::KpMultiply => Some(ControlKey::Multiply),
|
||||
Key::KpDecimal => Some(ControlKey::Decimal),
|
||||
Key::KpMinus => Some(ControlKey::Subtract),
|
||||
Key::KpPlus => Some(ControlKey::Add),
|
||||
|
Loading…
Reference in New Issue
Block a user