Skip to content

Commit f7deecf

Browse files
authored
Merge pull request #1024 from posit-dev/task/rename-interface
Rename `interface.rs` to `console.rs` and `RMain` to `Console`
2 parents ca75dbb + b655078 commit f7deecf

40 files changed

+586
-650
lines changed

crates/ark/src/browser.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use harp::utils::r_normalize_path;
1010
use libr::Rf_ScalarLogical;
1111
use libr::SEXP;
1212

13+
use crate::console::Console;
1314
use crate::help::message::HelpEvent;
1415
use crate::help::message::ShowHelpUrlKind;
1516
use crate::help::message::ShowHelpUrlParams;
16-
use crate::interface::RMain;
1717
use crate::ui::events::send_open_with_system_event;
1818
use crate::ui::events::send_show_url_event;
1919

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

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

3232
fn handle_help_url(url: String) -> anyhow::Result<()> {
33-
RMain::with(|main| {
34-
let event = HelpEvent::ShowHelpUrl(ShowHelpUrlParams {
35-
url,
36-
kind: ShowHelpUrlKind::HelpProxy,
37-
});
38-
main.send_help_event(event)
39-
})
33+
let event = HelpEvent::ShowHelpUrl(ShowHelpUrlParams {
34+
url,
35+
kind: ShowHelpUrlKind::HelpProxy,
36+
});
37+
Console::get().send_help_event(event)
4038
}
4139

4240
unsafe fn ps_browse_url_impl(url: SEXP) -> anyhow::Result<SEXP> {

crates/ark/src/connections/r_connection.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use stdext::spawn;
3636
use stdext::unwrap;
3737
use uuid::Uuid;
3838

39-
use crate::interface::RMain;
39+
use crate::console::Console;
4040
use crate::modules::ARK_ENVS;
4141
use crate::r_task;
4242

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

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

318-
let main = RMain::get();
318+
let console = Console::get();
319319

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

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

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

341-
main.get_comm_manager_tx()
342-
.send(CommManagerEvent::Message(id_, CommMsg::Close))?;
340+
Console::get()
341+
.get_comm_manager_tx()
342+
.send(CommManagerEvent::Message(id, CommMsg::Close))?;
343343

344344
Ok(R_NilValue)
345345
}
346346

347347
#[harp::register]
348348
pub unsafe extern "C-unwind" fn ps_connection_updated(id: SEXP) -> Result<SEXP, anyhow::Error> {
349-
let main = RMain::get();
350349
let comm_id: String = RObject::view(id).to::<String>()?;
351-
352350
let event = ConnectionsFrontendEvent::Update;
353351

354-
main.get_comm_manager_tx().send(CommManagerEvent::Message(
355-
comm_id,
356-
CommMsg::Data(serde_json::to_value(event)?),
357-
))?;
352+
Console::get()
353+
.get_comm_manager_tx()
354+
.send(CommManagerEvent::Message(
355+
comm_id,
356+
CommMsg::Data(serde_json::to_value(event)?),
357+
))?;
358358

359359
Ok(R_NilValue)
360360
}
361361

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

368-
let main = RMain::get();
369368
let comm_id: String = RObject::view(id).to::<String>()?;
370-
371369
let event = ConnectionsFrontendEvent::Focus;
372370

373-
main.get_comm_manager_tx().send(CommManagerEvent::Message(
374-
comm_id,
375-
CommMsg::Data(serde_json::to_value(event)?),
376-
))?;
371+
Console::get()
372+
.get_comm_manager_tx()
373+
.send(CommManagerEvent::Message(
374+
comm_id,
375+
CommMsg::Data(serde_json::to_value(event)?),
376+
))?;
377377

378378
Ok(R_NilValue)
379379
}

0 commit comments

Comments
 (0)