pub use super::generated_api::api::{
action::{PaneIdAndShouldFloat, SwitchToModePayload},
event::EventNameList as ProtobufEventNameList,
input_mode::InputMode as ProtobufInputMode,
plugin_command::{
plugin_command::Payload, CommandName, ExecCmdPayload, IdAndNewName, MovePayload,
OpenCommandPanePayload, OpenFilePayload, PluginCommand as ProtobufPluginCommand,
PluginMessagePayload, RequestPluginPermissionPayload, ResizePayload, SetTimeoutPayload,
SubscribePayload, SwitchSessionPayload, SwitchTabToPayload, UnsubscribePayload,
},
plugin_permission::PermissionType as ProtobufPermissionType,
resize::ResizeAction as ProtobufResizeAction,
};
use crate::data::{ConnectToSession, PermissionType, PluginCommand};
use std::convert::TryFrom;
impl TryFrom<ProtobufPluginCommand> for PluginCommand {
type Error = &'static str;
fn try_from(protobuf_plugin_command: ProtobufPluginCommand) -> Result<Self, &'static str> {
match CommandName::from_i32(protobuf_plugin_command.name) {
Some(CommandName::Subscribe) => match protobuf_plugin_command.payload {
Some(Payload::SubscribePayload(subscribe_payload)) => {
let protobuf_event_list = subscribe_payload.subscriptions;
match protobuf_event_list {
Some(protobuf_event_list) => {
Ok(PluginCommand::Subscribe(protobuf_event_list.try_into()?))
},
None => Err("malformed subscription event"),
}
},
_ => Err("Mismatched payload for Subscribe"),
},
Some(CommandName::Unsubscribe) => match protobuf_plugin_command.payload {
Some(Payload::UnsubscribePayload(unsubscribe_payload)) => {
let protobuf_event_list = unsubscribe_payload.subscriptions;
match protobuf_event_list {
Some(protobuf_event_list) => {
Ok(PluginCommand::Unsubscribe(protobuf_event_list.try_into()?))
},