From 131a8697ddbbd539cf96ac9d7255dfe55fa53941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20J=C3=B6hnk?= Date: Tue, 19 Nov 2024 18:29:09 +0100 Subject: [PATCH] fix(ui): fixture definition lists throw not implemented error --- crates/ui/src/lib.rs | 1 - crates/ui/src/plugin/channels/method/ui.rs | 70 ++++++++++------------ crates/ui/src/plugin/channels/mod.rs | 12 ++++ 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 5473712fd..548849932 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -101,7 +101,6 @@ pub fn run { handler: UiHandler, } -impl MethodCallHandler for UiChannel { - fn on_method_call( - &mut self, +#[async_trait(?Send)] +impl AsyncMethodCallHandler for UiChannel { + async fn on_method_call( + &self, call: MethodCall, - resp: MethodCallReply, - engine_handle: EngineHandle, - ) { + _engine: EngineHandle, + ) -> MethodCallResult { match call.method.as_str() { + "commandLineExecute" => match call.args { + Value::String(command) => { + let result = self.handler.command_line_execute(command).await; + + match result { + Ok(_) => Ok(Value::Null), + Err(e) => Err(MethodCallError::from_code_message( + &format!("{e:?}"), + &format!("{e:?}"), + )), + } + } + _ => Err(MethodCallError::from_code_message( + "invalid-arguments", + "Invalid arguments", + )), + }, "showTable" => match call.args { Value::String(name) => { let tabular_data = self.handler.show_table(&name, &[]); - resp.respond_result(tabular_data); + tabular_data + .map(|r| r.into_value()) + .map_err(|e| MethodCallError::from_code_message(&format!("{e:?}"), &format!("{e}"))) } Value::List(args) => match &args[..] { [Value::String(name), Value::List(args)] => { @@ -43,37 +62,12 @@ impl MethodCallHandler for UiChannel { .collect::>(); let tabular_data = self.handler.show_table(name, &args); - resp.respond_result(tabular_data); + tabular_data + .map(|r| r.into_value()) + .map_err(|e| MethodCallError::from_code_message(&format!("{e:?}"), &format!("{e}"))) } _ => unreachable!("Invalid showTable call"), }, - _ => resp.respond_error(anyhow::anyhow!("Invalid arguments")), - }, - _ => resp.not_implemented(), - } - } -} - -#[async_trait(?Send)] -impl AsyncMethodCallHandler for UiChannel { - async fn on_method_call( - &self, - call: MethodCall, - _engine: EngineHandle, - ) -> MethodCallResult { - match call.method.as_str() { - "commandLineExecute" => match call.args { - Value::String(command) => { - let result = self.handler.command_line_execute(command).await; - - match result { - Ok(_) => Ok(Value::Null), - Err(e) => Err(MethodCallError::from_code_message( - &format!("{e:?}"), - &format!("{e:?}"), - )), - } - } _ => Err(MethodCallError::from_code_message( "invalid-arguments", "Invalid arguments", @@ -92,10 +86,6 @@ impl UiChannel { Self { handler } } - pub fn channel(self, context: Context) -> MethodChannel { - MethodChannel::new(context, "mizer.live/ui", self) - } - pub fn async_channel(self, context: Context) -> RegisteredAsyncMethodCallHandler> { RegisteredAsyncMethodCallHandler::new(context, "mizer.live/ui", self) } diff --git a/crates/ui/src/plugin/channels/mod.rs b/crates/ui/src/plugin/channels/mod.rs index 9438c4462..f729ce42e 100644 --- a/crates/ui/src/plugin/channels/mod.rs +++ b/crates/ui/src/plugin/channels/mod.rs @@ -65,3 +65,15 @@ impl MethodReplyExt for MethodCallReply { todo!() } } + +trait MessageExt { + fn into_value(self) -> Value; +} + +impl MessageExt for T { + fn into_value(self) -> Value { + let msg = self.encode_to_vec(); + + Value::U8List(msg) + } +} \ No newline at end of file