Skip to content

Commit

Permalink
new reload hack without firefox issue
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Sep 3, 2021
1 parent 0c8c215 commit df86c75
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions nicegui/nicegui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
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 = () => { setTimeout(location.reload.bind(location), 100); return false; };
</script>
''' # 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
3 changes: 2 additions & 1 deletion nicegui/static/templates/js/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ function send_to_server(e, event_type, debug_flag) {
}
if (use_websockets) {
if (web_socket_closed) {
window.location.reload();
let ok_to_reload = confirm('Page needs to be reloaded, click OK to reload');
if (ok_to_reload) window.location.reload();
return;
}
if (websocket_ready) {
Expand Down
6 changes: 4 additions & 2 deletions nicegui/static/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@

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

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

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

0 comments on commit df86c75

Please sign in to comment.