diff --git a/aiserver.py b/aiserver.py index 419b5930..84fc1fae 100644 --- a/aiserver.py +++ b/aiserver.py @@ -2068,7 +2068,7 @@ def index(): if 'new_ui' in request.args: return render_template('index_new.html', hide_ai_menu=args.noaimenu) else: - return render_template('index.html', hide_ai_menu=args.noaimenu) + return render_template('index.html', hide_ai_menu=args.noaimenu, flaskwebgui=vars.flaskwebgui) @app.route('/favicon.ico') def favicon(): return send_from_directory(app.root_path, @@ -5913,7 +5913,7 @@ if __name__ == "__main__": from flaskwebgui import FlaskUI vars.serverstarted = True vars.flaskwebgui = True - FlaskUI(app, socketio=socketio, start_server="flask-socketio", maximized=True, close_server_on_exit=False).run() + FlaskUI(app, socketio=socketio, start_server="flask-socketio", maximized=True, close_server_on_exit=True).run() except: import webbrowser webbrowser.open_new('http://localhost:{0}'.format(port)) diff --git a/static/flask_web_gui.js b/static/flask_web_gui.js new file mode 100644 index 00000000..8571d84f --- /dev/null +++ b/static/flask_web_gui.js @@ -0,0 +1,20 @@ +async function getRequest(url='') { + const response = await fetch(url, { + method: 'GET', + cache: 'no-cache' + }) +} + +document.addEventListener('DOMContentLoaded', function() { + +let url = document.location +let route = "/flaskwebgui-keep-server-alive"; +let interval_request = 3 * 1000; //sec + +function keep_alive_server(){ + getRequest(url + route); +} + +setInterval(keep_alive_server, interval_request); + +}) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 0d77fd49..3f3aa876 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,6 +19,9 @@ + {% if flaskwebgui %} + + {% endif %}