Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions crates/ark/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use harp::utils::r_normalize_path;
use libr::Rf_ScalarLogical;
use libr::SEXP;

use crate::console::Console;
use crate::help::message::HelpEvent;
use crate::help::message::ShowHelpUrlKind;
use crate::help::message::ShowHelpUrlParams;
use crate::interface::RMain;
use crate::ui::events::send_open_with_system_event;
use crate::ui::events::send_show_url_event;

Expand All @@ -26,17 +26,15 @@ pub unsafe extern "C-unwind" fn ps_browse_url(url: SEXP) -> anyhow::Result<SEXP>
}

fn is_help_url(url: &str) -> bool {
RMain::with(|main| main.is_help_url(url))
Console::get().is_help_url(url)
}

fn handle_help_url(url: String) -> anyhow::Result<()> {
RMain::with(|main| {
let event = HelpEvent::ShowHelpUrl(ShowHelpUrlParams {
url,
kind: ShowHelpUrlKind::HelpProxy,
});
main.send_help_event(event)
})
let event = HelpEvent::ShowHelpUrl(ShowHelpUrlParams {
url,
kind: ShowHelpUrlKind::HelpProxy,
});
Console::get().send_help_event(event)
}

unsafe fn ps_browse_url_impl(url: SEXP) -> anyhow::Result<SEXP> {
Expand Down
48 changes: 24 additions & 24 deletions crates/ark/src/connections/r_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use stdext::spawn;
use stdext::unwrap;
use uuid::Uuid;

use crate::interface::RMain;
use crate::console::Console;
use crate::modules::ARK_ENVS;
use crate::r_task;

Expand Down Expand Up @@ -307,15 +307,15 @@ pub unsafe extern "C-unwind" fn ps_connection_opened(
let id = Uuid::new_v4().to_string();
let id_r: RObject = id.clone().into();

if !RMain::is_initialized() {
// If RMain is not initialized, we are probably in unit tests, so we
if !Console::is_initialized() {
// If Console is not initialized, we are probably in unit tests, so we
// just don't start the connection and let the testing code manually do
// it. Note that RMain could be initialized in integration tests.
log::warn!("Connection Pane: RMain is not initialized. Connection will not be started.");
// it. Note that Console could be initialized in integration tests.
log::warn!("Connection Pane: Console is not initialized. Connection will not be started.");
return Ok(id_r.sexp);
}

let main = RMain::get();
let console = Console::get();

let metadata = Metadata {
name: RObject::view(name).to::<String>()?,
Expand All @@ -325,7 +325,7 @@ pub unsafe extern "C-unwind" fn ps_connection_opened(
code: RObject::view(code).to::<Option<String>>().unwrap_or(None),
};

if let Err(err) = RConnection::start(metadata, main.get_comm_manager_tx().clone(), id) {
if let Err(err) = RConnection::start(metadata, console.get_comm_manager_tx().clone(), id) {
log::error!("Connection Pane: Failed to start connection: {err:?}");
return Err(err);
}
Expand All @@ -335,45 +335,45 @@ pub unsafe extern "C-unwind" fn ps_connection_opened(

#[harp::register]
pub unsafe extern "C-unwind" fn ps_connection_closed(id: SEXP) -> Result<SEXP, anyhow::Error> {
let main = RMain::get();
let id_ = RObject::view(id).to::<String>()?;
let id = RObject::view(id).to::<String>()?;

main.get_comm_manager_tx()
.send(CommManagerEvent::Message(id_, CommMsg::Close))?;
Console::get()
.get_comm_manager_tx()
.send(CommManagerEvent::Message(id, CommMsg::Close))?;

Ok(R_NilValue)
}

#[harp::register]
pub unsafe extern "C-unwind" fn ps_connection_updated(id: SEXP) -> Result<SEXP, anyhow::Error> {
let main = RMain::get();
let comm_id: String = RObject::view(id).to::<String>()?;

let event = ConnectionsFrontendEvent::Update;

main.get_comm_manager_tx().send(CommManagerEvent::Message(
comm_id,
CommMsg::Data(serde_json::to_value(event)?),
))?;
Console::get()
.get_comm_manager_tx()
.send(CommManagerEvent::Message(
comm_id,
CommMsg::Data(serde_json::to_value(event)?),
))?;

Ok(R_NilValue)
}

#[harp::register]
pub unsafe extern "C-unwind" fn ps_connection_focus(id: SEXP) -> Result<SEXP, anyhow::Error> {
if !RMain::is_initialized() {
if !Console::is_initialized() {
return Ok(R_NilValue);
}

let main = RMain::get();
let comm_id: String = RObject::view(id).to::<String>()?;

let event = ConnectionsFrontendEvent::Focus;

main.get_comm_manager_tx().send(CommManagerEvent::Message(
comm_id,
CommMsg::Data(serde_json::to_value(event)?),
))?;
Console::get()
.get_comm_manager_tx()
.send(CommManagerEvent::Message(
comm_id,
CommMsg::Data(serde_json::to_value(event)?),
))?;

Ok(R_NilValue)
}
Loading
Loading