Skip to content

Commit 5333e63

Browse files
committed
Announce package updates via modal on first gadget launch
1 parent b4c58f0 commit 5333e63

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Imports:
2727
tidyr,
2828
rstudioapi,
2929
shiny,
30-
miniUI
30+
miniUI,
31+
jsonlite
3132
RoxygenNote: 6.0.1
3233
Roxygen: list(markdown = TRUE)
3334
URL: https://github.com/gadenbuie/regexplain

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ importFrom(dplyr,select)
1414
importFrom(dplyr,summarize)
1515
importFrom(rlang,.data)
1616
importFrom(utils,getFromNamespace)
17+
importFrom(utils,installed.packages)
18+
importFrom(utils,packageVersion)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Options from **Regex** tab are extended to **Output** tab as well. Colored
66
options according to group where they are applied.
7+
* Added a mechanism to announce package updates while this package is on GitHub.
8+
Only checked once per R session on the first launch of the gadget.
79

810
### 0.1.4
911

R/regex_gadget.R

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ regex_gadget <- function(text = NULL,
1010
start_page = if (is.null(text)) "Text" else "Regex") {
1111
stopifnot(requireNamespace("miniUI"), requireNamespace("shiny"))
1212

13+
update_available <- check_version()
14+
1315
# ---- UI ----
1416
ui <- miniPage(
1517
shiny::includeCSS(system.file("styles", "style.css", package = "regexplain")),
@@ -116,6 +118,33 @@ regex_gadget <- function(text = NULL,
116118

117119
# ---- Server ----
118120
server <- function(input, output, session) {
121+
if (!is.null(update_available)) {
122+
showModal(
123+
modalDialog(
124+
title = "Update Available \U1F389",
125+
easyClose = TRUE,
126+
footer = modalButton("OK"),
127+
tagList(
128+
tags$p(
129+
"Version", update_available$version, "is",
130+
tags$a(href = update_available$link,
131+
"available on GitHub.")
132+
),
133+
if ("devtools" %in% installed.packages()) tags$p(
134+
"The fastest way to update is with devtools:",
135+
tags$pre(
136+
"devtools::update_packages(\"gadenbuie/regexplain\")"
137+
)
138+
),
139+
tags$p(
140+
class = 'help-block',
141+
"This message won't be shown again during this R session."
142+
)
143+
)
144+
)
145+
)
146+
}
147+
119148
# ---- Server - Global ----
120149
rtext <- reactive({
121150
x <- if ('text_break_lines' %in% input$regex_options) {
@@ -326,3 +355,42 @@ get_pkg_namespace <- function(fn) {
326355
x
327356
}
328357

358+
#' Check if an updated version is available
359+
#'
360+
#' I included this because it can be difficult to tell if your RStudio Addins
361+
#' are up to date. I may add new features that you want but you won't hear about
362+
#' the updates. This function checks if an update is available, using GitHub
363+
#' tags. If an update is available, a modal dialog is shown when you start
364+
#' the regexplain gadget. This only happens once per R session, though, so feel
365+
#' free to ignore the message.
366+
#'
367+
#' @param gh_user GitHub user account
368+
#' @param gh_repo GitHub repo name
369+
#' @param this_version The currently installed version of the package
370+
#' @keywords internal
371+
check_version <- function(
372+
gh_user = "gadenbuie",
373+
gh_repo = "regexplain",
374+
this_version = packageVersion('regexplain')
375+
) {
376+
ok_to_check <- getOption("regexplain.no.check.version", TRUE)
377+
if (!ok_to_check) return(NULL)
378+
if (!requireNamespace('jsonlite', quietly = TRUE)) return(NULL)
379+
gh_tags <- jsonlite::fromJSON(
380+
paste0("https://api.github.com/repos/", gh_user, "/", gh_repo, "/git/refs/tags"),
381+
simplifyDataFrame = TRUE
382+
)
383+
gh_tags$tag <- sub("refs/tags/", "", gh_tags$ref, fixed = TRUE)
384+
gh_tags$version <- sub("^v\\.?", "", gh_tags$tag)
385+
if (any(gh_tags$version > this_version)) {
386+
max_version <- max(gh_tags$version)
387+
max_tag <- gh_tags$tag[gh_tags$version == max_version]
388+
options(regexplain.no.check.version = FALSE)
389+
return(
390+
list(
391+
version = max_version,
392+
link = paste("https://github.com", gh_user, gh_repo, "releases/tag", max_tag, sep = "/")
393+
)
394+
)
395+
} else return(NULL)
396+
}

R/regexplain-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#' @importFrom dplyr "%>%" mutate filter group_by summarize select
2-
#' @importFrom utils getFromNamespace
2+
#' @importFrom utils getFromNamespace installed.packages packageVersion
33
#' @keywords internal
44
"_PACKAGE"

man/check_version.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)