@@ -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 \U 1F389" ,
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+ }
0 commit comments