diff --git a/lapce-app/src/app.rs b/lapce-app/src/app.rs index 22037ddc..c7d3fe76 100644 --- a/lapce-app/src/app.rs +++ b/lapce-app/src/app.rs @@ -3844,38 +3844,44 @@ pub fn launch() { } } }); - std::thread::spawn(move || { - use self::grammars::*; - let updated = match find_grammar_release() { - Ok(release) => { - let mut updated = false; - match fetch_grammars(&release) { - Err(e) => { - trace!( - TraceLevel::ERROR, - "failed to fetch grammars: {e}" - ); + std::thread::Builder::new() + .name("FindGrammar".to_owned()) + .spawn(move || { + use self::grammars::*; + let updated = match find_grammar_release() { + Ok(release) => { + let mut updated = false; + match fetch_grammars(&release) { + Err(e) => { + trace!( + TraceLevel::ERROR, + "failed to fetch grammars: {e}" + ); + } + Ok(u) => updated |= u, } - Ok(u) => updated |= u, - } - match fetch_queries(&release) { - Err(e) => { - trace!( - TraceLevel::ERROR, - "failed to fetch grammars: {e}" - ); + match fetch_queries(&release) { + Err(e) => { + trace!( + TraceLevel::ERROR, + "failed to fetch grammars: {e}" + ); + } + Ok(u) => updated |= u, } - Ok(u) => updated |= u, + updated } - updated - } - Err(e) => { - trace!(TraceLevel::ERROR, "failed to obtain release info: {e}"); - false - } - }; - send(updated); - }); + Err(e) => { + trace!( + TraceLevel::ERROR, + "failed to obtain release info: {e}" + ); + false + } + }; + send(updated); + }) + .unwrap(); } #[cfg(feature = "updater")] @@ -3888,14 +3894,17 @@ pub fn launch() { latest_release.set(Arc::new(Some(release))); } }); - std::thread::spawn(move || loop { - if let Ok(release) = crate::update::get_latest_release() { - if let Err(err) = tx.send(release) { - tracing::error!("{:?}", err); + std::thread::Builder::new() + .name("LapceUpdater".to_owned()) + .spawn(move || loop { + if let Ok(release) = crate::update::get_latest_release() { + if let Err(err) = tx.send(release) { + tracing::error!("{:?}", err); + } } - } - std::thread::sleep(std::time::Duration::from_secs(60 * 60)); - }); + std::thread::sleep(std::time::Duration::from_secs(60 * 60)); + }) + .unwrap(); } { @@ -3909,11 +3918,14 @@ pub fn launch() { } } }); - std::thread::spawn(move || { - if let Err(err) = listen_local_socket(tx) { - tracing::error!("{:?}", err); - } - }); + std::thread::Builder::new() + .name("ListenLocalSocket".to_owned()) + .spawn(move || { + if let Err(err) = listen_local_socket(tx) { + tracing::error!("{:?}", err); + } + }) + .unwrap(); } { diff --git a/lapce-app/src/db.rs b/lapce-app/src/db.rs index 74531187..a017deec 100644 --- a/lapce-app/src/db.rs +++ b/lapce-app/src/db.rs @@ -63,53 +63,57 @@ pub fn new() -> Result { folder, }; let local_db = db.clone(); - std::thread::spawn(move || -> Result<()> { - loop { - let event = save_rx.recv()?; - match event { - SaveEvent::App(info) => { - if let Err(err) = local_db.insert_app_info(info) { - tracing::error!("{:?}", err); + std::thread::Builder::new() + .name("SaveEventHandler".to_owned()) + .spawn(move || -> Result<()> { + loop { + let event = save_rx.recv()?; + match event { + SaveEvent::App(info) => { + if let Err(err) = local_db.insert_app_info(info) { + tracing::error!("{:?}", err); + } } - } - SaveEvent::Workspace(workspace, info) => { - if let Err(err) = - local_db.insert_workspace(&workspace, &info) - { - tracing::error!("{:?}", err); + SaveEvent::Workspace(workspace, info) => { + if let Err(err) = + local_db.insert_workspace(&workspace, &info) + { + tracing::error!("{:?}", err); + } } - } - SaveEvent::RecentWorkspace(workspace) => { - if let Err(err) = local_db.insert_recent_workspace(workspace) - { - tracing::error!("{:?}", err); + SaveEvent::RecentWorkspace(workspace) => { + if let Err(err) = + local_db.insert_recent_workspace(workspace) + { + tracing::error!("{:?}", err); + } } - } - SaveEvent::Doc(info) => { - if let Err(err) = local_db.insert_doc(&info) { - tracing::error!("{:?}", err); + SaveEvent::Doc(info) => { + if let Err(err) = local_db.insert_doc(&info) { + tracing::error!("{:?}", err); + } } - } - SaveEvent::DisabledVolts(volts) => { - if let Err(err) = local_db.insert_disabled_volts(volts) { - tracing::error!("{:?}", err); + SaveEvent::DisabledVolts(volts) => { + if let Err(err) = local_db.insert_disabled_volts(volts) { + tracing::error!("{:?}", err); + } } - } - SaveEvent::WorkspaceDisabledVolts(workspace, volts) => { - if let Err(err) = local_db - .insert_workspace_disabled_volts(workspace, volts) - { - tracing::error!("{:?}", err); + SaveEvent::WorkspaceDisabledVolts(workspace, volts) => { + if let Err(err) = local_db + .insert_workspace_disabled_volts(workspace, volts) + { + tracing::error!("{:?}", err); + } } - } - SaveEvent::PanelOrder(order) => { - if let Err(err) = local_db.insert_panel_orders(&order) { - tracing::error!("{:?}", err); + SaveEvent::PanelOrder(order) => { + if let Err(err) = local_db.insert_panel_orders(&order) { + tracing::error!("{:?}", err); + } } } } - } - }); + }) + .unwrap(); Ok(db) } diff --git a/lapce-app/src/palette.rs b/lapce-app/src/palette.rs index 2fdc31fc..6af5c722 100644 --- a/lapce-app/src/palette.rs +++ b/lapce-app/src/palette.rs @@ -180,9 +180,12 @@ pub fn new( let (resp_tx, resp_rx) = crossbeam_channel::unbounded(); { let run_id = run_id_counter.clone(); - std::thread::spawn(move || { - Self::update_process(run_id, run_rx, resp_tx); - }); + std::thread::Builder::new() + .name("PaletteUpdateProcess".to_owned()) + .spawn(move || { + Self::update_process(run_id, run_rx, resp_tx); + }) + .unwrap(); } let (filtered_items, set_filtered_items) = cx.create_signal(im::Vector::new()); diff --git a/lapce-app/src/plugin.rs b/lapce-app/src/plugin.rs index d659cef2..f57fb59a 100644 --- a/lapce-app/src/plugin.rs +++ b/lapce-app/src/plugin.rs @@ -198,20 +198,23 @@ pub fn new( } }, ); - std::thread::spawn(move || { - let volts = find_all_volts(&extra_plugin_paths); - let volts = volts - .into_iter() - .filter_map(|meta| { - if meta.wasm.is_none() { - Some((volt_icon(&meta), meta)) - } else { - None - } - }) - .collect::>(); - send(volts); - }); + std::thread::Builder::new() + .name("FindAllVolts".to_owned()) + .spawn(move || { + let volts = find_all_volts(&extra_plugin_paths); + let volts = volts + .into_iter() + .filter_map(|meta| { + if meta.wasm.is_none() { + Some((volt_icon(&meta), meta)) + } else { + None + } + }) + .collect::>(); + send(volts); + }) + .unwrap(); } { diff --git a/lapce-app/src/proxy.rs b/lapce-app/src/proxy.rs index 28503a0c..61efd7c4 100644 --- a/lapce-app/src/proxy.rs +++ b/lapce-app/src/proxy.rs @@ -54,66 +54,76 @@ pub fn new_proxy( { let core_rpc = core_rpc.clone(); let proxy_rpc = proxy_rpc.clone(); - std::thread::spawn(move || { - core_rpc.notification(CoreNotification::ProxyStatus { - status: ProxyStatus::Connecting, - }); - proxy_rpc.initialize( - workspace.path.clone(), - disabled_volts, - extra_plugin_paths, - plugin_configurations, - 1, - 1, - ); + std::thread::Builder::new() + .name("ProxyRpcHandler".to_owned()) + .spawn(move || { + core_rpc.notification(CoreNotification::ProxyStatus { + status: ProxyStatus::Connecting, + }); + proxy_rpc.initialize( + workspace.path.clone(), + disabled_volts, + extra_plugin_paths, + plugin_configurations, + 1, + 1, + ); - match &workspace.kind { - LapceWorkspaceType::Local => { - let core_rpc = core_rpc.clone(); - let proxy_rpc = proxy_rpc.clone(); - std::thread::spawn(move || { - let mut dispatcher = Dispatcher::new(core_rpc, proxy_rpc); - let proxy_rpc = dispatcher.proxy_rpc.clone(); - proxy_rpc.mainloop(&mut dispatcher); - }); - } - LapceWorkspaceType::RemoteSSH(remote) => { - if let Err(e) = start_remote( - SshRemote { - ssh: remote.clone(), - }, - core_rpc.clone(), - proxy_rpc.clone(), - ) { - error!("Failed to start SSH remote: {e}"); + match &workspace.kind { + LapceWorkspaceType::Local => { + let core_rpc = core_rpc.clone(); + let proxy_rpc = proxy_rpc.clone(); + std::thread::Builder::new() + .name("Dispatcher".to_owned()) + .spawn(move || { + let mut dispatcher = + Dispatcher::new(core_rpc, proxy_rpc); + let proxy_rpc = dispatcher.proxy_rpc.clone(); + proxy_rpc.mainloop(&mut dispatcher); + }) + .unwrap(); + } + LapceWorkspaceType::RemoteSSH(remote) => { + if let Err(e) = start_remote( + SshRemote { + ssh: remote.clone(), + }, + core_rpc.clone(), + proxy_rpc.clone(), + ) { + error!("Failed to start SSH remote: {e}"); + } + } + #[cfg(windows)] + LapceWorkspaceType::RemoteWSL(remote) => { + if let Err(e) = start_remote( + wsl::WslRemote { + wsl: remote.clone(), + }, + core_rpc.clone(), + proxy_rpc.clone(), + ) { + error!("Failed to start SSH remote: {e}"); + } } } - #[cfg(windows)] - LapceWorkspaceType::RemoteWSL(remote) => { - if let Err(e) = start_remote( - wsl::WslRemote { - wsl: remote.clone(), - }, - core_rpc.clone(), - proxy_rpc.clone(), - ) { - error!("Failed to start SSH remote: {e}"); - } - } - } - }); + }) + .unwrap(); } let (tx, rx) = crossbeam_channel::unbounded(); { let core_rpc = core_rpc.clone(); - std::thread::spawn(move || { - let mut proxy = Proxy { tx, term_tx }; - core_rpc.mainloop(&mut proxy); - core_rpc.notification(CoreNotification::ProxyStatus { - status: ProxyStatus::Connected, - }); - }) + std::thread::Builder::new() + .name("CoreRpcHandler".to_owned()) + .spawn(move || { + let mut proxy = Proxy { tx, term_tx }; + core_rpc.mainloop(&mut proxy); + core_rpc.notification(CoreNotification::ProxyStatus { + status: ProxyStatus::Connected, + }); + }) + .unwrap() }; let notification = create_signal_from_channel(rx); diff --git a/lapce-app/src/proxy/remote.rs b/lapce-app/src/proxy/remote.rs index e4aa7e06..7a216fca 100644 --- a/lapce-app/src/proxy/remote.rs +++ b/lapce-app/src/proxy/remote.rs @@ -177,71 +177,77 @@ pub fn start_remote( let local_proxy_rpc = proxy_rpc.clone(); let local_writer_tx = writer_tx.clone(); - std::thread::spawn(move || { - for msg in local_proxy_rpc.rx() { - match msg { - ProxyRpc::Request(id, rpc) => { - if let Err(err) = - local_writer_tx.send(RpcMessage::Request(id, rpc)) - { - tracing::error!("{:?}", err); + std::thread::Builder::new() + .name("ProxyRpcHandler".to_owned()) + .spawn(move || { + for msg in local_proxy_rpc.rx() { + match msg { + ProxyRpc::Request(id, rpc) => { + if let Err(err) = + local_writer_tx.send(RpcMessage::Request(id, rpc)) + { + tracing::error!("{:?}", err); + } } - } - ProxyRpc::Notification(rpc) => { - if let Err(err) = - local_writer_tx.send(RpcMessage::Notification(rpc)) - { - tracing::error!("{:?}", err); + ProxyRpc::Notification(rpc) => { + if let Err(err) = + local_writer_tx.send(RpcMessage::Notification(rpc)) + { + tracing::error!("{:?}", err); + } } - } - ProxyRpc::Shutdown => { - if let Err(err) = child.kill() { - tracing::error!("{:?}", err); + ProxyRpc::Shutdown => { + if let Err(err) = child.kill() { + tracing::error!("{:?}", err); + } + if let Err(err) = child.wait() { + tracing::error!("{:?}", err); + } + return; } - if let Err(err) = child.wait() { - tracing::error!("{:?}", err); - } - return; } } - } - }); + }) + .unwrap(); - std::thread::spawn(move || { - for msg in reader_rx { - match msg { - RpcMessage::Request(id, req) => { - let writer_tx = writer_tx.clone(); - let core_rpc = core_rpc.clone(); - std::thread::spawn(move || match core_rpc.request(req) { - Ok(resp) => { - if let Err(err) = - writer_tx.send(RpcMessage::Response(id, resp)) - { - tracing::error!("{:?}", err); + std::thread::Builder::new() + .name("RpcMessageHandler".to_owned()) + .spawn(move || { + for msg in reader_rx { + match msg { + RpcMessage::Request(id, req) => { + let writer_tx = writer_tx.clone(); + let core_rpc = core_rpc.clone(); + std::thread::spawn(move || match core_rpc.request(req) { + Ok(resp) => { + if let Err(err) = + writer_tx.send(RpcMessage::Response(id, resp)) + { + tracing::error!("{:?}", err); + } } - } - Err(e) => { - if let Err(err) = - writer_tx.send(RpcMessage::Error(id, e)) - { - tracing::error!("{:?}", err); + Err(e) => { + if let Err(err) = + writer_tx.send(RpcMessage::Error(id, e)) + { + tracing::error!("{:?}", err); + } } - } - }); - } - RpcMessage::Notification(n) => { - core_rpc.notification(n); - } - RpcMessage::Response(id, resp) => { - proxy_rpc.handle_response(id, Ok(resp)); - } - RpcMessage::Error(id, err) => { - proxy_rpc.handle_response(id, Err(err)); + }); + } + RpcMessage::Notification(n) => { + core_rpc.notification(n); + } + RpcMessage::Response(id, resp) => { + proxy_rpc.handle_response(id, Ok(resp)); + } + RpcMessage::Error(id, err) => { + proxy_rpc.handle_response(id, Err(err)); + } } } - } - }); + }) + .unwrap(); Ok(()) } diff --git a/lapce-app/src/window_tab.rs b/lapce-app/src/window_tab.rs index 486484db..76626934 100644 --- a/lapce-app/src/window_tab.rs +++ b/lapce-app/src/window_tab.rs @@ -318,9 +318,12 @@ pub fn new( crossbeam_channel::unbounded(); { let term_notification_tx = term_notification_tx.clone(); - std::thread::spawn(move || { - terminal_update_process(term_rx, term_notification_tx); - }); + std::thread::Builder::new() + .name("terminal update process".to_owned()) + .spawn(move || { + terminal_update_process(term_rx, term_notification_tx); + }) + .unwrap(); } let proxy = new_proxy( @@ -1326,7 +1329,7 @@ pub fn run_workbench_command( update_in_progress.set(false); }, ); - std::thread::spawn(move || { + std::thread::Builder::new().name("RestartToUpdate".to_owned()).spawn(move || { let do_update = || -> anyhow::Result<()> { let src = crate::update::download_release(&release)?; @@ -1344,7 +1347,7 @@ pub fn run_workbench_command( } send(false); - }); + }).unwrap(); } } }