diff --git a/js/background.js b/js/background.js index d4cbb8a2b..ed5e0667d 100644 --- a/js/background.js +++ b/js/background.js @@ -76,10 +76,26 @@ storage.fetch(); - const idleListener = new IdleDetector(); - idleListener.on('idle', (event) => { - console.log('Detected user idle:', event); + + /* eslint-enable */ + /* jshint ignore:start */ + const idleDetector = new IdleDetector(); + idleDetector.on('idle', async () => { + const results = await MessageMigration.processNext({ + BackboneMessage: Whisper.Message, + BackboneMessageCollection: Whisper.MessageCollection, + count: 3, + upgradeMessageSchema, + wrapDeferred, }); + console.log('Message schema upgrade:', results); + + if (!results.hasMore) { + idleDetector.stop(); + } + }); + /* jshint ignore:end */ + /* eslint-disable */ // We need this 'first' check because we don't want to start the app up any other time // than the first time. And storage.fetch() will cause onready() to fire. @@ -91,11 +107,11 @@ first = false; ConversationController.load().then(start, start); - idleListener.start(); + idleDetector.start(); }); Whisper.events.on('shutdown', function() { - idleListener.stop(); + idleDetector.stop(); if (messageReceiver) { messageReceiver.close().then(function() { diff --git a/preload.js b/preload.js index 029df59a6..7a8defd34 100644 --- a/preload.js +++ b/preload.js @@ -122,12 +122,12 @@ const upgradeMessageSchema = message => Message.upgradeSchema(message, upgradeSchemaContext); - window.Signal = window.Signal || {}; - const { IdleDetector} = require('./js/modules/idle_detector'); - window.Signal.IdleDetector = IdleDetector; + window.Signal = window.Signal || {}; + window.Signal.IdleDetector = IdleDetector; window.Signal.Logs = require('./js/modules/logs'); + window.Signal.MessageMigration = require('./js/modules/messages_migration'); window.Signal.OS = require('./js/modules/os'); window.Signal.Backup = require('./js/modules/backup'); window.Signal.Crypto = require('./js/modules/crypto');