Skip to content

Commit

Permalink
fix(ui): fixture definition lists throw not implemented error
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjoehnk committed Nov 19, 2024
1 parent a0d40dc commit 131a869
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
1 change: 0 additions & 1 deletion crates/ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub fn run<R: RuntimeApi + 'static, AR: AsyncRuntime + 'static, LH: LifecycleHan
let _ui_dialog_events =
UiDialogChannel::new(handlers.ui.clone(), async_runtime, context.weak())
.event_channel(context.weak());
let _ui = UiChannel::new(handlers.ui.clone()).channel(context.weak());
let _ui = UiChannel::new(handlers.ui).async_channel(context.weak());

context
Expand Down
70 changes: 30 additions & 40 deletions crates/ui/src/plugin/channels/method/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,45 @@ use nativeshell::shell::{
use mizer_api::handlers::UiHandler;
use mizer_api::RuntimeApi;

use crate::plugin::channels::MethodReplyExt;
use crate::plugin::channels::{MessageExt, MethodReplyExt};

#[derive(Clone)]
pub struct UiChannel<R> {
handler: UiHandler<R>,
}

impl<R: RuntimeApi + 'static> MethodCallHandler for UiChannel<R> {
fn on_method_call(
&mut self,
#[async_trait(?Send)]
impl<R: RuntimeApi + 'static> AsyncMethodCallHandler for UiChannel<R> {
async fn on_method_call(
&self,
call: MethodCall<Value>,
resp: MethodCallReply<Value>,
engine_handle: EngineHandle,
) {
_engine: EngineHandle,
) -> MethodCallResult<Value> {
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)] => {
Expand All @@ -43,37 +62,12 @@ impl<R: RuntimeApi + 'static> MethodCallHandler for UiChannel<R> {
.collect::<Vec<_>>();
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<R: RuntimeApi + 'static> AsyncMethodCallHandler for UiChannel<R> {
async fn on_method_call(
&self,
call: MethodCall<Value>,
_engine: EngineHandle,
) -> MethodCallResult<Value> {
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",
Expand All @@ -92,10 +86,6 @@ impl<R: RuntimeApi + 'static> UiChannel<R> {
Self { handler }
}

pub fn channel(self, context: Context) -> MethodChannel {
MethodChannel::new(context, "mizer.live/ui", self)
}

pub fn async_channel(self, context: Context) -> RegisteredAsyncMethodCallHandler<UiChannel<R>> {
RegisteredAsyncMethodCallHandler::new(context, "mizer.live/ui", self)
}
Expand Down
12 changes: 12 additions & 0 deletions crates/ui/src/plugin/channels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ impl MethodReplyExt for MethodCallReply<Value> {
todo!()
}
}

trait MessageExt {
fn into_value(self) -> Value;
}

impl<T: mizer_api::Message> MessageExt for T {
fn into_value(self) -> Value {
let msg = self.encode_to_vec();

Value::U8List(msg)
}
}

0 comments on commit 131a869

Please sign in to comment.