rstudio / rstudioapi

Safely access RStudio's API (when available)
http://rstudio.github.io/rstudioapi
Other
168 stars 35 forks source link

addTheme() does not resolve bit.ly links #136

Open DesiQuintans opened 5 years ago

DesiQuintans commented 5 years ago

I'm not sure if this is within your control, but reporting it anyway. I have tried making a short bit.ly link for people to install my theme from a GitHub release, but installing from the short URL returns the error:

Invalid path http://bit.ly/pebble-safe-dark. Please supply a path or URL to an .rstheme or .tmtheme file to add.

Code below.

# This works
rstudioapi::addTheme("https://github.com/DesiQuintans/Pebble-safe/releases/download/1.0.0/Pebble-Safe_Dark.rstheme", apply = TRUE, force = TRUE)

# This short URL does not work
rstudioapi::addTheme("http://bit.ly/pebble-safe-dark", apply = TRUE, force = TRUE)

# But the short URL does eventually resolve to the .rsTheme if you access it with a browser.
kevinushey commented 5 years ago

Looks like we could fix this just by re-arranging the code here, and forcing a .rstheme extension on the downloaded object:

https://github.com/rstudio/rstudioapi/blob/f4418fc01a139daf1cbfa2d64e30004f0e4d537a/R/themes.R#L50-L69

DesiQuintans commented 5 years ago

An interesting other unexpected behaviour that's related to your potential fix. Trying to get people to install from a URL that ends with rsTheme or tmTheme but isn't actually the proper file format makes RStudio install a completely invalid file that tries to be a theme but fails.

For example, trying to get people to install from the GitHub repo itself (obviously a bad idea, but roll with it):

https://github.com/DesiQuintans/Pebble-safe/blob/master/Pebble-Safe_Dark.rstheme

Because this URL leads to another GitHub page, the HTML of that page gets downloaded, saved as Pebble-Safe_Dark.rstheme, and RStudio tries to use it as the theme. It correctly sets the editor background colour but fails at everything else.