Desktop
System notifications
Show native toast notifications with click actions, buttons and reply fields on Windows and Linux.
Show a toast from Java. It uses WinRT on Windows and the desktop's notification service on Linux. Available since 0.3.0.
From Java
app.notify(Notification.of("Export finished", "report.pdf is ready")
.withOnClick(() -> window.focus())
.withButton("Open", () -> open()) // up to 5 buttons
.withReply("Send", "Reply", text -> send(text))) // a text field: Windows only
.thenAccept(shown -> { /* false: the system did not show it */ });Callbacks run on the UI thread while the app runs. To skip a toast while the user is already in your window, check window.isFocused() (since 0.3.1).
Platform notes
- On Windows the first call registers your
appIdas the display name underHKCU\Software\Classes\AppUserModelId(nothing is installed). The future isfalseif the user turned notifications off. - On Linux the future is
falsewhen there is no notification service.
From the page
To let trusted pages do it, call window.enableNotifications(app) before the page loads, then:
await jolt.notify(title, body, {
onclick,
buttons: [{ label, onclick }],
reply: { label, placeholder, onreply }
});At most 5 notifications per 10 seconds per window.