mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 14:59:02 +08:00
fix rustPointerInput jni parameter declaration, call new_string in with_local_frame (#8266)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
a84b9bd2c8
commit
bd51afe86c
@ -227,7 +227,7 @@ pub fn clear_codec_info() {
|
||||
)?;
|
||||
Ok(JObject::null())
|
||||
})?;
|
||||
*/
|
||||
*/
|
||||
pub fn call_main_service_pointer_input(kind: &str, mask: i32, x: i32, y: i32) -> JniResult<()> {
|
||||
if let (Some(jvm), Some(ctx)) = (
|
||||
JVM.read().unwrap().as_ref(),
|
||||
@ -238,7 +238,7 @@ pub fn call_main_service_pointer_input(kind: &str, mask: i32, x: i32, y: i32) ->
|
||||
env.call_method(
|
||||
ctx,
|
||||
"rustPointerInput",
|
||||
"(Ljava/lang/String;III)V",
|
||||
"(IIII)V",
|
||||
&[
|
||||
JValue::Int(kind),
|
||||
JValue::Int(mask),
|
||||
@ -278,19 +278,22 @@ pub fn call_main_service_get_by_name(name: &str) -> JniResult<String> {
|
||||
MAIN_SERVICE_CTX.read().unwrap().as_ref(),
|
||||
) {
|
||||
let mut env = jvm.attach_current_thread_as_daemon()?;
|
||||
let name = env.new_string(name)?;
|
||||
let res = env
|
||||
.call_method(
|
||||
ctx,
|
||||
"rustGetByName",
|
||||
"(Ljava/lang/String;)Ljava/lang/String;",
|
||||
&[JValue::Object(&JObject::from(name))],
|
||||
)?
|
||||
.l()?;
|
||||
let res = JString::from(res);
|
||||
let res = env.get_string(&res)?;
|
||||
let res = res.to_string_lossy().to_string();
|
||||
return Ok(res);
|
||||
let res = env.with_local_frame(10, |env| -> JniResult<String> {
|
||||
let name = env.new_string(name)?;
|
||||
let res = env
|
||||
.call_method(
|
||||
ctx,
|
||||
"rustGetByName",
|
||||
"(Ljava/lang/String;)Ljava/lang/String;",
|
||||
&[JValue::Object(&JObject::from(name))],
|
||||
)?
|
||||
.l()?;
|
||||
let res = JString::from(res);
|
||||
let res = env.get_string(&res)?;
|
||||
let res = res.to_string_lossy().to_string();
|
||||
Ok(res)
|
||||
})?;
|
||||
Ok(res)
|
||||
} else {
|
||||
return Err(JniError::ThrowFailed(-1));
|
||||
}
|
||||
@ -306,20 +309,23 @@ pub fn call_main_service_set_by_name(
|
||||
MAIN_SERVICE_CTX.read().unwrap().as_ref(),
|
||||
) {
|
||||
let mut env = jvm.attach_current_thread_as_daemon()?;
|
||||
let name = env.new_string(name)?;
|
||||
let arg1 = env.new_string(arg1.unwrap_or(""))?;
|
||||
let arg2 = env.new_string(arg2.unwrap_or(""))?;
|
||||
env.with_local_frame(10, |env| -> JniResult<()> {
|
||||
let name = env.new_string(name)?;
|
||||
let arg1 = env.new_string(arg1.unwrap_or(""))?;
|
||||
let arg2 = env.new_string(arg2.unwrap_or(""))?;
|
||||
|
||||
env.call_method(
|
||||
ctx,
|
||||
"rustSetByName",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
&[
|
||||
JValue::Object(&JObject::from(name)),
|
||||
JValue::Object(&JObject::from(arg1)),
|
||||
JValue::Object(&JObject::from(arg2)),
|
||||
],
|
||||
)?;
|
||||
env.call_method(
|
||||
ctx,
|
||||
"rustSetByName",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
&[
|
||||
JValue::Object(&JObject::from(name)),
|
||||
JValue::Object(&JObject::from(arg1)),
|
||||
JValue::Object(&JObject::from(arg2)),
|
||||
],
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err(JniError::ThrowFailed(-1));
|
||||
|
@ -2180,7 +2180,8 @@ pub fn session_request_new_display_init_msgs(session_id: SessionID, display: usi
|
||||
pub mod server_side {
|
||||
use hbb_common::{config, log};
|
||||
use jni::{
|
||||
objects::{JClass, JString},
|
||||
errors::{Error as JniError, Result as JniResult},
|
||||
objects::{JClass, JObject, JString},
|
||||
sys::jstring,
|
||||
JNIEnv,
|
||||
};
|
||||
@ -2223,15 +2224,20 @@ pub mod server_side {
|
||||
input: JString,
|
||||
) -> jstring {
|
||||
let mut env = env;
|
||||
let res = if let (Ok(input), Ok(locale)) = (env.get_string(&input), env.get_string(&locale))
|
||||
{
|
||||
let input: String = input.into();
|
||||
let locale: String = locale.into();
|
||||
crate::client::translate_locale(input, &locale)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
return env.new_string(res).unwrap_or(input).into_raw();
|
||||
let res =
|
||||
env.with_local_frame_returning_local(10, |env: &mut JNIEnv| -> JniResult<JObject> {
|
||||
let res = if let (Ok(input), Ok(locale)) =
|
||||
(env.get_string(&input), env.get_string(&locale))
|
||||
{
|
||||
let input: String = input.into();
|
||||
let locale: String = locale.into();
|
||||
crate::client::translate_locale(input, &locale)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
env.new_string(res).map(|v| v.into())
|
||||
});
|
||||
res.unwrap_or(input.into()).into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
Loading…
Reference in New Issue
Block a user