Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jennybc
Copy link
Member

@jennybc jennybc commented Jul 19, 2025

Comment on lines -51 to -52
// TODO: What is the right thing to do outside of Positron when
// `options(browser =)` is called? Right now we error.
Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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? 🤔

Copy link
Member Author

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.

~/tmp % jupyter console --kernel=ark
Jupyter console 6.6.3


R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.


In [1]: browseURL("~/tmp")
  2025-07-21T21:35:02.025887Z ERROR  No help port is available to check if '~/tmp' is a help url. Is the help comm open?
    at crates/ark/src/interface.rs:2032

  2025-07-21T21:35:02.026935Z ERROR  Failed to browse url due to: UI comm not connected, can't run `open_with_system`.
    at crates/ark/src/browser.rs:22


In [2]: getOption("browser")
Out[2]:
function(url) {
    .ps.Call("ps_browse_url", as.character(url))
}
<environment: 0x11fd5bc70>

Copy link
Member Author

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.

Comment on lines -54 to -62
// 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."))?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was basically duplicated in ps_ui_show_url() so now they share logic via the send_show_url_event() helper.

// 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())?;
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Comment on lines -51 to -52
// TODO: What is the right thing to do outside of Positron when
// `options(browser =)` is called? Right now we error.
Copy link
Contributor

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?

Ok(R_NilValue)
}

pub fn send_open_with_system_default_event(path: &str) -> anyhow::Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align with event name?

Suggested change
pub fn send_open_with_system_default_event(path: &str) -> anyhow::Result<()> {
pub fn send_open_with_system_event(path: &str) -> anyhow::Result<()> {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. I'm implementing in a local commit, because I need to use "Rename Symbol" to also hit the call sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants