Skip to content

Commit

Permalink
Disable downloading files in WASM by default to avoid triggering `C…
Browse files Browse the repository at this point in the history
…ORS` condition that will terminate the program
  • Loading branch information
dipterix committed Jan 26, 2025
1 parent a26514b commit 18823dd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changes since last CRAN release
* `2bdf8722 (HEAD -> master)` [_`dipterix`_]: Added `FileDataHandler` classes to handle drag & drop files; supported drop-in electrode coordinate files
* `4c7c6ac6 (HEAD -> master)` [_`dipterix`_]: Disable downloading files in `WASM` by default to avoid triggering `CORS` condition that will terminate the program
* `a26514bf` [_`dipterix`_]: rewrote drag & drop code so its framework can be easily extended; surface color handlers now handle measurements and annotations different, with separate storage
* `2bdf8722` [_`dipterix`_]: Added `FileDataHandler` classes to handle drag & drop files; supported drop-in electrode coordinate files
* `caf0a3ed (origin/master, origin/HEAD)` [_`dipterix`_]: `GIfTI` reader now respect the transforms if there exists a transform with target space to be the `scanner_anat`
* `a5a0b6cd` [_`dipterix`_]: Allows continuous data cube to change color map
* `af5b9c90` [_`dipterix`_]: `add_annotation` automatically compiles annotations from template if missing
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: Your Advanced 3D Brain Visualization
Version: 1.2.0.9013
Version: 1.2.0.9014
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "[email protected]", role = c("ctb", "res")),
Expand Down
8 changes: 8 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ get_os <- function(){
return('unknown')
}

download_file <- function(...) {
if( identical(get_os(), "emscripten") && !isTRUE(getOption("threeBrain.download.wasm.enabled", FALSE)) ) {
# WASM and downloading files might not work well :|
stop("WASM environment detected. Downloading external files is disabled");
}
utils::download.file(...)
}

package_installed <- function(pkgs, all = FALSE){
re <- sapply(pkgs, function(p){
system.file('', package = p) != ''
Expand Down
2 changes: 1 addition & 1 deletion R/ext_media.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ video_content <- function(path, duration = Inf, time_start = 0, asp_ratio = 16 /
on.exit({ options(oldopt) })

path <- tempfile(fileext = '.mp4')
utils::download.file(url, destfile = path)
download_file(url, destfile = path)
temp <- TRUE
} else {
is_url <- TRUE
Expand Down
4 changes: 2 additions & 2 deletions R/loaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ download_template_subject <- function(
if(file.exists(destzip)) {
unlink(destzip)
}
utils::download.file(url = url, destfile = destzip, quiet = FALSE, cacheOK = TRUE)
download_file(url = url, destfile = destzip, quiet = FALSE, cacheOK = TRUE)

sub_dir <- file.path(dir, subject_code)
# sub_dir = dir
Expand Down Expand Up @@ -238,7 +238,7 @@ available_templates <- function() {
)

res <- tryCatch({
utils::download.file(url, destfile = tf, quiet = TRUE)
download_file(url, destfile = tf, quiet = TRUE)
releases <- jsonlite::read_json(tf)
res <- releases[vapply(releases, function(rel) {
isTRUE(rel$tag_name == "1.0.0")
Expand Down
8 changes: 6 additions & 2 deletions R/threeBrain.R
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,12 @@ threeBrain <- function(

for( ii in seq_along(annotation_types) ) {

annotation_type <- annotation_types[[ ii ]]
brain$add_annotation( annotation_type, surface_type = "pial" )
# This might lead to downloading templates, which will trigger warnings
# However, webr doesn't like it when warning exists
suppressWarnings({
annotation_type <- annotation_types[[ ii ]]
brain$add_annotation( annotation_type, surface_type = "pial" )
})

}

Expand Down

0 comments on commit 18823dd

Please sign in to comment.