Skip to content

Commit

Permalink
Change Window() async option to pure julia kwarg.
Browse files Browse the repository at this point in the history
Change `:async => false` opt to `async=false` keyword argument.
  • Loading branch information
NHDaly committed Sep 22, 2018
1 parent c8abde2 commit d120a31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ const window_defaults = @d(:url => "about:blank",

raw_window(a::Electron, opts) = @js a createWindow($(merge(window_defaults, opts)))

function Window(a::Shell, opts::AbstractDict = Dict())
function Window(a::Shell, opts::AbstractDict = Dict(); async=true)
# TODO: Custom urls don't support async b/c don't load Blink.js. (Same as https://github.com/JunoLab/Blink.jl/issues/150)
return haskey(opts, :url) ?
Window(raw_window(a, opts), a, nothing) :
Window(a, Page(), opts)
Window(a, Page(), opts, async=async)
end

function Window(a::Shell, content::Page, opts::AbstractDict = Dict())
function Window(a::Shell, content::Page, opts::AbstractDict = Dict(); async=true)
url = Blink.localurl(content)
is_async(opts) = get(opts, :async, true) # Async default: true
callback = !is_async(opts)
if callback
if !async
# Send the callback id as a query param in the url.
id, cond = Blink.callback!()
url *= "?callback=$id"
Expand All @@ -43,7 +42,7 @@ function Window(a::Shell, content::Page, opts::AbstractDict = Dict())
opts = merge(opts, Dict(:url => url))
w = Window(raw_window(a, opts), a, content)
# If callback is requested, wait until the window has finished loading.
if callback
if !async
val = wait(cond)
if isa(val, AbstractDict) && get(val, "type", "") == "error"
err = JSError(get(val, "name", "unknown"), get(val, "message", "blank"))
Expand All @@ -53,7 +52,7 @@ function Window(a::Shell, content::Page, opts::AbstractDict = Dict())
return w
end

Window(args...) = Window(shell(), args...)
Window(args...; kwargs...) = Window(shell(), args...; kwargs...)

dot(a::Electron, win::Integer, code; callback = true) =
js(a, :(withwin($(win), $(jsstring(code)...))),
Expand Down
2 changes: 1 addition & 1 deletion test/AtomShell/window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Blink
using Test

@testset "size Tests" begin
w = Window(Blink.@d(:show => false, :width=>150, :height=>100, :async=>false));
w = Window(Blink.@d(:show => false, :width=>150, :height=>100), async=false);
@test size(w) == [150,100]

size(w, 200,200)
Expand Down
8 changes: 4 additions & 4 deletions test/content/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Blink
using Test

@testset "content! Tests" begin
w = Window(Blink.@d(:show => false, :async=>false));
w = Window(Blink.@d(:show => false), async=false);
body!(w, "", async=false);
@test (@js w document.querySelector("body").innerHTML) == ""

Expand All @@ -20,22 +20,22 @@ using Test
fadeTestHtml = """<script>var testJS = "test";</script><div id="d">hi world</div>"""
@testset "Fade True" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false));
w = Window(Blink.@d(:show => false), async=false);

body!(w, fadeTestHtml; fade=true, async=false);
@test (@js w testJS) == "test"
end
@testset "Fade False" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false, :async=>false));
w = Window(Blink.@d(:show => false), async=false);

body!(w, fadeTestHtml; fade=false, async=false);
@test (@js w testJS) == "test"
end
end

@testset "Sync/Async content reload tests" begin
w = Window(Blink.@d(:show => false, :async=>false));
w = Window(Blink.@d(:show => false), async=false);
sleep_content(seconds) = """
<script>
function spinsleep(ms) {
Expand Down

0 comments on commit d120a31

Please sign in to comment.