Fix the webworker app

This commit is contained in:
yflory
2017-12-01 18:29:59 +01:00
parent b14228da18
commit e164edec03
7 changed files with 72 additions and 13 deletions

View File

@@ -4,6 +4,8 @@ define([
'/common/cryptpad-common.js',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
'/common/common-interface.js',
'/customize/messages.js',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
@@ -14,15 +16,16 @@ define([
Cryptpad,
nThen,
SFCommon,
UI,
Messages
)
{
var Messages = Cryptpad.Messages;
var APP = window.APP = {};
var common;
var sFrameChan;
nThen(function (waitFor) {
$(waitFor(Cryptpad.addLoadingScreen));
$(waitFor(UI.addLoadingScreen));
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
}).nThen(function (waitFor) {
sFrameChan = common.getSframeChannel();
@@ -44,7 +47,7 @@ define([
APP.toolbar = Toolbar.create(configTb);
APP.toolbar.$rightside.hide();
Cryptpad.removeLoadingScreen();
UI.removeLoadingScreen();
if (!window.Worker) {
return void $container.text("WebWorkers not supported by your browser");
}

View File

@@ -2,15 +2,15 @@
define([
'/bower_components/nthen/index.js',
'/api/config',
'jquery',
'/common/dom-ready.js',
'/common/requireconfig.js',
'/common/sframe-common-outer.js'
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
$(waitFor());
DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
@@ -19,7 +19,7 @@ define([
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
$('#sbox-iframe').attr('src',
document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/worker/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));

View File

@@ -30,19 +30,39 @@ var i = 0;
onconnect = function(e) {
console.log(e);
console.log(i);
var port = e.ports[0];
console.log('here');
require([
'/customize/messages.js',
], function (Messages) {
console.log(Messages);
'/common/outer/async-store.js'
], function (Store) {
console.log(Store);
console.log(self.Proxy);
var n = i;
port.postMessage({state: 'READY'});
port.onmessage = function (e) {
console.log('worker received');
console.log(e.data);
port.postMessage('hello CryptPad'+n+', ' + Messages.test);
port.postMessage('hello CryptPad'+n);
};
var data = {
query: function (cmd, data, cb) {
console.log(cmd, data);
},
userHash: '/1/edit/RuTAa+HmbtSUqCWPAEXqPQ/WxOd8thjW3l7Bnkkfn9alSTB/',
anonHash: '/1/edit/GT+hupjbbJqo9JIld-G8Rw/onfiJqWbpB0sAb-1sB6VhE+v/',
localToken: 4915598039548860,
language: 'fr',
};
Store.init(data, function (ret) {
console.log(ret);
console.log("Store is connected");
Store.get(['cryptpad.username'], function (val) {
port.postMessage(val);
});
port.postMessage('Store is connected!');
port.postMessage('Your username is ' + ret.store.proxy['cryptpad.username']);
});
i++;
});
};