Add protocol name support to Magpie
This commit is contained in:
parent
cedd5503e6
commit
f4a366a215
|
@ -24,6 +24,7 @@ pub type PanelId = u32;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct CreatePanel {
|
||||
pub id: PanelId,
|
||||
pub protocol: String,
|
||||
pub script: PathBuf,
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,11 @@ impl Client {
|
|||
while let Some(msg) = self.messenger.recv() {
|
||||
println!("Client #{}: {:?}", self.token.0, msg);
|
||||
match msg {
|
||||
MagpieServerMsg::CreatePanel(CreatePanel { id, script }) => {
|
||||
MagpieServerMsg::CreatePanel(CreatePanel {
|
||||
id,
|
||||
protocol,
|
||||
script,
|
||||
}) => {
|
||||
let window = self.data.write().new_window_id();
|
||||
|
||||
if let Some(old_id) = self.id_to_window.insert(id, window) {
|
||||
|
@ -107,7 +111,11 @@ impl Client {
|
|||
let _ = self.window_sender.send_event(msg);
|
||||
}
|
||||
|
||||
let msg = WindowMessage::OpenWindow { id: window, script };
|
||||
let msg = WindowMessage::OpenWindow {
|
||||
id: window,
|
||||
protocol,
|
||||
script,
|
||||
};
|
||||
let _ = self.window_sender.send_event(msg);
|
||||
}
|
||||
MagpieServerMsg::SendMessage(SendMessage { id, msg }) => {
|
||||
|
|
|
@ -17,10 +17,19 @@ use crate::service::ipc::{IpcMessage, IpcMessageSender};
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum WindowMessage {
|
||||
OpenWindow { id: usize, script: PathBuf },
|
||||
CloseWindow { id: usize },
|
||||
OpenWindow {
|
||||
id: usize,
|
||||
protocol: String,
|
||||
script: PathBuf,
|
||||
},
|
||||
CloseWindow {
|
||||
id: usize,
|
||||
},
|
||||
Quit,
|
||||
SendMessage { id: usize, msg: Vec<u8> },
|
||||
SendMessage {
|
||||
id: usize,
|
||||
msg: Vec<u8>,
|
||||
},
|
||||
}
|
||||
|
||||
pub type WindowMessageSender = EventLoopProxy<WindowMessage>;
|
||||
|
@ -155,11 +164,11 @@ impl WindowStore {
|
|||
message: WindowMessage,
|
||||
) -> anyhow::Result<bool> {
|
||||
match message {
|
||||
WindowMessage::OpenWindow { id, script } => {
|
||||
WindowMessage::OpenWindow { id, protocol, script } => {
|
||||
println!("Opening window {} with script {:?}", id, script);
|
||||
let module = std::fs::read(script)?;
|
||||
let mut script = self.runtime.load_module(&module)?;
|
||||
let panel = script.create_panel(vec![])?;
|
||||
let panel = script.create_panel(&protocol, vec![])?;
|
||||
let window = Window::new(panel, &event_loop)?;
|
||||
let window_id = window.get_id();
|
||||
self.windows.insert(window_id, window);
|
||||
|
|
Loading…
Reference in New Issue