Skip to content

Commit

Permalink
loadurl blocks until page is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Forgy authored and Eric Forgy committed Dec 29, 2015
1 parent 022ceb5 commit a799337
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/AtomShell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ handlers.eval = function(data, c) {
}
}

var connection = {};

var server = net.createServer(function(c) { //'connection' listener
connection = c;
c.on('end', function() {
app.quit();
});
Expand Down Expand Up @@ -78,6 +81,15 @@ function createWindow(opts) {
return win.id;
}

function load(opts) {
var win = windows[opts.id];
win.loadUrl(opts.url);
win.webContents.on("dom-ready", function() {
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
10 changes: 7 additions & 3 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

export Window, flashframe, shell, progress, title,
Expand Down Expand Up @@ -93,8 +93,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

0 comments on commit a799337

Please sign in to comment.