Skip to content

Commit

Permalink
fix reload without confirmation dialog by modifying static justpy files
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Sep 3, 2021
1 parent 35a6e74 commit 0c8c215
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion nicegui/nicegui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
wp = jp.QuasarPage(delete_flag=False, title=Ui.config.title, favicon=Ui.config.favicon)
wp.tailwind = True # use Tailwind classes instead of Quasars
wp.css = HtmlFormatter().get_style_defs('.codehilite')
wp.head_html += '<script>confirm = (text) => console.log(text);</script>\n' # avoid confirmation dialog for reload

main = jp.Div(a=wp, classes='q-ma-md column items-start', style='row-gap: 1em')
main.add_page(wp)
Expand Down
5 changes: 2 additions & 3 deletions nicegui/static/templates/js/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ function send_to_server(e, event_type, debug_flag) {
}
if (use_websockets) {
if (web_socket_closed) {
let ok_to_reload = confirm('Page needs to be reloaded, click OK to reload');
if (ok_to_reload) window.location.reload();
window.location.reload();
return;
}
if (websocket_ready) {
Expand Down Expand Up @@ -174,4 +173,4 @@ function send_to_server(e, event_type, debug_flag) {
}
}

// {% endraw %}
// {% endraw %}
6 changes: 2 additions & 4 deletions nicegui/static/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@

socket.addEventListener('error', function (event) {
console.log('Websocket closed');
let ok_to_reload = confirm('Page needs to be reloaded, click OK to reload');
if (ok_to_reload) window.location.reload()
window.location.reload()
});

var web_socket_closed = false;
socket.addEventListener('close', function (event) {
console.log('Websocket closed');
web_socket_closed = true;
let ok_to_reload = confirm('Page needs to be reloaded, click OK to reload');
if (ok_to_reload) window.location.reload()
window.location.reload()
});

socket.addEventListener('message', function (event) {
Expand Down

0 comments on commit 0c8c215

Please sign in to comment.