Skip to content

Commit

Permalink
add body keyword to Window
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Dec 30, 2022
1 parent 5176c9e commit 4627d2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,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(); async=false)
function Window(a::Shell, opts::AbstractDict = Dict(); async=false, body=nothing)
# 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 = haskey(opts, :url) ?
Window(raw_window(a, opts), a, nothing, nothing) :
Window(a, Page(), opts, async=async)
Window(a, Page(), opts; async=async)
isnothing(body) || body!(window, body)
return window
end

function Window(a::Shell, content::Page, opts::AbstractDict = Dict(); async=false)
function Window(a::Shell, content::Page, opts::AbstractDict = Dict(); async=false, body=nothing)
id, callback_cond = Blink.callback!()
url = Blink.localurl(content) * "?callback=$id"

Expand All @@ -72,6 +74,8 @@ function Window(a::Shell, content::Page, opts::AbstractDict = Dict(); async=fals
wait(w)
end

isnothing(body) || body!(w, body)

return w
end

Expand Down
3 changes: 1 addition & 2 deletions test/webio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ end
end

@testset "button click" begin
w = Window(Dict(:show => false))
scope = Scope()
obs = Observable(scope, "obs", false)
obschannel = Channel(1)
Expand All @@ -47,7 +46,7 @@ end
end
)
))
body!(w, scope)
w = Window(Dict(:show => false); body=scope)

# Sleep to allow WebIO scope to mount in Electron
sleep(0.25)
Expand Down

0 comments on commit 4627d2b

Please sign in to comment.