From 54a587d6a3ac88eb81035ffbb413d8f961fcced2 Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Mon, 17 Jan 2022 12:11:06 -0500 Subject: [PATCH] Show confirmation dialog when navigating away from UI window --- aiserver.py | 4 ++++ static/application.js | 14 ++++++++------ templates/index.html | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/aiserver.py b/aiserver.py index 4ed27799..62cc4199 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3653,6 +3653,7 @@ def checkworldinfo(txt, allowed_entries=None, allowed_folders=None, force_use_tx # Commit changes to Memory storage #==================================================================# def memsubmit(data): + emit('from_server', {'cmd': 'setinputtext', 'data': data}, broadcast=True) # Maybe check for length at some point # For now just send it to storage vars.memory = data @@ -3676,6 +3677,9 @@ def anotesubmit(data, template=""): settingschanged() vars.authornotetemplate = template + emit('from_server', {'cmd': 'setanote', 'data': vars.authornote}, broadcast=True) + emit('from_server', {'cmd': 'setanotetemplate', 'data': vars.authornotetemplate}, broadcast=True) + #==================================================================# # Assembles game data into a request to InferKit API #==================================================================# diff --git a/static/application.js b/static/application.js index 89b80acb..e8a3202f 100644 --- a/static/application.js +++ b/static/application.js @@ -806,9 +806,6 @@ function dosubmit(disallow_abort) { hideMessage(); hidegenseqs(); socket.send({'cmd': 'submit', 'allowabort': !disallow_abort, 'actionmode': adventure ? action_mode : 0, 'chatname': chatmode ? chat_name.val() : undefined, 'data': txt}); - if(memorymode) { - memorytext = input_text.val(); - } } function changemode() { @@ -1772,8 +1769,8 @@ $(document).ready(function(){ seqselcontents = $("#seqselcontents"); // Connect to SocketIO server - socket = io.connect(window.document.origin, {transports: ['polling', 'websocket']}); - + socket = io.connect(window.document.origin, {transports: ['polling', 'websocket'], closeOnBeforeunload: false}); + socket.on('from_server', function(msg) { if(msg.cmd == "connected") { // Connected to Server Actions @@ -2536,5 +2533,10 @@ $(document).ready(function(){ sendSaveAsRequest(); } }); -}); + $(window).on("beforeunload", function() { + if(gamestarted || memorytext.length > 0 || $("#anoteinput").val().length > 0 || $(".wilistitem").length > 1) { + return true; + } + }); +}); diff --git a/templates/index.html b/templates/index.html index 3c93e8ce..f4d67f83 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@ - +