diff --git a/script.html b/script.html
index 66adca3..cdd9f65 100644
--- a/script.html
+++ b/script.html
@@ -184,9 +184,32 @@ function wire(locked) {
photo_id: ph ? ph.value : undefined });
b.disabled = true; b.textContent = "Drawing…";
var r = await api("make_shot_image", { email: email, project_id: pid, index: idx });
- b.disabled = false;
- if (!r.ok) { b.textContent = "Try again"; showMsg("msg", r.error || "Could not make that frame."); return; }
- load();
+ if (!r.ok) {
+ b.disabled = false; b.textContent = "Try again";
+ showMsg("msg", r.error || "Could not make that frame.");
+ return;
+ }
+ // Drawing takes about half a minute and runs on the server, so the call
+ // above returns straight away. Watch the shot until the frame appears.
+ var waited = 0;
+ var tick = setInterval(async function () {
+ waited += 4;
+ var g = await api("get_project", { email: email, project_id: pid });
+ var seg = (g.ok && g.script && g.script.segments || []).filter(function (x) {
+ return parseInt(x.index, 10) === idx; })[0];
+ if (seg && seg.draw_error) {
+ clearInterval(tick);
+ b.disabled = false; b.textContent = "Try again";
+ showMsg("msg", "That frame did not draw: " + seg.draw_error);
+ return;
+ }
+ if (seg && seg.plate_url) { clearInterval(tick); load(); return; }
+ if (waited > 120) {
+ clearInterval(tick);
+ b.disabled = false; b.textContent = "Try again";
+ showMsg("msg", "That frame is taking unusually long. Try again in a moment.");
+ }
+ }, 4000);
});
});