From 598d56c75e88e22be07abb4875d60f36161e322f Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 6 Jun 2018 17:45:43 +0200 Subject: [PATCH 1/2] Fix cache issues --- www/common/cryptpad-common.js | 5 +- www/common/outer/webworker.js | 89 +++++++++++++++-------------------- 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index e550671b0..53600499e 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -16,13 +16,14 @@ define([ Messaging, Constants, Feedback, LocalStore, /*AStore, */Channel, AppConfig, Nthen) { - /* This file exposes functionality which is specific to Cryptpad, but not to any particular pad type. This includes functions for committing metadata about pads to your local storage for future use and improved usability. Additionally, there is some basic functionality for import/export. */ + var urlArgs = Util.find(Config, ['requireConf', 'urlArgs']) || ''; + var postMessage = function (/*cmd, data, cb*/) { /*setTimeout(function () { AStore.query(cmd, data, cb); @@ -885,7 +886,7 @@ define([ }));*/ var msgEv = Util.mkEvent(); - var worker = new Worker('/common/outer/webworker.js'); + var worker = new Worker('/common/outer/webworker.js?' + urlArgs); worker.onmessage = function (ev) { msgEv.fire(ev); }; diff --git a/www/common/outer/webworker.js b/www/common/outer/webworker.js index 81cd2fa9f..fcdfdc6cb 100644 --- a/www/common/outer/webworker.js +++ b/www/common/outer/webworker.js @@ -1,63 +1,52 @@ /* jshint ignore:start */ importScripts('/bower_components/requirejs/require.js'); -require.config({ - // fix up locations so that relative urls work. - baseUrl: '/', - paths: { - // jquery declares itself as literally "jquery" so it cannot be pulled by path :( - "jquery": "/bower_components/jquery/dist/jquery.min", - // json.sortify same - "json.sortify": "/bower_components/json.sortify/dist/JSON.sortify", - cm: '/bower_components/codemirror' - }, - map: { - '*': { - 'css': '/bower_components/require-css/css.js', - 'less': '/common/RequireLess.js', - } - } -}); window = self; localStorage = { setItem: function (k, v) { localStorage[k] = v; }, getItem: function (k) { return localStorage[k]; } }; + require([ - '/common/common-util.js', - '/common/outer/worker-channel.js', - '/common/outer/store-rpc.js' -], function (Util, Channel, Rpc) { - var msgEv = Util.mkEvent(); + '/common/requireconfig.js' +], function (RequireConfig) { + require.config(RequireConfig()); + require([ + '/common/common-util.js', + '/common/outer/worker-channel.js', + '/common/outer/store-rpc.js' + ], function (Util, Channel, Rpc) { + var msgEv = Util.mkEvent(); - Channel.create(msgEv, postMessage, function (chan) { - console.log('ww ready'); - Object.keys(Rpc.queries).forEach(function (q) { - if (q === 'CONNECT') { return; } - chan.on(q, function (data, cb) { - try { - Rpc.queries[q](data, cb); - } catch (e) { - console.error('Error in webworker when executing query ' + q); - console.error(e); - console.log(data); - } - }); - }); - chan.on('CONNECT', function (cfg, cb) { - console.log('onConnect'); - // load Store here, with cfg, and pass a "query" (chan.query) - cfg.query = function (cmd, data, cb) { - chan.query(cmd, data, function (err, data) { - if (err) { return void cb({error: err}); } - cb(data); + Channel.create(msgEv, postMessage, function (chan) { + console.log('ww ready'); + Object.keys(Rpc.queries).forEach(function (q) { + if (q === 'CONNECT') { return; } + chan.on(q, function (data, cb) { + try { + Rpc.queries[q](data, cb); + } catch (e) { + console.error('Error in webworker when executing query ' + q); + console.error(e); + console.log(data); + } }); - }; - Rpc.queries['CONNECT'](cfg, cb); - }); - }, true); + }); + chan.on('CONNECT', function (cfg, cb) { + console.log('onConnect'); + // load Store here, with cfg, and pass a "query" (chan.query) + cfg.query = function (cmd, data, cb) { + chan.query(cmd, data, function (err, data) { + if (err) { return void cb({error: err}); } + cb(data); + }); + }; + Rpc.queries['CONNECT'](cfg, cb); + }); + }, true); - onmessage = function (e) { - msgEv.fire(e); - }; + onmessage = function (e) { + msgEv.fire(e); + }; + }); }); From a6d9ecb3ba270d2e8167f8a9cfb690b13f43e611 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 6 Jun 2018 17:48:10 +0200 Subject: [PATCH 2/2] lint compliance --- www/common/outer/async-store.js | 2 +- www/worker/sw.js | 2 ++ www/worker2 | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) delete mode 120000 www/worker2 diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index eb8748c6f..d7c8489d4 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -928,7 +928,7 @@ define([ queue: [], data: {} }; - Store.joinPad = function (data, cb) { + Store.joinPad = function (data) { var conf = { onReady: function (padData) { channel.data = padData || {}; diff --git a/www/worker/sw.js b/www/worker/sw.js index 7f102e49f..8790de68c 100644 --- a/www/worker/sw.js +++ b/www/worker/sw.js @@ -1,3 +1,5 @@ +/* jshint ignore:start */ + var id = Math.floor(Math.random()*100000); var postMsg = function (client, data) { diff --git a/www/worker2 b/www/worker2 deleted file mode 120000 index b2b186dda..000000000 --- a/www/worker2 +++ /dev/null @@ -1 +0,0 @@ -worker/ \ No newline at end of file