mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
add callback called when window regains focus
I need to redraw the canvas then, but haven't figured out yet.
This commit is contained in:
parent
fa8bcd3c2c
commit
4eede76780
2 changed files with 26 additions and 6 deletions
|
@ -161,9 +161,12 @@ EM_JS(void, call_get_string, (const char* msg, const char* dflt,
|
|||
} );
|
||||
|
||||
EM_JS(void, call_haveDevID, (void* closure, const char* devid,
|
||||
const char* gitrev, int now, StringProc proc), {
|
||||
const char* gitrev, int now,
|
||||
StringProc conflictProc,
|
||||
StringProc focussedProc ), {
|
||||
let jsgr = UTF8ToString(gitrev);
|
||||
onHaveDevID(closure, UTF8ToString(devid), jsgr, now, proc);
|
||||
onHaveDevID(closure, UTF8ToString(devid), jsgr, now,
|
||||
conflictProc, focussedProc);
|
||||
});
|
||||
|
||||
EM_JS(bool, call_mqttSend, (const char* topic, const uint8_t* ptr, int len), {
|
||||
|
@ -610,11 +613,24 @@ updateDeviceButtons( Globals* globals )
|
|||
static void
|
||||
onConflict( void* closure, const char* ignored )
|
||||
{
|
||||
Globals* globals = (Globals*)closure;
|
||||
CAST_GLOB(Globals*, globals, closure);
|
||||
call_alert( "Control passed to another tab" );
|
||||
XP_MEMSET( globals, 0, sizeof(*globals) ); /* stop everything :-) */
|
||||
}
|
||||
|
||||
static void
|
||||
onFocussed( void* closure, const char* ignored )
|
||||
{
|
||||
XP_LOGFF("Need to refresh...");
|
||||
/* This hasn't worked.... */
|
||||
/* CAST_GLOB(Globals*, globals, closure); */
|
||||
/* GameState* gs = getCurGame( globals ); */
|
||||
/* if ( !!gs ) { */
|
||||
/* board_invalAll( gs->game.board ); */
|
||||
/* updateScreen( gs, false ); */
|
||||
/* } */
|
||||
}
|
||||
|
||||
static void
|
||||
initDeviceGlobals( Globals* globals )
|
||||
{
|
||||
|
@ -647,7 +663,7 @@ initDeviceGlobals( Globals* globals )
|
|||
XP_SNPRINTF( buf, VSIZE(buf), MQTTDevID_FMT, devID );
|
||||
XP_LOGFF( "got mqtt devID: %s", buf );
|
||||
int now = dutil_getCurSeconds( globals->dutil, NULL );
|
||||
call_haveDevID( globals, buf, GITREV, now, onConflict );
|
||||
call_haveDevID( globals, buf, GITREV, now, onConflict, onFocussed );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -45,7 +45,7 @@ function registerOnce(devid, gitrev, now) {
|
|||
}
|
||||
}
|
||||
|
||||
function onHaveDevID(closure, devid, gitrev, now, proc) {
|
||||
function onHaveDevID(closure, devid, gitrev, now, noTabProc, focusProc) {
|
||||
// Set a unique tag so we know if somebody comes along later
|
||||
let tabID = Math.random();
|
||||
localStorage.setItem('tabID', tabID);
|
||||
|
@ -53,12 +53,16 @@ function onHaveDevID(closure, devid, gitrev, now, proc) {
|
|||
newTabID = localStorage.getItem('tabID');
|
||||
if ( newTabID != tabID ) {
|
||||
state.client.disconnect();
|
||||
ccallString(proc, state.closure, '');
|
||||
ccallString(noTabProc, state.closure, '');
|
||||
window.removeEventListener('storage', listener);
|
||||
}
|
||||
};
|
||||
window.addEventListener('storage', listener);
|
||||
|
||||
window.onfocus = function () {
|
||||
ccallString(focusProc, state.closure, '');
|
||||
};
|
||||
|
||||
registerOnce(devid, gitrev, now);
|
||||
|
||||
state.closure = closure;
|
||||
|
|
Loading…
Reference in a new issue