/
openbrowserwindow.jl
82 lines (77 loc) · 2.32 KB
/
openbrowserwindow.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##### Beginning of file
# Parts of this file are based on:
# 1. https://github.com/JuliaPlots/Plots.jl/blob/master/src/backends/web.jl
# 2. https://github.com/JuliaGraphics/Luxor.jl/blob/master/src/Luxor.jl
import FileIO
"""
"""
function open_browser_window(filename::Void, a::Associative = ENV)
Compat.@warn("no filename to open")
return filename
end
"""
"""
function open_browser_window(filename::AbstractString, a::Associative = ENV)
extension = filename_extension(filename)
is_svg_file = extension == ".svg"
is_png_file = extension == ".png"
is_svg_or_png_file = is_svg_file || is_png_file
is_ijulia = isdefined(Main, :IJulia) && Main.IJulia.inited
if is_ijulia && is_svg_or_png_file
Main.IJulia.clear_output(true)
if is_svg_file
open(filename) do f
display(
"image/svg+xml",
readstring(f),
)
end
elseif is_png_file
# We use Base.invokelatest to avoid world age errors
Base.invokelatest(
display,
"image/png",
FileIO.load(filename),
)
end
elseif (is_make_examples(a)) ||
(is_make_docs(a)) ||
(is_runtests(a) && !open_plots_during_tests(a))
Compat.@debug(
string(
"Skipping opening file: ",
filename,
)
)
else
Compat.@debug(string("Opening file ",filename,))
if is_apple()
try
run(`open $(filename)`)
catch e
Compat.@warn(string("ignoring error: ", e))
end
elseif is_linux() || is_bsd()
try
run(`xdg-open $(filename)`)
catch e
Compat.@warn(string("ignoring error: ", e))
end
elseif is_windows()
try
run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`)
catch e
Compat.@warn(string("ignoring error: ", e))
end
else
Compat.@warn(
string(
"unknown operating system; could not open file ",
filename,
)
)
end
end
return filename
end
##### End of file