diff --git a/xwords4/wasm/main.c b/xwords4/wasm/main.c index 09e60c2a2..fb97d53ce 100644 --- a/xwords4/wasm/main.c +++ b/xwords4/wasm/main.c @@ -569,6 +569,14 @@ updateScreen( Globals* globals, bool doSave ) } } +static void +doExit( Globals* globals ) +{ + call_alert( "Control passed to another tab" ); + XP_MEMSET( globals, 0, sizeof(*globals) ); /* stop everything :-) */ + // emscripten_cancel_main_loop(); <-- does nothing +} + static void looper( void* closure ) { @@ -605,6 +613,8 @@ button( void* closure, const char* msg ) } else if ( 0 == strcmp(msg, "vals") ) { globals->cp.tvType = (globals->cp.tvType + 1) % TVT_N_ENTRIES; draw = board_prefsChanged( board, &globals->cp ); + } else if ( 0 == strcmp(msg, "exit") ) { + doExit( globals ); } if ( draw ) { diff --git a/xwords4/wasm/shell_minimal.html b/xwords4/wasm/shell_minimal.html index 909a379cf..7b4f9dea1 100644 --- a/xwords4/wasm/shell_minimal.html +++ b/xwords4/wasm/shell_minimal.html @@ -55,6 +55,7 @@ position: absolute; text-align: left; z-index: 10000; + white-space: pre-wrap; left: 33%; top: 250px; width: 33%; diff --git a/xwords4/wasm/xwutils.js b/xwords4/wasm/xwutils.js index 4decd42fc..6f2b6ff5f 100644 --- a/xwords4/wasm/xwutils.js +++ b/xwords4/wasm/xwutils.js @@ -16,7 +16,17 @@ function callButton(obj) { } function onHaveDevID(closure, devid) { - console.log('got ' + devid); + // Set a unique tag so we know if somebody comes along later + let tabID = Math.random(); + localStorage.setItem('tabID', tabID); + window.addEventListener('storage', function () { + newTabID = localStorage.getItem('tabID'); + if ( newTabID != tabID ) { + state.client.disconnect(); + Module.ccall('button', null, ['number', 'string'], [state.closure, 'exit']); + } + } ); + state.closure = closure; document.getElementById("mqtt_span").textContent=devid;