fn handle_platform_message(&self, mut msg: PlatformMessage) {
        debug_assert_eq!(msg.channel, self.name());
        if let Some(handler) = self.message_handler() {
            if let Some(engine) = self.engine() {
                let message = self.codec().decode_message(msg.message).unwrap();
                let channel = self.name().to_owned();
                log::trace!("on channel {}, got message {:?}", channel, message);
                let plugin_name = self.plugin_name();
                let mut response_handle = msg.response_handle.take();
                let codec = self.codec();
                engine.clone().run_in_background(async move {
                    let mut handler = handler.write().unwrap();
                    let result = handler.on_message(message, engine.clone());
                    let response = match result {
                        Ok(value) => value,
                        Err(error) => {
                            log::error!(
                                target: handler
                                    .log_target()
                                    .unwrap_or(plugin_name),
                                "error in message handler on channel {}: {}",
                                channel,
                                error);
                            Value::Null
                        }
                    };
                    if response_handle.is_some() {
                        engine.post_platform_callback(crate::MainThreadCallback::Channel((
                            channel,
                            Box::new(move |channel| {
                                let buf = codec.encode_message(&response);
                                if let Some(handle) = response_handle.take() {
                                    channel.send_response(handle, &buf);
                                }
                            }),
                        )));
                    }
                });
            }
        }
    }
/// Handle incoming message received on this channel
Handle incoming message received on this channel
Handle incoming message received on this channel
fn handle_platform_message(&self, mut msg: PlatformMessage) {
        debug_assert_eq!(msg.channel, self.name());
        if let Some(handler) = self.message_handler() {
            if let Some(engine) = self.engine() {
                let message = self.codec().decode_message(msg.message).unwrap();
                let channel = self.name().to_owned();
                log::trace!("on channel {}, got message {:?}", channel, message);
                let plugin_name = self.plugin_name();
                let mut response_handle = msg.response_handle.take();
                let codec = self.codec();
                engine.clone().run_in_background(async move {
                    let mut handler = handler.write().unwrap();
                    let result = handler.on_message(message, engine.clone());
                    let response = match result {
                        Ok(value) => value,
                        Err(error) => {
                            log::error!(
                                target: handler
                                    .log_target()
                                    .unwrap_or(plugin_name),
                                "error in message handler on channel {}: {}",
                                channel,
                                error);
                            Value::Null
                        }
                    };
                    if response_handle.is_some() {
                        engine.post_platform_callback(crate::MainThreadCallback::Channel((
                            channel,
                            Box::new(move |channel| {
                                let buf = codec.encode_message(&response);
                                if let Some(handle) = response_handle.take() {
                                    channel.send_response(handle, &buf);
                                }
                            }),
                        )));
                    }
                });
            }
        }
    }
fn handle_platform_message ( & self , mut msg : PlatformMessage ) { debug_assert_eq ! ( msg channel self name ( ) ) ; if let Some ( handler ) = self . message_handler ( ) { if let Some ( engine ) = self . engine ( ) { let message = self . codec ( ) . decode_message ( msg . message ) . unwrap ( ) ; let channel = self . name ( ) . to_owned ( ) ; log :: trace ! ( " " channel message ) ; let plugin_name = self . plugin_name ( ) ; let mut response_handle = msg . response_handle . take ( ) ; let codec = self . codec ( ) ; engine . clone ( ) . run_in_background ( async move { let mut handler = handler . write ( ) . unwrap ( ) ; let result = handler . on_message ( message , engine . clone ( ) ) ; let response = match result { Ok ( value ) => value , Err ( error ) => { log :: error ! ( target handler log_target ( ) unwrap_or ( plugin_name ) " " channel error ) ; Value :: Null } } ; if response_handle . is_some ( ) { engine . post_platform_callback ( crate :: MainThreadCallback :: Channel ( ( channel , Box :: new ( move | channel | { let buf = codec . encode_message ( & response ) ; if let Some ( handle ) = response_handle . take ( ) { channel . send_response ( handle , & buf ) ; } } ) , ) ) ) ; } } ) ; } } }
Handle incoming message received on this channel
Handle incoming message received on this channel
&self
msg
PlatformMessage