Fix the webworker app

pull/1/head
yflory 7 years ago
parent b14228da18
commit e164edec03

@ -37,4 +37,5 @@ body.cp-app-todo { @import "../../../todo/app-todo.less"; }
body.cp-app-profile { @import "../../../profile/app-profile.less"; } body.cp-app-profile { @import "../../../profile/app-profile.less"; }
body.cp-app-settings { @import "../../../settings/app-settings.less"; } body.cp-app-settings { @import "../../../settings/app-settings.less"; }
body.cp-app-debug { @import "../../../debug/app-debug.less"; } body.cp-app-debug { @import "../../../debug/app-debug.less"; }
body.cp-app-worker { @import "../../../worker/app-worker.less"; }

@ -650,6 +650,9 @@ define([
} }
AStore.query("CONNECT", cfg, waitFor(function (data) { AStore.query("CONNECT", cfg, waitFor(function (data) {
if (data.error) { throw new Error(data.error); } if (data.error) { throw new Error(data.error); }
if (data.state === 'ALREADY_INIT') {
data = data.returned;
}
if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); } if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); }

@ -815,7 +815,6 @@ define([
store.proxy = rt.proxy; store.proxy = rt.proxy;
store.loggedIn = typeof(data.userHash) !== "undefined"; store.loggedIn = typeof(data.userHash) !== "undefined";
var returned = {};
rt.proxy.on('create', function (info) { rt.proxy.on('create', function (info) {
store.realtime = info.realtime; store.realtime = info.realtime;
store.network = info.network; store.network = info.network;
@ -858,7 +857,8 @@ define([
Store.init = function (data, callback) { Store.init = function (data, callback) {
if (initialized) { if (initialized) {
return void callback({ return void callback({
error: 'ALREADY_INIT' state: 'ALREADY_INIT',
returned: store.returned
}); });
} }
initialized = true; initialized = true;
@ -873,6 +873,7 @@ define([
if (Object.keys(store.proxy).length === 1) { if (Object.keys(store.proxy).length === 1) {
Feedback.send("FIRST_APP_USE", true); Feedback.send("FIRST_APP_USE", true);
} }
store.returned = ret;
callback(ret); callback(ret);

@ -0,0 +1,31 @@
var window = self;
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",
//"pdfjs-dist/build/pdf": "/bower_components/pdfjs-dist/build/pdf",
//"pdfjs-dist/build/pdf.worker": "/bower_components/pdfjs-dist/build/pdf.worker"
cm: '/bower_components/codemirror'
},
map: {
'*': {
'css': '/bower_components/require-css/css.js',
'less': '/common/RequireLess.js',
}
}
});
onconnect = function(e) {
var port = e.ports[0];
port.postMessage({state: 'READY'});
port.onmessage = function (e) {
};
};

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

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

@ -30,19 +30,39 @@ var i = 0;
onconnect = function(e) { onconnect = function(e) {
console.log(e); console.log(e);
console.log(i);
var port = e.ports[0]; var port = e.ports[0];
console.log('here'); console.log('here');
require([ require([
'/customize/messages.js', '/common/outer/async-store.js'
], function (Messages) { ], function (Store) {
console.log(Messages); console.log(Store);
console.log(self.Proxy);
var n = i; var n = i;
port.postMessage({state: 'READY'}); port.postMessage({state: 'READY'});
port.onmessage = function (e) { port.onmessage = function (e) {
console.log('worker received'); console.log('worker received');
console.log(e.data); 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++; i++;
}); });
}; };

Loading…
Cancel
Save