summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zellij-utils/src/plugin_api/event.rs')
-rw-r--r--zellij-utils/src/plugin_api/event.rs43
1 files changed, 39 insertions, 4 deletions
diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs
index a322ec3bf..d9e5341d6 100644
--- a/zellij-utils/src/plugin_api/event.rs
+++ b/zellij-utils/src/plugin_api/event.rs
@@ -6,6 +6,7 @@ pub use super::generated_api::api::{
EventType as ProtobufEventType, InputModeKeybinds as ProtobufInputModeKeybinds,
KeyBind as ProtobufKeyBind, ModeUpdatePayload as ProtobufModeUpdatePayload,
PaneInfo as ProtobufPaneInfo, PaneManifest as ProtobufPaneManifest,
+ ResurrectableSession as ProtobufResurrectableSession,
SessionManifest as ProtobufSessionManifest, TabInfo as ProtobufTabInfo, *,
},
input_mode::InputMode as ProtobufInputMode,
@@ -23,6 +24,7 @@ use crate::input::actions::Action;
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::path::PathBuf;
+use std::time::Duration;
impl TryFrom<ProtobufEvent> for Event {
type Error = &'static str;
@@ -176,10 +178,19 @@ impl TryFrom<ProtobufEvent> for Event {
protobuf_session_update_payload,
)) => {
let mut session_infos: Vec<SessionInfo> = vec![];
+ let mut resurrectable_sessions: Vec<(String, Duration)> = vec![];
for protobuf_session_info in protobuf_session_update_payload.session_manifests {
session_infos.push(SessionInfo::try_from(protobuf_session_info)?);
}
- Ok(Event::SessionUpdate(session_infos))
+ for protobuf_resurrectable_session in
+ protobuf_session_update_payload.resurrectable_sessions
+ {
+ resurrectable_sessions.push(protobuf_resurrectable_session.into());
+ }
+ Ok(Event::SessionUpdate(
+ session_infos,
+ resurrectable_sessions.into(),
+ ))
},
_ => Err("Malformed payload for the SessionUpdate Event"),
},
@@ -359,13 +370,18 @@ impl TryFrom<Event> for ProtobufEvent {
)),
})
},
- Event::SessionUpdate(session_infos) => {
+ Event::SessionUpdate(session_infos, resurrectable_sessions) => {
let mut protobuf_session_manifests = vec![];
for session_info in session_infos {
protobuf_session_manifests.push(session_info.try_into()?);
}
+ let mut protobuf_resurrectable_sessions = vec![];
+ for resurrectable_session in resurrectable_sessions {
+ protobuf_resurrectable_sessions.push(resurrectable_session.into());
+ }
let session_update_payload = SessionUpdatePayload {
session_manifests: protobuf_session_manifests,
+ resurrectable_sessions: protobuf_resurrectable_sessions,
};
Ok(ProtobufEvent {
name: ProtobufEventType::SessionUpdate as i32,
@@ -887,6 +903,24 @@ impl TryFrom<EventType> for ProtobufEventType {
}
}
+impl From<ProtobufResurrectableSession> for (String, Duration) {
+ fn from(protobuf_resurrectable_session: ProtobufResurrectableSession) -> (String, Duration) {
+ (
+ protobuf_resurrectable_session.name,
+ Duration::from_secs(protobuf_resurrectable_session.creation_time),
+ )
+ }
+}
+
+impl From<(String, Duration)> for ProtobufResurrectableSession {
+ fn from(session_name_and_creation_time: (String, Duration)) -> ProtobufResurrectableSession {
+ ProtobufResurrectableSession {
+ name: session_name_and_creation_time.0,
+ creation_time: session_name_and_creation_time.1.as_secs(),
+ }
+ }
+}
+
#[test]
fn serialize_mode_update_event() {
use prost::Message;
@@ -1249,7 +1283,7 @@ fn serialize_file_system_delete_event() {
#[test]
fn serialize_session_update_event() {
use prost::Message;
- let session_update_event = Event::SessionUpdate(Default::default());
+ let session_update_event = Event::SessionUpdate(Default::default(), Default::default());
let protobuf_event: ProtobufEvent = session_update_event.clone().try_into().unwrap();
let serialized_protobuf_event = protobuf_event.encode_to_vec();
let deserialized_protobuf_event: ProtobufEvent =
@@ -1360,8 +1394,9 @@ fn serialize_session_update_event_with_non_default_values() {
is_current_session: false,
};
let session_infos = vec![session_info_1, session_info_2];
+ let resurrectable_sessions = vec![];
- let session_update_event = Event::SessionUpdate(session_infos);
+ let session_update_event = Event::SessionUpdate(session_infos, resurrectable_sessions);
let protobuf_event: ProtobufEvent = session_update_event.clone().try_into().unwrap();
let serialized_protobuf_event = protobuf_event.encode_to_vec();
let deserialized_protobuf_event: ProtobufEvent =