-
Notifications
You must be signed in to change notification settings - Fork 17
Use new UI event to send a putative path to the system for opening #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,16 @@ | |
// | ||
// | ||
|
||
use amalthea::comm::ui_comm::ShowUrlParams; | ||
use amalthea::comm::ui_comm::UiFrontendEvent; | ||
use harp::object::RObject; | ||
use harp::utils::r_normalize_path; | ||
use libr::Rf_ScalarLogical; | ||
use libr::SEXP; | ||
|
||
use crate::help::message::HelpEvent; | ||
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; | ||
|
||
#[harp::register] | ||
pub unsafe extern "C-unwind" fn ps_browse_url(url: SEXP) -> anyhow::Result<SEXP> { | ||
|
@@ -35,33 +36,32 @@ fn handle_help_url(url: String) -> anyhow::Result<()> { | |
} | ||
|
||
unsafe fn ps_browse_url_impl(url: SEXP) -> anyhow::Result<SEXP> { | ||
// Extract URL. | ||
let url = RObject::view(url).to::<String>()?; | ||
let _span = tracing::trace_span!("browseURL", url = %url).entered(); | ||
// Extract URL string for analysis | ||
let url_string = RObject::view(url).to::<String>()?; | ||
let _span = tracing::trace_span!("browseURL", url = %url_string).entered(); | ||
|
||
// Handle help server requests. | ||
if is_help_url(&url) { | ||
if is_help_url(&url_string) { | ||
log::trace!("Help is handling URL"); | ||
handle_help_url(url)?; | ||
handle_help_url(url_string)?; | ||
return Ok(Rf_ScalarLogical(1)); | ||
} else { | ||
log::trace!("Help is not handling URL"); | ||
} | ||
|
||
// TODO: What is the right thing to do outside of Positron when | ||
// `options(browser =)` is called? Right now we error. | ||
|
||
// For all other URLs, create a ShowUrl event and send it to the main | ||
// thread; Positron will handle it. | ||
let params = ShowUrlParams { url }; | ||
let event = UiFrontendEvent::ShowUrl(params); | ||
|
||
let main = RMain::get(); | ||
let ui_comm_tx = main | ||
.get_ui_comm_tx() | ||
.ok_or_else(|| anyhow::anyhow!("UI comm not connected."))?; | ||
Comment on lines
-54
to
-62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was basically duplicated in |
||
|
||
ui_comm_tx.send_event(event); | ||
// Handle web URLs | ||
if is_web_url(&url_string) { | ||
log::trace!("Handling web URL"); | ||
send_show_url_event(&url_string)?; | ||
return Ok(Rf_ScalarLogical(1)); | ||
} | ||
|
||
// This is probably a file path? Send to the front end and ask for system | ||
// default opener. | ||
log::trace!("Treating as file path and asking system to open"); | ||
let path = r_normalize_path(url.into())?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The opener service on the Positron side expects a resolved path, so it's important to normalize on the backend. |
||
send_open_with_system_event(&path)?; | ||
Ok(Rf_ScalarLogical(1)) | ||
} | ||
|
||
fn is_web_url(url: &str) -> bool { | ||
url.starts_with("http://") || url.starts_with("https://") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone want me to hang onto this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, we should only inject this option when launched from Positron. Probably an easy fix if you want to do it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really follow how ark would hit
ps_browse_url_impl()
outside of Positron. Because I assume it works like this:In Positron, ark takes charge of the
"browser"
option and that eventually routes through here.But outside of Positron, ark would presumably have the default implementation of
"browser"
, yeah?Is the claim that ark would error outside of Positron actually true or true anymore? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I am wrong. Why do we set an option like
"browser"
in ark, but outside of Positron? This feels like it might be out of scope for this PR (a bigger problem). In which case I should just retain the comment and move on.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already tracking this problem here: #588.
So I'm going to merge this once the Positron side is approved.