ソースを参照

new reload hack without firefox issue

Falko Schindler 3 年 前
コミット
df86c759c3

+ 5 - 0
nicegui/nicegui.py

@@ -11,6 +11,11 @@ from .timer import Timer
 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)

+ 2 - 1
nicegui/static/templates/js/event_handler.js

@@ -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) {

+ 4 - 2
nicegui/static/templates/main.html

@@ -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) {