From d816a2ed9f68322fb91091605cf81283bc95db51 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 19 Jul 2018 17:51:38 +0200 Subject: [PATCH] Prevent timeout when restoring drive --- www/common/cryptpad-common.js | 6 ++++-- www/common/outer/worker-channel.js | 6 ++++-- www/common/sframe-channel.js | 6 ++++-- www/drive/inner.js | 7 ++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 02f7c80a7..4652c104f 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -110,6 +110,8 @@ define([ value: data }, function (obj) { cb(obj); + }, { + timeout: 5 * 60 * 1000 }); }; common.addSharedFolder = function (secret, cb) { @@ -1328,12 +1330,12 @@ define([ }); }); - postMessage = function (cmd, data, cb) { + postMessage = function (cmd, data, cb, opts) { cb = cb || function () {}; chan.query(cmd, data, function (err, data) { if (err) { return void cb ({error: err}); } cb(data); - }); + }, opts); }; console.log('Posting CONNECT'); diff --git a/www/common/outer/worker-channel.js b/www/common/outer/worker-channel.js index 30148fc40..06c81d1eb 100644 --- a/www/common/outer/worker-channel.js +++ b/www/common/outer/worker-channel.js @@ -32,12 +32,14 @@ define([ var chan = {}; // Send a query. channel.query('Q_SOMETHING', { args: "whatever" }, function (reply) { ... }); - chan.query = function (q, content, cb) { + chan.query = function (q, content, cb, opts) { var txid = mkTxid(); + opts = opts || {}; + var to = opts.timeout || 30000; var timeout = setTimeout(function () { delete queries[txid]; //console.log("Timeout making query " + q); - }, 30000); + }, to); queries[txid] = function (data, msg) { clearTimeout(timeout); delete queries[txid]; diff --git a/www/common/sframe-channel.js b/www/common/sframe-channel.js index eb06af6ab..a7edf0814 100644 --- a/www/common/sframe-channel.js +++ b/www/common/sframe-channel.js @@ -21,16 +21,18 @@ define([ var chan = {}; // Send a query. channel.query('Q_SOMETHING', { args: "whatever" }, function (reply) { ... }); - chan.query = function (q, content, cb) { + chan.query = function (q, content, cb, opts) { if (!otherWindow) { throw new Error('not yet initialized'); } if (!SFrameProtocol[q]) { throw new Error('please only make queries are defined in sframe-protocol.js'); } + opts = opts || {}; var txid = mkTxid(); + var to = opts.timeout || 30000; var timeout = setTimeout(function () { delete queries[txid]; console.log("Timeout making query " + q); - }, 30000); + }, to); queries[txid] = function (data, msg) { clearTimeout(timeout); delete queries[txid]; diff --git a/www/drive/inner.js b/www/drive/inner.js index dc5c5fad2..f3904c692 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3374,8 +3374,13 @@ define([ /* add a history button */ APP.histConfig = { onLocal: function () { + UI.addLoadingScreen({ loadingText: "Please be careful" }); // XXX proxy.drive = history.currentObj.drive; - sframeChan.query("Q_DRIVE_RESTORE", history.currentObj.drive, function () {}); + sframeChan.query("Q_DRIVE_RESTORE", history.currentObj.drive, function () { + UI.removeLoadingScreen(); + }, { + timeout: 5 * 60 * 1000 + }); }, onRemote: function () {}, setHistory: setHistory,