prepare rpc before 'ready' if pinning is enabled

This commit is contained in:
ansuz 2017-04-07 17:24:25 +02:00
parent a70388284d
commit bd2034c47b
2 changed files with 53 additions and 4 deletions

View file

@ -12,6 +12,8 @@ define(function() {
*/
config.notificationTimeout = 5000;
config.enablePinning = true;
config.whiteboardPalette = [
'#000000', // black
'#FFFFFF', // white

View file

@ -6,9 +6,11 @@ define([
'/bower_components/alertifyjs/dist/js/alertify.js',
'/common/clipboard.js',
'/customize/application_config.js',
'/common/pinpad.js', /* TODO
load pinpad dynamically only after you know that it will be needed */
'/bower_components/jquery/dist/jquery.min.js',
], function (Config, Messages, Store, Crypto, Alertify, Clipboard, AppConfig) {
], function (Config, Messages, Store, Crypto, Alertify, Clipboard, Pinpad, AppConfig) {
/* 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.
@ -25,6 +27,8 @@ define([
var store;
var PINNING_ENABLED = AppConfig.enablePinning;
var rpc;
var find = common.find = function (map, path) {
return (map && path.reduce(function (p, n) {
@ -36,6 +40,11 @@ define([
if (store) { return store; }
throw new Error("Store is not ready!");
};
var getProxy = common.getProxy = function () {
if (store && store.getProxy()) {
return store.getProxy().proxy;
}
};
var getNetwork = common.getNetwork = function () {
if (store) {
if (store.getProxy() && store.getProxy().info) {
@ -563,6 +572,7 @@ define([
// STORAGE
/* commit a list of pads to localStorage */
// TODO integrate pinning if enabled
var setRecentPads = common.setRecentPads = function (pads, cb) {
getStore().setDrive(storageKey, pads, function (err, data) {
cb(err, data);
@ -589,6 +599,7 @@ define([
// STORAGE
// TODO integrate pinning if enabled
var forgetPad = common.forgetPad = function (href, cb) {
var parsed = parsePadUrl(href);
@ -670,6 +681,8 @@ define([
var isNotStrongestStored = common.isNotStrongestStored = function (href, recents) {
return findStronger(href, recents);
};
// TODO integrate pinning
var setPadTitle = common.setPadTitle = function (name, cb) {
var href = window.location.href;
var parsed = parsePadUrl(href);
@ -805,12 +818,14 @@ define([
// local name?
common.ready = function (f) {
var state = 0;
var block = 0;
var env = {};
var cb = function () {
block--;
if (!block) {
f(void 0, env);
}
};
if (sessionStorage[newPadNameKey]) {
@ -825,6 +840,9 @@ define([
Store.ready(function (err, storeObj) {
store = common.store = env.store = storeObj;
var proxy = getProxy();
var network = getNetwork();
$(function() {
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
// won't work. We have to reset it now to make sure it uses a correct "body"
@ -848,8 +866,34 @@ define([
}
};
if (PINNING_ENABLED && isLoggedIn()) {
console.log("logged in. pads will be pinned");
block++;
// TODO setTimeout in case rpc doesn't
// activate in reasonable time?
Pinpad.create(network, proxy, function (e, call) {
if (e) {
console.error(e);
return cb();
}
console.log('RPC handshake complete');
rpc = env.rpc = call;
// TODO check if pin list is up to date
// if not, reset
cb();
});
} else if (PINNING_ENABLED) {
console.log('not logged in. pads will not be pinned');
} else {
console.log('pinning disabled');
}
// Everything's ready, continue...
if($('#pad-iframe').length) {
block++;
var $iframe = $('#pad-iframe');
var iframe = $iframe[0];
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
@ -860,6 +904,8 @@ define([
$iframe.load(cb);
return;
}
block++;
cb();
});
}, common);
@ -950,6 +996,7 @@ define([
/*
* Buttons
*/
// TODO integrate pinning if enabled
var renamePad = common.renamePad = function (title, callback) {
if (title === null) { return; }