Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadurl blocks until page is loaded #43

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/AtomShell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ function arg(name) {
}

var handlers = {};
var connection = {};

handlers.eval = function(data, c) {
connection = c; // Make the connection available to the code to be eval'ed
var result = eval(data.code);
if (data.callback) {
result == undefined && (result = null);
Expand All @@ -35,7 +37,6 @@ var server = net.createServer(function(c) { //'connection' listener
buffer[0] += lines[0];
for (var i = 1; i < lines.length; i++)
buffer[buffer.length] = lines[i];

while (buffer.length > 1)
line(buffer.shift());
});
Expand Down Expand Up @@ -71,13 +72,31 @@ function createWindow(opts) {
win.loadURL(opts.url);
}

win.webContents.on('dom-ready', function(opts) {
var browserOpts = opts.sender.browserWindowOptions;
if (browserOpts.hasOwnProperty("callback")) {
var callback = browserOpts.callback;
var result = {type: 'callback', callback: callback, result: callback};
connection.write(JSON.stringify(result));
}
});

win.on('closed', function() {
delete windows[win.id];
});

return win.id;
}

function load(opts) {
var win = windows[opts.id];
win.loadURL(opts.url);
win.webContents.on("dom-ready", function() {
var result = {type: 'callback', callback: opts.callback, result: opts.callback};
connection.write(JSON.stringify(result));
});
}

function evalwith(obj, code) {
return (function() {
return eval(code);
Expand Down
18 changes: 14 additions & 4 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ..Blink
import Blink: js, jsstring, id
import Blink: js, jsstring, id, callback!
import Base: position, size, close

export Window, flashframe, shell, progress, title,
Expand All @@ -21,7 +21,13 @@ const window_defaults = @d(:url => "about:blank",
"use-content-size" => true,
:icon => Pkg.dir("Blink", "deps", "julia.png"))

raw_window(a::Shell, opts) = @js a createWindow($(merge(window_defaults, opts)))
function raw_window(a::Shell, opts)
id,cb = callback!()
opts["callback"] = id
winid = @js a createWindow($(merge(window_defaults, opts)))
wait(cb,10,msg = "createWindow timed out")
winid
end

function Window(a::Shell, opts::Associative = Dict())
return haskey(opts, :url) ?
Expand Down Expand Up @@ -93,8 +99,12 @@ floating(win::Window, flag) =
floating(win::Window) =
@dot win isAlwaysOnTop()

loadurl(win::Window, url) =
@dot win loadURL($url)
function loadurl(win::Window, url)
id,cb = callback!()
opts = @d(:callback=>id,:id=>win.id,:url=>url)
@js_ shell(win) load($opts)
wait(cb,5,msg="Loading URL timed out")
end

loadfile(win::Window, f) =
loadurl(win, "file://$f")
Expand Down