proxy start at ssh

This commit is contained in:
Dongdong Zhou 2020-11-21 17:49:25 +00:00
parent b9c1468389
commit b2daa3e0ae
3 changed files with 43 additions and 11 deletions

View File

@ -1241,10 +1241,11 @@ pub fn select(
&PaletteType::Workspace => {
let state =
LAPCE_APP_STATE.get_tab_state(&self.window_id, &self.tab_id);
state.stop();
*state.workspace.lock() = self.workspace.clone().unwrap();
*state.ssh_session.lock() = None;
state.stop();
state.start_plugin();
state.start_proxy();
ctx.request_paint();
}
&PaletteType::Command => {

View File

@ -22,6 +22,8 @@
use crate::buffer::BufferId;
use crate::command::LapceUICommand;
use crate::state::LapceWorkspace;
use crate::state::LapceWorkspaceType;
use crate::state::LAPCE_APP_STATE;
#[derive(Clone)]
@ -81,6 +83,10 @@ pub fn get_completion(
f,
);
}
pub fn stop(&self) {
self.process.lock().kill();
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -161,13 +167,29 @@ fn handle_request(
pub fn start_proxy_process(
window_id: WindowId,
tab_id: WidgetId,
workspace: PathBuf,
workspace: LapceWorkspace,
) {
thread::spawn(move || {
let child = Command::new("/Users/Lulu/lapce/target/debug/lapce-proxy")
let workspace_type = LAPCE_APP_STATE
.get_tab_state(&window_id, &tab_id)
.workspace
.lock()
.kind
.clone();
let mut child = match workspace_type {
LapceWorkspaceType::Local => {
Command::new("/Users/Lulu/lapce/target/debug/lapce-proxy")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn();
.spawn()
}
LapceWorkspaceType::RemoteSSH(user, host) => Command::new("ssh")
.arg(format!("{}@{}", user, host))
.arg("./lapce/lapce-proxy")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn(),
};
if child.is_err() {
println!("can't start proxy {:?}", child);
return;
@ -181,7 +203,7 @@ pub fn start_proxy_process(
peer,
process: Arc::new(Mutex::new(child)),
};
proxy.initialize(workspace);
proxy.initialize(workspace.path.clone());
{
let state = LAPCE_APP_STATE.get_tab_state(&window_id, &tab_id);
*state.proxy.lock() = Some(proxy);

View File

@ -293,6 +293,7 @@ pub fn get_state(&self, tab_id: &WidgetId) -> LapceTabState {
#[derive(Clone)]
pub struct LapceTabState {
pub window_id: WindowId,
pub tab_id: WidgetId,
pub status_id: WidgetId,
pub workspace: Arc<Mutex<LapceWorkspace>>,
@ -321,6 +322,7 @@ pub fn new(window_id: WindowId) -> LapceTabState {
let tab_id = WidgetId::next();
let status_id = WidgetId::next();
let state = LapceTabState {
window_id,
tab_id: tab_id.clone(),
status_id,
workspace: Arc::new(Mutex::new(workspace.clone())),
@ -350,7 +352,7 @@ pub fn new(window_id: WindowId) -> LapceTabState {
ssh_session: Arc::new(Mutex::new(None)),
proxy: Arc::new(Mutex::new(None)),
};
start_proxy_process(window_id, tab_id, workspace.path.clone());
start_proxy_process(window_id, tab_id, workspace.clone());
let local_state = state.clone();
thread::spawn(move || {
local_state.start_plugin();
@ -358,9 +360,16 @@ pub fn new(window_id: WindowId) -> LapceTabState {
state
}
pub fn start_proxy(&self) {
start_proxy_process(
self.window_id,
self.tab_id,
self.workspace.lock().clone(),
);
}
pub fn stop(&self) {
self.plugins.lock().stop();
self.lsp.lock().stop();
self.proxy.lock().as_ref().unwrap().stop();
}
pub fn start_plugin(&self) {