Pop-out windows
Let a page ask for another window while your Java code decides, with keys to avoid duplicates and broadcasts between windows.
Available since 0.3.0. app.createWindow(...) can be called as often as you like (on the UI thread), and app.windows() lists the windows that are open. A page can ask for another window, for example an email shown in its own window, but it never opens one itself: your Java code decides.
Allow the opener
main.enableOpenWindow(app, request -> { // UI thread, once per request
if (!request.path().startsWith("/message/")) return null; // null refuses (the page gets false)
WebWindow popout = request.createWindow(app);
popout.loadResources(resources, router,
ResourceOptions.defaults().withStartPath(request.path()));
return popout;
});Ask from the page
const opened = await jolt.openWindow("/message/42", { key: "message-42", title: "Re: lunch", width: 900, height: 700 });
// true: a window opened, or the one with that key was brought to the front. false: the app refused.- key stops duplicates: asking again for the same key focuses the window that is already open (your opener is not called).
- path must be an address inside the app (one leading
/);//host,https://...and the like are rejected. - The window you return gets
jolt.openWindowandjolt.broadcasttoo, with the same opener. Refuse inside the opener (look atrequest.opener()) if pop-outs must not open more windows. At most 10 requests per window per 10 seconds. - The request is yours to check:
path,key,titleand the sizes come from the page.request.options()has no owner; use.withOwner(request.opener())if the pop-out should stay in front of its window and close with it.
Talking between windows
jolt.broadcast(text) goes to every other window that has called enableOpenWindow, and const stop = jolt.onBroadcast(text => ...) receives it. A window never gets its own broadcasts, and text is limited to 16 K characters. To refresh a message list after a reply, broadcast a short event such as "message-42:read" and let each window fetch what it needs.
From Java: window.isFocused() tells whether the window is the one the user is working in, window.focus() brings a window to the front, and WindowOptions.withOwner(window) makes a window belong to another one.