diff --git a/background.html b/background.html index 0d7df041..897c12c9 100644 --- a/background.html +++ b/background.html @@ -541,6 +541,7 @@ + diff --git a/js/background.js b/js/background.js index a893a8d6..b1a74221 100644 --- a/js/background.js +++ b/js/background.js @@ -87,8 +87,9 @@ openInbox(); } + WallClockListener.init(); RotateSignedPreKeyListener.init(); - ExpiringMessagesListener.update(); + ExpiringMessagesListener.init(); }); window.getSyncRequest = function() { diff --git a/js/expiring_messages.js b/js/expiring_messages.js index 096d0dfb..0d96b5a6 100644 --- a/js/expiring_messages.js +++ b/js/expiring_messages.js @@ -37,6 +37,10 @@ } window.ExpiringMessagesListener = { + init: function() { + checkExpiringMessages(); + window.events.on('timetravel', checkExpiringMessages); + }, update: checkExpiringMessages }; diff --git a/js/rotate_signed_prekey_listener.js b/js/rotate_signed_prekey_listener.js index aab636ff..d39349b7 100644 --- a/js/rotate_signed_prekey_listener.js +++ b/js/rotate_signed_prekey_listener.js @@ -53,6 +53,11 @@ scheduleNextRotation(); setTimeoutForNextRun(); }); + window.events.on('timetravel', function() { + if (Whisper.Registration.isDone()) { + setTimeoutForNextRun(); + } + }); } }; }()); diff --git a/js/wall_clock_listener.js b/js/wall_clock_listener.js new file mode 100644 index 00000000..cf25da58 --- /dev/null +++ b/js/wall_clock_listener.js @@ -0,0 +1,25 @@ +/* + * vim: ts=4:sw=4:expandtab + */ + +;(function () { + 'use strict'; + + var lastTime; + var interval = 1000; + function checkTime() { + var currentTime = Date.now(); + if (currentTime > (lastTime + interval * 2)) { + console.log('time travel detected!'); + window.events.trigger('timetravel'); + } + lastTime = currentTime; + } + + window.WallClockListener = { + init: function() { + lastTime = Date.now(); + setInterval(checkTime, 1000); + } + }; +}());