Make loading screen come much earlier on pad2
This commit is contained in:
parent
ec64ac485d
commit
cbac5e417c
@ -1,5 +1,5 @@
|
|||||||
define([
|
define([
|
||||||
'less!/customize/src/less/cryptpad.less'
|
'less!/customize/src/less/loading.less'
|
||||||
], function () {
|
], function () {
|
||||||
var urlArgs = window.location.href.replace(/^.*\?([^\?]*)$/, function (all, x) { return x; });
|
var urlArgs = window.location.href.replace(/^.*\?([^\?]*)$/, function (all, x) { return x; });
|
||||||
var elem = document.createElement('div');
|
var elem = document.createElement('div');
|
||||||
|
|||||||
@ -9,11 +9,22 @@ if (req.pfx) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
require.config(req.cfg);
|
require.config(req.cfg);
|
||||||
if (req.req) { require(req.req, function () { }); }
|
var txid = Math.random().toString(16).replace('0.', '');
|
||||||
window.addEventListener('message', function (msg) {
|
var intr;
|
||||||
|
var ready = function () {
|
||||||
|
intr = setInterval(function () {
|
||||||
|
if (typeof(txid) !== 'string') { return; }
|
||||||
|
window.parent.postMessage(JSON.stringify({ q: 'READY', txid: txid }), '*');
|
||||||
|
}, 1);
|
||||||
|
};
|
||||||
|
if (req.req) { require(req.req, ready); } else { ready(); }
|
||||||
|
var onReply = function (msg) {
|
||||||
var data = JSON.parse(msg.data);
|
var data = JSON.parse(msg.data);
|
||||||
if (data.q !== 'INIT') { return; }
|
if (data.txid !== txid) { return; }
|
||||||
msg.source.postMessage(JSON.stringify({ txid: data.txid, content: 'OK' }), '*');
|
clearInterval(intr);
|
||||||
|
txid = {};
|
||||||
|
window.removeEventListener('message', onReply);
|
||||||
require(['/common/sframe-boot2.js'], function () { });
|
require(['/common/sframe-boot2.js'], function () { });
|
||||||
});
|
};
|
||||||
|
window.addEventListener('message', onReply);
|
||||||
}());
|
}());
|
||||||
@ -105,7 +105,6 @@ define([
|
|||||||
insideHandlers.push(content);
|
insideHandlers.push(content);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var intr;
|
|
||||||
var txid;
|
var txid;
|
||||||
window.addEventListener('message', function (msg) {
|
window.addEventListener('message', function (msg) {
|
||||||
var data = JSON.parse(msg.data);
|
var data = JSON.parse(msg.data);
|
||||||
@ -113,12 +112,8 @@ define([
|
|||||||
console.log("DROP Message from unexpected source");
|
console.log("DROP Message from unexpected source");
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
} else if (!otherWindow) {
|
} else if (!otherWindow) {
|
||||||
if (data.txid !== txid) {
|
|
||||||
console.log("DROP Message with weird txid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearInterval(intr);
|
|
||||||
otherWindow = ow;
|
otherWindow = ow;
|
||||||
|
ow.postMessage(JSON.stringify({ txid: data.txid }), '*');
|
||||||
cb(chan);
|
cb(chan);
|
||||||
} else if (typeof(data.q) === 'string' && handlers[data.q]) {
|
} else if (typeof(data.q) === 'string' && handlers[data.q]) {
|
||||||
handlers[data.q].forEach(function (f) {
|
handlers[data.q].forEach(function (f) {
|
||||||
@ -139,17 +134,6 @@ define([
|
|||||||
// we're in the sandbox
|
// we're in the sandbox
|
||||||
otherWindow = ow;
|
otherWindow = ow;
|
||||||
cb(chan);
|
cb(chan);
|
||||||
} else {
|
|
||||||
require(['/common/requireconfig.js'], function (RequireConfig) {
|
|
||||||
txid = mkTxid();
|
|
||||||
intr = setInterval(function () {
|
|
||||||
ow.postMessage(JSON.stringify({
|
|
||||||
txid: txid,
|
|
||||||
content: { requireConf: RequireConfig() },
|
|
||||||
q: 'INIT'
|
|
||||||
}), '*');
|
|
||||||
}, 1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<html class="cp pad">
|
<html class="cp pad">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
<script async data-bootload="/pad2/main.js" data-main="/common/sframe-boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
<script async data-bootload="/pad2/main.js" data-main="/common/sframe-boot.js?ver=1.1" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
|||||||
@ -1,11 +1,25 @@
|
|||||||
|
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
||||||
define([
|
define([
|
||||||
|
'/bower_components/nthen/index.js',
|
||||||
'/api/config',
|
'/api/config',
|
||||||
'jquery',
|
'jquery',
|
||||||
'/common/requireconfig.js',
|
'/common/requireconfig.js'
|
||||||
'/common/cryptget.js'
|
], function (nThen, ApiConfig, $, RequireConfig) {
|
||||||
], function (ApiConfig, $, RequireConfig, Cryptget) {
|
|
||||||
var requireConfig = RequireConfig();
|
var requireConfig = RequireConfig();
|
||||||
$(function () {
|
|
||||||
|
// Loaded in load #3
|
||||||
|
var CpNfOuter;
|
||||||
|
var Cryptpad;
|
||||||
|
var Crypto;
|
||||||
|
var Cryptget;
|
||||||
|
|
||||||
|
var sframeChan;
|
||||||
|
var secret;
|
||||||
|
var hashes;
|
||||||
|
|
||||||
|
nThen(function (waitFor) {
|
||||||
|
$(waitFor());
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
var req = {
|
var req = {
|
||||||
cfg: requireConfig,
|
cfg: requireConfig,
|
||||||
req: [ '/common/loading.js' ],
|
req: [ '/common/loading.js' ],
|
||||||
@ -16,25 +30,38 @@ define([
|
|||||||
$('#sbox-iframe').attr('src',
|
$('#sbox-iframe').attr('src',
|
||||||
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + requireConfig.urlArgs +
|
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + requireConfig.urlArgs +
|
||||||
'#' + encodeURIComponent(JSON.stringify(req)));
|
'#' + encodeURIComponent(JSON.stringify(req)));
|
||||||
});
|
|
||||||
require([
|
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
||||||
'/common/sframe-channel.js',
|
// loading screen setup.
|
||||||
'/common/sframe-chainpad-netflux-outer.js',
|
var done = waitFor();
|
||||||
'/bower_components/nthen/index.js',
|
var onMsg = function (msg) {
|
||||||
'/common/cryptpad-common.js',
|
var data = JSON.parse(msg.data);
|
||||||
'/bower_components/chainpad-crypto/crypto.js'
|
if (data.q !== 'READY') { return; }
|
||||||
], function (SFrameChannel, CpNfOuter, nThen, Cryptpad, Crypto) {
|
window.removeEventListener('message', onMsg);
|
||||||
var sframeChan;
|
var _done = done;
|
||||||
var hashes;
|
done = function () { };
|
||||||
var secret;
|
_done();
|
||||||
nThen(function (waitFor) {
|
};
|
||||||
$(waitFor());
|
window.addEventListener('message', onMsg);
|
||||||
|
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
|
// Load #3, the loading screen is up so grab whatever you need...
|
||||||
|
require([
|
||||||
|
'/common/sframe-chainpad-netflux-outer.js',
|
||||||
|
'/common/cryptpad-common.js',
|
||||||
|
'/bower_components/chainpad-crypto/crypto.js',
|
||||||
|
'/common/cryptget.js',
|
||||||
|
'/common/sframe-channel.js',
|
||||||
|
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel) {
|
||||||
|
CpNfOuter = _CpNfOuter;
|
||||||
|
Cryptpad = _Cryptpad;
|
||||||
|
Crypto = _Crypto;
|
||||||
|
Cryptget = _Cryptget;
|
||||||
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
||||||
sframeChan = sfc;
|
sframeChan = sfc;
|
||||||
console.log('sframe initialized');
|
|
||||||
}));
|
}));
|
||||||
Cryptpad.ready(waitFor());
|
Cryptpad.ready(waitFor());
|
||||||
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
secret = Cryptpad.getSecrets();
|
secret = Cryptpad.getSecrets();
|
||||||
if (!secret.channel) {
|
if (!secret.channel) {
|
||||||
@ -195,4 +222,3 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user