diff --git a/src/AtomShell/window.jl b/src/AtomShell/window.jl index f737eb3..ace914a 100644 --- a/src/AtomShell/window.jl +++ b/src/AtomShell/window.jl @@ -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" @@ -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")) @@ -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)...))), diff --git a/test/AtomShell/window.jl b/test/AtomShell/window.jl index 7033576..6286d39 100644 --- a/test/AtomShell/window.jl +++ b/test/AtomShell/window.jl @@ -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) diff --git a/test/content/api.jl b/test/content/api.jl index 0a920db..b8ade26 100644 --- a/test/content/api.jl +++ b/test/content/api.jl @@ -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) == "" @@ -20,14 +20,14 @@ using Test fadeTestHtml = """