mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
chore: fixed imports
This commit is contained in:
parent
535de6c2fc
commit
8225524cb3
7 changed files with 42 additions and 33 deletions
|
@ -6,7 +6,10 @@ use std::sync::Arc;
|
|||
use tokio::sync::{mpsc, oneshot, watch};
|
||||
|
||||
use crate::{
|
||||
api::{controller::{AsyncReceiver, AsyncSender, ControllerCallback}, Controller, Cursor},
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender, ControllerCallback},
|
||||
Controller, Cursor,
|
||||
},
|
||||
errors::ControllerResult,
|
||||
};
|
||||
use codemp_proto::{
|
||||
|
|
|
@ -2,7 +2,10 @@ use jni::{objects::JObject, JNIEnv};
|
|||
use jni_toolbox::jni;
|
||||
|
||||
use crate::{
|
||||
api::{controller::{AsyncReceiver, AsyncSender}, TextChange},
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender},
|
||||
TextChange,
|
||||
},
|
||||
errors::ControllerError,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use crate::{
|
||||
api::{Controller, Cursor},
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender},
|
||||
Cursor,
|
||||
},
|
||||
errors::ControllerError,
|
||||
};
|
||||
use jni::{objects::JObject, JNIEnv};
|
||||
use jni_toolbox::jni;
|
||||
use crate::{
|
||||
api::{controller::{AsyncSender, AsyncReceiver}, Cursor},
|
||||
errors::ControllerError
|
||||
};
|
||||
|
||||
use super::null_check;
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use crate::{
|
||||
api::controller::AsyncReceiver,
|
||||
errors::{ConnectionError, ControllerError, RemoteError},
|
||||
ffi::java::null_check,
|
||||
Workspace,
|
||||
};
|
||||
use jni::{objects::JObject, JNIEnv};
|
||||
use jni_toolbox::jni;
|
||||
|
||||
/// Get the workspace id.
|
||||
|
@ -115,17 +117,25 @@ fn clear_callback(workspace: &mut Workspace) {
|
|||
|
||||
/// Register a callback for workspace events.
|
||||
#[jni(package = "mp.code", class = "Workspace")]
|
||||
fn callback<'local>(env: &mut JNIEnv<'local>, controller: &mut crate::Workspace, cb: JObject<'local>) {
|
||||
fn callback<'local>(
|
||||
env: &mut JNIEnv<'local>,
|
||||
controller: &mut crate::Workspace,
|
||||
cb: JObject<'local>,
|
||||
) {
|
||||
null_check!(env, cb, {});
|
||||
let Ok(cb_ref) = env.new_global_ref(cb) else {
|
||||
env.throw_new("mp/code/exceptions/JNIException", "Failed to pin callback reference!")
|
||||
.expect("Failed to throw exception!");
|
||||
env.throw_new(
|
||||
"mp/code/exceptions/JNIException",
|
||||
"Failed to pin callback reference!",
|
||||
)
|
||||
.expect("Failed to throw exception!");
|
||||
return;
|
||||
};
|
||||
|
||||
controller.callback(move |workspace: crate::Workspace| {
|
||||
let jvm = super::jvm();
|
||||
let mut env = jvm.attach_current_thread_permanently()
|
||||
let mut env = jvm
|
||||
.attach_current_thread_permanently()
|
||||
.expect("failed attaching to main JVM thread");
|
||||
if let Err(e) = env.with_local_frame(5, |env| {
|
||||
use jni_toolbox::IntoJavaObject;
|
||||
|
@ -134,7 +144,7 @@ fn callback<'local>(env: &mut JNIEnv<'local>, controller: &mut crate::Workspace,
|
|||
&cb_ref,
|
||||
"accept",
|
||||
"(Ljava/lang/Object;)V",
|
||||
&[jni::objects::JValueGen::Object(&jworkspace)]
|
||||
&[jni::objects::JValueGen::Object(&jworkspace)],
|
||||
) {
|
||||
tracing::error!("error invoking callback: {e:?}");
|
||||
};
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use napi::threadsafe_function::{ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode};
|
||||
use napi_derive::napi;
|
||||
use crate::api::TextChange;
|
||||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||
use crate::api::TextChange;
|
||||
use crate::buffer::controller::BufferController;
|
||||
use napi::threadsafe_function::{
|
||||
ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
use napi::threadsafe_function::ErrorStrategy::Fatal;
|
||||
use napi_derive::napi;
|
||||
use napi::threadsafe_function::{ThreadsafeFunction, ThreadSafeCallContext, ThreadsafeFunctionCallMode};
|
||||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||
use crate::cursor::controller::CursorController;
|
||||
use napi::threadsafe_function::ErrorStrategy::Fatal;
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
use napi::threadsafe_function::ErrorStrategy::Fatal;
|
||||
use napi::threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode};
|
||||
use napi_derive::napi;
|
||||
use crate::Workspace;
|
||||
use crate::api::controller::AsyncReceiver;
|
||||
use crate::buffer::controller::BufferController;
|
||||
use crate::cursor::controller::CursorController;
|
||||
use crate::api::controller::AsyncReceiver;
|
||||
use crate::Workspace;
|
||||
use napi::threadsafe_function::ErrorStrategy::Fatal;
|
||||
use napi::threadsafe_function::{
|
||||
ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
||||
};
|
||||
use napi_derive::napi;
|
||||
|
||||
use super::client::JsUser;
|
||||
|
||||
#[napi(object, js_name = "Event")]
|
||||
pub struct JsEvent {
|
||||
|
@ -111,18 +114,14 @@ impl Workspace {
|
|||
}
|
||||
|
||||
#[napi(js_name = "callback", ts_args_type = "fun: (event: Workspace) => void")]
|
||||
pub fn js_callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
let tsfn : ThreadsafeFunction<crate::Workspace, Fatal> =
|
||||
fun.create_threadsafe_function(0,
|
||||
|ctx : ThreadSafeCallContext<crate::Workspace>| {
|
||||
pub fn js_callback(&self, fun: napi::JsFunction) -> napi::Result<()> {
|
||||
let tsfn: ThreadsafeFunction<crate::Workspace, Fatal> = fun
|
||||
.create_threadsafe_function(0, |ctx: ThreadSafeCallContext<crate::Workspace>| {
|
||||
Ok(vec![ctx.value])
|
||||
}
|
||||
)?;
|
||||
self.callback(move |controller : Workspace| {
|
||||
|
||||
})?;
|
||||
self.callback(move |controller: Workspace| {
|
||||
tsfn.call(controller.clone(), ThreadsafeFunctionCallMode::Blocking); //check this with tracing also we could use Ok(event) to get the error
|
||||
// If it blocks the main thread too many time we have to change this
|
||||
|
||||
// If it blocks the main thread too many time we have to change this
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue