1
2
3###
4# These methods could be removed if shiny were able to be imported.
5# * `shiny::in_devmode()`
6# * `shiny::get_devmode_option()`
7###
8
9get_precompiled_option <- function(
10  name = "bslib.precompiled",
11  default = TRUE,
12  devmode_default = FALSE,
13  devmode_message = "Disabling the use of bslib precompiled themes. To be able to use precompiled themes, call `options(bslib.precompiled = TRUE)`"
14) {
15  get_shiny_devmode_option(
16    name,
17    default = default,
18    devmode_default = devmode_default,
19    devmode_message = devmode_message
20  )
21}
22
23
24in_shiny_devmode <- function() {
25  isTRUE(getOption("shiny.devmode", FALSE)) &&
26    !identical(Sys.getenv("TESTTHAT"), "true")
27}
28
29#' @importFrom rlang missing_arg is_missing maybe_missing
30get_shiny_devmode_option <- function(
31  name,
32  default = NULL,
33  devmode_default = missing_arg(),
34  devmode_message = missing_arg()
35) {
36
37  if (!in_shiny_devmode()) {
38    # Dev Mode disabled, act like `getOption()`
39    return(getOption(name, default = default))
40  }
41
42  # Dev Mode enabled, update the default value for `getOption()`
43  getOption(name, default = {
44    # Notify developer
45    if (
46      !is_missing(devmode_message) &&
47      !is.null(devmode_message) &&
48      getOption("shiny.devmode.verbose", TRUE)
49    ) {
50      devmode_message <- paste0("shiny devmode - ", devmode_message)
51      rlang::inform(
52        message = devmode_message,
53        .frequency = "regularly",
54        .frequency_id = devmode_message,
55        .file = stderr()
56      )
57    }
58
59    # Return Dev Mode default value `devmode_default`
60    maybe_missing(devmode_default, default)
61  })
62}
63