Restore connector mode functionality in Firefox
Non-Zotero for Firefox connector code will probably need to be updated to handle these changes.
This commit is contained in:
parent
b18c580dac
commit
e3a9c6779b
|
@ -613,7 +613,9 @@ var Zotero_Browser = new function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield Zotero.DB.waitForTransaction();
|
if (!Zotero.isConnector) {
|
||||||
|
yield Zotero.DB.waitForTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
Zotero_Browser.progress.show();
|
Zotero_Browser.progress.show();
|
||||||
Zotero_Browser.isScraping = true;
|
Zotero_Browser.isScraping = true;
|
||||||
|
@ -635,14 +637,16 @@ var Zotero_Browser = new function() {
|
||||||
collection = ZoteroPane.getSelectedCollection();
|
collection = ZoteroPane.getSelectedCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
|
if (!Zotero.isConnector) {
|
||||||
Zotero_Browser.progress.Translation.cannotAddToPublications();
|
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
|
||||||
return;
|
Zotero_Browser.progress.Translation.cannotAddToPublications();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (Zotero.Feeds.get(libraryID)) {
|
|
||||||
Zotero_Browser.progress.Translation.cannotAddToFeed();
|
if (Zotero.Feeds.get(libraryID)) {
|
||||||
return;
|
Zotero_Browser.progress.Translation.cannotAddToFeed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero_Browser.progress.Translation.scrapingTo(libraryID, collection);
|
Zotero_Browser.progress.Translation.scrapingTo(libraryID, collection);
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
Components.utils.import("resource://zotero/config.js");
|
Components.utils.import("resource://zotero/config.js");
|
||||||
Components.utils.import("resource:///modules/CustomizableUI.jsm");
|
Components.utils.import("resource:///modules/CustomizableUI.jsm");
|
||||||
|
|
||||||
|
// Necessary for connector mode, for some reason
|
||||||
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
||||||
|
.getService(Components.interfaces.nsISupports)
|
||||||
|
.wrappedJSObject;
|
||||||
|
|
||||||
var comboButtonsID = 'zotero-toolbar-buttons';
|
var comboButtonsID = 'zotero-toolbar-buttons';
|
||||||
|
|
||||||
CustomizableUI.addListener({
|
CustomizableUI.addListener({
|
||||||
|
|
|
@ -42,6 +42,10 @@ var ZoteroOverlay = new function()
|
||||||
var self = this;
|
var self = this;
|
||||||
var iconLoaded = false;
|
var iconLoaded = false;
|
||||||
|
|
||||||
|
if (Zotero.isConnector) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.Promise.try(function () {
|
Zotero.Promise.try(function () {
|
||||||
if (!Zotero) {
|
if (!Zotero) {
|
||||||
throw new Error("No Zotero object");
|
throw new Error("No Zotero object");
|
||||||
|
|
|
@ -55,34 +55,54 @@ Zotero.Repo = new function() {
|
||||||
/**
|
/**
|
||||||
* Get translator code from repository
|
* Get translator code from repository
|
||||||
* @param {String} translatorID ID of the translator to retrieve code for
|
* @param {String} translatorID ID of the translator to retrieve code for
|
||||||
* @param {Function} callback Callback to pass code when retreived
|
|
||||||
*/
|
*/
|
||||||
this.getTranslatorCode = function(translatorID, callback) {
|
this.getTranslatorCode = Zotero.Promise.method(function (translatorID) {
|
||||||
|
var deferred = Zotero.Promise.defer();
|
||||||
|
|
||||||
// try standalone
|
// try standalone
|
||||||
Zotero.Connector.callMethod("getTranslatorCode", {"translatorID":translatorID}, function(result) {
|
Zotero.Connector.callMethod("getTranslatorCode", {"translatorID":translatorID}, function(result) {
|
||||||
if(result) {
|
if(result) {
|
||||||
_haveCode(result, translatorID, Zotero.Repo.SOURCE_ZOTERO_STANDALONE, callback);
|
deferred.resolve(
|
||||||
|
Zotero.Promise.all(
|
||||||
|
[
|
||||||
|
_haveCode(result, translatorID),
|
||||||
|
Zotero.Repo.SOURCE_ZOTERO_STANDALONE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// then try repo
|
// then try repo
|
||||||
Zotero.HTTP.doGet(ZOTERO_CONFIG.REPOSITORY_URL + "code/" + translatorID + "?version=" + Zotero.version,
|
Zotero.HTTP.doGet(
|
||||||
|
ZOTERO_CONFIG.REPOSITORY_URL + "code/" + translatorID + "?version=" + Zotero.version,
|
||||||
function(xmlhttp) {
|
function(xmlhttp) {
|
||||||
_haveCode(xmlhttp.status === 200 ? xmlhttp.responseText : false, translatorID,
|
deferred.resolve(
|
||||||
Zotero.Repo.SOURCE_REPO, callback);
|
Zotero.Promise.all(
|
||||||
|
[
|
||||||
|
_haveCode(
|
||||||
|
xmlhttp.status === 200 ? xmlhttp.responseText : false,
|
||||||
|
translatorID
|
||||||
|
),
|
||||||
|
Zotero.Repo.SOURCE_REPO
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
return deferred.promise;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when code has been retrieved from standalone or repo
|
* Called when code has been retrieved from standalone or repo
|
||||||
*/
|
*/
|
||||||
function _haveCode(code, translatorID, source, callback) {
|
function _haveCode(code, translatorID) {
|
||||||
if(!code) {
|
if(!code) {
|
||||||
Zotero.logError(new Error("Code could not be retrieved for " + translatorID));
|
Zotero.logError(new Error("Code could not be retrieved for " + translatorID));
|
||||||
callback(false);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Zotero.isFx) {
|
if(!Zotero.isFx) {
|
||||||
|
@ -91,16 +111,14 @@ Zotero.Repo = new function() {
|
||||||
var m = infoRe.exec(code);
|
var m = infoRe.exec(code);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
Zotero.logError(new Error("Invalid or missing translator metadata JSON object for " + translatorID));
|
Zotero.logError(new Error("Invalid or missing translator metadata JSON object for " + translatorID));
|
||||||
callback(false);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var metadata = JSON.parse(m[0]);
|
var metadata = JSON.parse(m[0]);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Zotero.logError(new Error("Invalid or missing translator metadata JSON object for " + translatorID));
|
Zotero.logError(new Error("Invalid or missing translator metadata JSON object for " + translatorID));
|
||||||
callback(false);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var translator = Zotero.Translators.getWithoutCode(translatorID);
|
var translator = Zotero.Translators.getWithoutCode(translatorID);
|
||||||
|
@ -114,7 +132,7 @@ Zotero.Repo = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(code, source);
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Enumeration of types of translators
|
// Enumeration of types of translators
|
||||||
const TRANSLATOR_TYPES = {"import":1, "export":2, "web":4, "search":8};
|
var TRANSLATOR_TYPES = {"import":1, "export":2, "web":4, "search":8};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton to handle loading and caching of translators
|
* Singleton to handle loading and caching of translators
|
||||||
|
@ -92,9 +92,6 @@ Zotero.Translators = new function() {
|
||||||
/**
|
/**
|
||||||
* Gets the translator that corresponds to a given ID, without attempting to retrieve code
|
* Gets the translator that corresponds to a given ID, without attempting to retrieve code
|
||||||
* @param {String} id The ID of the translator
|
* @param {String} id The ID of the translator
|
||||||
* @param {Function} [callback] An optional callback to be executed when translators have been
|
|
||||||
* retrieved. If no callback is specified, translators are
|
|
||||||
* returned.
|
|
||||||
*/
|
*/
|
||||||
this.getWithoutCode = function(id) {
|
this.getWithoutCode = function(id) {
|
||||||
if(!_initialized) Zotero.Translators.init();
|
if(!_initialized) Zotero.Translators.init();
|
||||||
|
@ -103,54 +100,46 @@ Zotero.Translators = new function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the translator that corresponds to a given ID
|
* Gets the translator that corresponds to a given ID
|
||||||
|
*
|
||||||
* @param {String} id The ID of the translator
|
* @param {String} id The ID of the translator
|
||||||
* @param {Function} [callback] An optional callback to be executed when translators have been
|
|
||||||
* retrieved. If no callback is specified, translators are
|
|
||||||
* returned.
|
|
||||||
*/
|
*/
|
||||||
this.get = function(id, callback) {
|
this.get = Zotero.Promise.method(function (id) {
|
||||||
if(!_initialized) Zotero.Translators.init();
|
if(!_initialized) Zotero.Translators.init();
|
||||||
var translator = _translators[id];
|
var translator = _translators[id];
|
||||||
if(!translator) {
|
if(!translator) {
|
||||||
callback(false);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only need to get code if it is of some use
|
// only need to get code if it is of some use
|
||||||
if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER
|
if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER
|
||||||
&& !translator.hasOwnProperty("code")) {
|
&& !translator.hasOwnProperty("code")) {
|
||||||
translator.getCode(function() { callback(translator) });
|
return translator.getCode().then(() => translator);
|
||||||
} else {
|
} else {
|
||||||
callback(translator);
|
return translator;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all translators for a specific type of translation
|
* Gets all translators for a specific type of translation
|
||||||
* @param {String} type The type of translators to get (import, export, web, or search)
|
* @param {String} type The type of translators to get (import, export, web, or search)
|
||||||
* @param {Function} callback A required callback to be executed when translators have been
|
|
||||||
* retrieved.
|
|
||||||
* @param {Boolean} [debugMode] Whether to assume debugging mode. If true, code is included for
|
* @param {Boolean} [debugMode] Whether to assume debugging mode. If true, code is included for
|
||||||
* unsupported translators, and code originally retrieved from the
|
* unsupported translators, and code originally retrieved from the
|
||||||
* repo is re-retrieved from Zotero Standalone.
|
* repo is re-retrieved from Zotero Standalone.
|
||||||
*/
|
*/
|
||||||
this.getAllForType = function(type, callback, debugMode) {
|
this.getAllForType = Zotero.Promise.method(function (type, debugMode) {
|
||||||
if(!_initialized) Zotero.Translators.init()
|
if(!_initialized) Zotero.Translators.init()
|
||||||
var translators = _cache[type].slice(0);
|
var translators = _cache[type].slice(0);
|
||||||
new Zotero.Translators.CodeGetter(translators, callback, translators, debugMode);
|
var codeGetter = new Zotero.Translators.CodeGetter(translators, debugMode);
|
||||||
return true;
|
return codeGetter.getAll();
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets web translators for a specific location
|
* Gets web translators for a specific location
|
||||||
* @param {String} uri The URI for which to look for translators
|
* @param {String} uri The URI for which to look for translators
|
||||||
* @param {Function} [callback] An optional callback to be executed when translators have been
|
* @return {Promise<Array[]>} - A promise for a 2-item array containing an array of translators and
|
||||||
* retrieved. If no callback is specified, translators are
|
* an array of functions for converting URLs from proper to proxied forms
|
||||||
* returned. The callback is passed a set of functions for
|
|
||||||
* converting URLs from proper to proxied forms as the second
|
|
||||||
* argument.
|
|
||||||
*/
|
*/
|
||||||
this.getWebTranslatorsForLocation = function(uri, callback) {
|
this.getWebTranslatorsForLocation = Zotero.Promise.method(function (uri) {
|
||||||
if(!_initialized) Zotero.Translators.init();
|
if(!_initialized) Zotero.Translators.init();
|
||||||
var allTranslators = _cache["web"];
|
var allTranslators = _cache["web"];
|
||||||
var potentialTranslators = [];
|
var potentialTranslators = [];
|
||||||
|
@ -215,10 +204,11 @@ Zotero.Translators = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new Zotero.Translators.CodeGetter(potentialTranslators, callback,
|
var codeGetter = new Zotero.Translators.CodeGetter(potentialTranslators);
|
||||||
[potentialTranslators, converterFunctions]);
|
return codeGetter.getAll().then(function () {
|
||||||
return true;
|
return [potentialTranslators, converterFunctions];
|
||||||
}
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts translators to JSON-serializable objects
|
* Converts translators to JSON-serializable objects
|
||||||
|
@ -331,29 +321,16 @@ Zotero.Translators = new function() {
|
||||||
* A class to get the code for a set of translators at once
|
* A class to get the code for a set of translators at once
|
||||||
*
|
*
|
||||||
* @param {Zotero.Translator[]} translators Translators for which to retrieve code
|
* @param {Zotero.Translator[]} translators Translators for which to retrieve code
|
||||||
* @param {Function} callback Callback to call once code has been retrieved
|
|
||||||
* @param {Function} callbackArgs All arguments to be passed to callback (including translators)
|
|
||||||
* @param {Boolean} [debugMode] If true, include code for unsupported translators
|
* @param {Boolean} [debugMode] If true, include code for unsupported translators
|
||||||
*/
|
*/
|
||||||
Zotero.Translators.CodeGetter = function(translators, callback, callbackArgs, debugMode) {
|
Zotero.Translators.CodeGetter = function(translators, debugMode) {
|
||||||
this._translators = translators;
|
this._translators = translators;
|
||||||
this._callbackArgs = callbackArgs;
|
|
||||||
this._callback = callback;
|
|
||||||
this._debugMode = debugMode;
|
this._debugMode = debugMode;
|
||||||
this.getCodeFor(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Translators.CodeGetter.prototype.getCodeFor = function(i) {
|
Zotero.Translators.CodeGetter.prototype.getAll = Zotero.Promise.method(function () {
|
||||||
var me = this;
|
var translators = [];
|
||||||
while(true) {
|
for (let translator of this._translators) {
|
||||||
if(i === this._translators.length) {
|
|
||||||
// all done; run callback
|
|
||||||
this._callback(this._callbackArgs);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var translator = this._translators[i];
|
|
||||||
|
|
||||||
// retrieve code if no code and translator is supported locally
|
// retrieve code if no code and translator is supported locally
|
||||||
if((translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER && !translator.hasOwnProperty("code"))
|
if((translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER && !translator.hasOwnProperty("code"))
|
||||||
// or if debug mode is enabled (even if unsupported locally)
|
// or if debug mode is enabled (even if unsupported locally)
|
||||||
|
@ -362,17 +339,13 @@ Zotero.Translators.CodeGetter.prototype.getCodeFor = function(i) {
|
||||||
// include test cases)
|
// include test cases)
|
||||||
|| (Zotero.Repo && translator.codeSource === Zotero.Repo.SOURCE_REPO)))) {
|
|| (Zotero.Repo && translator.codeSource === Zotero.Repo.SOURCE_REPO)))) {
|
||||||
// get next translator
|
// get next translator
|
||||||
translator.getCode(function() { me.getCodeFor(i+1) });
|
translators.push(translator.getCode());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we are not at end of list and there is no reason to retrieve the code, keep going
|
|
||||||
// through the list of potential translators
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
return Zotero.Promise.all(translators);
|
||||||
|
});
|
||||||
|
|
||||||
const TRANSLATOR_REQUIRED_PROPERTIES = ["translatorID", "translatorType", "label", "creator", "target",
|
var TRANSLATOR_REQUIRED_PROPERTIES = ["translatorID", "translatorType", "label", "creator", "target",
|
||||||
"priority", "lastUpdated"];
|
"priority", "lastUpdated"];
|
||||||
var TRANSLATOR_PASSING_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES
|
var TRANSLATOR_PASSING_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES
|
||||||
.concat(["browserSupport", "code", "runMode", "itemType"]);
|
.concat(["browserSupport", "code", "runMode", "itemType"]);
|
||||||
|
@ -453,21 +426,23 @@ Zotero.Translator.prototype.init = function(info) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves code for this translator
|
* Retrieves code for this translator
|
||||||
|
*
|
||||||
|
* @return {Promise<String|false>} - Promise for translator code or false if none
|
||||||
*/
|
*/
|
||||||
Zotero.Translator.prototype.getCode = function(callback) {
|
Zotero.Translator.prototype.getCode = function () {
|
||||||
var me = this;
|
return Zotero.Repo.getTranslatorCode(this.translatorID)
|
||||||
Zotero.Repo.getTranslatorCode(this.translatorID,
|
.then(function (args) {
|
||||||
function(code, source) {
|
var code = args[0];
|
||||||
if(!code) {
|
var source = args[1];
|
||||||
callback(false);
|
if (!code) {
|
||||||
} else {
|
return false;
|
||||||
// cache code for session only (we have standalone anyway)
|
|
||||||
me.code = code;
|
|
||||||
me.codeSource = source;
|
|
||||||
callback(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
// cache code for session only (we have standalone anyway)
|
||||||
|
this.code = code;
|
||||||
|
this.codeSource = source;
|
||||||
|
return code;
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1082,7 +1082,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
* getAllTranslators parameter is meaningless in this context.
|
* getAllTranslators parameter is meaningless in this context.
|
||||||
* @return {Promise} Promise for an array of {@link Zotero.Translator} objects
|
* @return {Promise} Promise for an array of {@link Zotero.Translator} objects
|
||||||
*/
|
*/
|
||||||
"getTranslators":function(getAllTranslators, checkSetTranslator) {
|
getTranslators: Zotero.Promise.method(function (getAllTranslators, checkSetTranslator) {
|
||||||
var potentialTranslators;
|
var potentialTranslators;
|
||||||
|
|
||||||
// do not allow simultaneous instances of getTranslators
|
// do not allow simultaneous instances of getTranslators
|
||||||
|
@ -1115,68 +1115,74 @@ Zotero.Translate.Base.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if detection returns immediately, return found translators
|
// if detection returns immediately, return found translators
|
||||||
var me = this;
|
|
||||||
return potentialTranslators.then(function(result) {
|
return potentialTranslators.then(function(result) {
|
||||||
var allPotentialTranslators = result[0];
|
var allPotentialTranslators = result[0];
|
||||||
var properToProxyFunctions = result[1];
|
var properToProxyFunctions = result[1];
|
||||||
me._potentialTranslators = [];
|
this._potentialTranslators = [];
|
||||||
me._foundTranslators = [];
|
this._foundTranslators = [];
|
||||||
|
|
||||||
// this gets passed out by Zotero.Translators.getWebTranslatorsForLocation() because it is
|
// this gets passed out by Zotero.Translators.getWebTranslatorsForLocation() because it is
|
||||||
// specific for each translator, but we want to avoid making a copy of a translator whenever
|
// specific for each translator, but we want to avoid making a copy of a translator whenever
|
||||||
// possible.
|
// possible.
|
||||||
me._properToProxyFunctions = properToProxyFunctions ? properToProxyFunctions : null;
|
this._properToProxyFunctions = properToProxyFunctions ? properToProxyFunctions : null;
|
||||||
me._waitingForRPC = false;
|
this._waitingForRPC = false;
|
||||||
|
|
||||||
for(var i=0, n=allPotentialTranslators.length; i<n; i++) {
|
for(var i=0, n=allPotentialTranslators.length; i<n; i++) {
|
||||||
var translator = allPotentialTranslators[i];
|
var translator = allPotentialTranslators[i];
|
||||||
if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER) {
|
if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER) {
|
||||||
me._potentialTranslators.push(translator);
|
this._potentialTranslators.push(translator);
|
||||||
} else if(me instanceof Zotero.Translate.Web && Zotero.Connector) {
|
} else if (this instanceof Zotero.Translate.Web && Zotero.Connector) {
|
||||||
me._waitingForRPC = true;
|
this._waitingForRPC = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach handler for translators, so that we can return a
|
// Attach handler for translators, so that we can return a
|
||||||
// promise that provides them.
|
// promise that provides them.
|
||||||
// TODO make me._detect() return a promise
|
// TODO make this._detect() return a promise
|
||||||
var deferred = Zotero.Promise.defer(),
|
var deferred = Zotero.Promise.defer();
|
||||||
translatorsHandler = function(obj, translators) {
|
var translatorsHandler = function(obj, translators) {
|
||||||
me.removeHandler("translators", translatorsHandler);
|
this.removeHandler("translators", translatorsHandler);
|
||||||
deferred.resolve(translators);
|
deferred.resolve(translators);
|
||||||
}
|
}.bind(this);
|
||||||
me.setHandler("translators", translatorsHandler);
|
this.setHandler("translators", translatorsHandler);
|
||||||
me._detect();
|
this._detect();
|
||||||
|
|
||||||
if(me._waitingForRPC) {
|
if(this._waitingForRPC) {
|
||||||
// Try detect in Zotero Standalone. If this fails, it fails; we shouldn't
|
// Try detect in Zotero Standalone. If this fails, it fails; we shouldn't
|
||||||
// get hung up about it.
|
// get hung up about it.
|
||||||
Zotero.Connector.callMethod("detect", {"uri":me.location.toString(),
|
Zotero.Connector.callMethod(
|
||||||
"cookie":me.document.cookie,
|
"detect",
|
||||||
"html":me.document.documentElement.innerHTML}).then(function(rpcTranslators) {
|
{
|
||||||
me._waitingForRPC = false;
|
uri: this.location.toString(),
|
||||||
|
cookie: this.document.cookie,
|
||||||
|
html: this.document.documentElement.innerHTML
|
||||||
|
},
|
||||||
|
function (rpcTranslators) {
|
||||||
|
this._waitingForRPC = false;
|
||||||
|
|
||||||
// if there are translators, add them to the list of found translators
|
// if there are translators, add them to the list of found translators
|
||||||
if(rpcTranslators) {
|
if(rpcTranslators) {
|
||||||
for(var i=0, n=rpcTranslators.length; i<n; i++) {
|
for(var i=0, n=rpcTranslators.length; i<n; i++) {
|
||||||
rpcTranslators[i].runMode = Zotero.Translator.RUN_MODE_ZOTERO_STANDALONE;
|
rpcTranslators[i].runMode = Zotero.Translator.RUN_MODE_ZOTERO_STANDALONE;
|
||||||
}
|
}
|
||||||
me._foundTranslators = me._foundTranslators.concat(rpcTranslators);
|
this._foundTranslators = this._foundTranslators.concat(rpcTranslators);
|
||||||
}
|
}
|
||||||
|
|
||||||
// call _detectTranslatorsCollected to return detected translators
|
// call _detectTranslatorsCollected to return detected translators
|
||||||
if(me._currentState === null) {
|
if (this._currentState === null) {
|
||||||
me._detectTranslatorsCollected();
|
this._detectTranslatorsCollected();
|
||||||
}
|
}
|
||||||
});
|
}.bind(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}).catch(function(e) {
|
}.bind(this))
|
||||||
|
.catch(function(e) {
|
||||||
Zotero.logError(e);
|
Zotero.logError(e);
|
||||||
me.complete(false, e);
|
this.complete(false, e);
|
||||||
});
|
}.bind(this));
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all potential translators (without running detect)
|
* Get all potential translators (without running detect)
|
||||||
|
@ -1199,7 +1205,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
* @returns {Promise} Promise resolved with saved items
|
* @returns {Promise} Promise resolved with saved items
|
||||||
* when translation complete
|
* when translation complete
|
||||||
*/
|
*/
|
||||||
"translate": function (options = {}, ...args) { // initialize properties specific to each translation
|
translate: Zotero.Promise.method(function (options = {}, ...args) { // initialize properties specific to each translation
|
||||||
if (typeof options == 'number') {
|
if (typeof options == 'number') {
|
||||||
Zotero.debug("Translate: translate() now takes an object -- update your code", 2);
|
Zotero.debug("Translate: translate() now takes an object -- update your code", 2);
|
||||||
options = {
|
options = {
|
||||||
|
@ -1256,19 +1262,28 @@ Zotero.Translate.Base.prototype = {
|
||||||
this.translator[0] = Zotero.Translators.get(this.translator[0]);
|
this.translator[0] = Zotero.Translators.get(this.translator[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var loadPromise = this._loadTranslator(this.translator[0]);
|
// Zotero.Translators.get() returns a promise in the connectors
|
||||||
if (this.noWait) {
|
if (this.noWait && this.translator[0].then && !this.translator[0].isResolved()) {
|
||||||
if (!loadPromise.isResolved()) {
|
throw new Error("Translator promise is not resolved in noWait mode");
|
||||||
return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode"));
|
}
|
||||||
|
|
||||||
|
Zotero.Promise.resolve(this.translator[0])
|
||||||
|
.then(function (translator) {
|
||||||
|
this.translator[0] = translator;
|
||||||
|
var loadPromise = this._loadTranslator(translator);
|
||||||
|
if (this.noWait) {
|
||||||
|
if (!loadPromise.isResolved()) {
|
||||||
|
return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode"));
|
||||||
|
}
|
||||||
|
this._translateTranslatorLoaded();
|
||||||
}
|
}
|
||||||
this._translateTranslatorLoaded();
|
else {
|
||||||
}
|
loadPromise.then(() => this._translateTranslatorLoaded());
|
||||||
else {
|
}
|
||||||
loadPromise.then(() => this._translateTranslatorLoaded());
|
}.bind(this));
|
||||||
}
|
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when translator has been retrieved and loaded
|
* Called when translator has been retrieved and loaded
|
||||||
|
@ -1586,7 +1601,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
*/
|
*/
|
||||||
"_checkIfDone":function() {
|
"_checkIfDone":function() {
|
||||||
if(!this._savingItems && !this._savingAttachments.length && (!this._currentState || this._waitingForSave)) {
|
if(!this._savingItems && !this._savingAttachments.length && (!this._currentState || this._waitingForSave)) {
|
||||||
if(this.newCollections) {
|
if(this.newCollections && this._itemSaver.saveCollections) {
|
||||||
var me = this;
|
var me = this;
|
||||||
this._itemSaver.saveCollections(this.newCollections).then(function (newCollections) {
|
this._itemSaver.saveCollections(this.newCollections).then(function (newCollections) {
|
||||||
me.newCollections = newCollections;
|
me.newCollections = newCollections;
|
||||||
|
@ -1659,7 +1674,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
/**
|
/**
|
||||||
* Loads the translator into its sandbox
|
* Loads the translator into its sandbox
|
||||||
* @param {Zotero.Translator} translator
|
* @param {Zotero.Translator} translator
|
||||||
* @return {Boolean} Whether the translator could be successfully loaded
|
* @return {Promise<Boolean>} Whether the translator could be successfully loaded
|
||||||
*/
|
*/
|
||||||
"_loadTranslator": Zotero.Promise.method(function (translator) {
|
"_loadTranslator": Zotero.Promise.method(function (translator) {
|
||||||
var sandboxLocation = this._getSandboxLocation();
|
var sandboxLocation = this._getSandboxLocation();
|
||||||
|
|
|
@ -140,36 +140,36 @@ Zotero.Translator.prototype.init = function(info) {
|
||||||
/**
|
/**
|
||||||
* Load code for a translator
|
* Load code for a translator
|
||||||
*/
|
*/
|
||||||
Zotero.Translator.prototype.getCode = function() {
|
Zotero.Translator.prototype.getCode = Zotero.Promise.method(function () {
|
||||||
if(this.code) return Zotero.Promise.resolve(this.code);
|
if (this.code) return this.code;
|
||||||
|
|
||||||
var me = this;
|
|
||||||
if(Zotero.isConnector) {
|
if(Zotero.isConnector) {
|
||||||
// TODO make this a promise
|
return Zotero.Repo.getTranslatorCode(this.translatorID)
|
||||||
return Zotero.Repo.getTranslatorCode(this.translatorID).
|
.then(function (args) {
|
||||||
spread(function(code, source) {
|
var code = args[0];
|
||||||
|
var source = args[1];
|
||||||
if(!code) {
|
if(!code) {
|
||||||
throw "Code for "+me.label+" could not be retrieved";
|
throw new Error("Code for " + this.label + " could not be retrieved");
|
||||||
}
|
}
|
||||||
// Cache any translators for session, since retrieving via
|
// Cache any translators for session, since retrieving via
|
||||||
// HTTP may be expensive
|
// HTTP may be expensive
|
||||||
me.code = code;
|
this.code = code;
|
||||||
me.codeSource = source;
|
this.codeSource = source;
|
||||||
return code;
|
return code;
|
||||||
});
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
var promise = Zotero.File.getContentsAsync(this.path);
|
var promise = Zotero.File.getContentsAsync(this.path);
|
||||||
if(this.cacheCode) {
|
if(this.cacheCode) {
|
||||||
// Cache target-less web translators for session, since we
|
// Cache target-less web translators for session, since we
|
||||||
// will use them a lot
|
// will use them a lot
|
||||||
promise.then(function(code) {
|
return promise.then(function(code) {
|
||||||
me.code = code;
|
this.code = code;
|
||||||
return code;
|
return code;
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata block for a translator
|
* Get metadata block for a translator
|
||||||
|
|
|
@ -260,7 +260,7 @@ Zotero.Translators = new function() {
|
||||||
*/
|
*/
|
||||||
this.getAll = function() {
|
this.getAll = function() {
|
||||||
return this.init().then(function () {
|
return this.init().then(function () {
|
||||||
return Object.keys(_translators);
|
return Object.keys(_translators).map(id => _translators[id]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,7 +460,16 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
this.initializationDeferred.resolve();
|
this.initializationDeferred.resolve();
|
||||||
|
|
||||||
if(Zotero.isConnector) {
|
if(Zotero.isConnector) {
|
||||||
|
// Add toolbar icon
|
||||||
|
try {
|
||||||
|
Services.scriptloader.loadSubScript("chrome://zotero/content/icon.js", {}, "UTF-8");
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.Repo.init();
|
Zotero.Repo.init();
|
||||||
|
Zotero.locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Zotero.isFirstLoadThisSession) {
|
if(!Zotero.isFirstLoadThisSession) {
|
||||||
|
|
|
@ -140,7 +140,7 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on window load or when has been reloaded after switching into or out of connector
|
* Called on window load or when pane has been reloaded after switching into or out of connector
|
||||||
* mode
|
* mode
|
||||||
*/
|
*/
|
||||||
function _loadPane() {
|
function _loadPane() {
|
||||||
|
@ -160,6 +160,10 @@ var ZoteroPane = new function()
|
||||||
collectionsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true);
|
collectionsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true);
|
||||||
collectionsTree.addEventListener("click", ZoteroPane_Local.onTreeClick, true);
|
collectionsTree.addEventListener("click", ZoteroPane_Local.onTreeClick, true);
|
||||||
|
|
||||||
|
// Clear items view, so that the load registers as a new selected collection when switching
|
||||||
|
// between modes
|
||||||
|
ZoteroPane_Local.itemsView = null;
|
||||||
|
|
||||||
var itemsTree = document.getElementById('zotero-items-tree');
|
var itemsTree = document.getElementById('zotero-items-tree');
|
||||||
itemsTree.controllers.appendController(new Zotero.ItemTreeCommandController(itemsTree));
|
itemsTree.controllers.appendController(new Zotero.ItemTreeCommandController(itemsTree));
|
||||||
itemsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true);
|
itemsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true);
|
||||||
|
|
|
@ -336,9 +336,6 @@ function ZoteroService() {
|
||||||
makeZoteroContext(false);
|
makeZoteroContext(false);
|
||||||
zContext.Zotero.init(zInitOptions)
|
zContext.Zotero.init(zInitOptions)
|
||||||
.catch(function (e) {
|
.catch(function (e) {
|
||||||
dump(e + "\n\n");
|
|
||||||
Components.utils.reportError(e);
|
|
||||||
|
|
||||||
if (e === "ZOTERO_SHOULD_START_AS_CONNECTOR") {
|
if (e === "ZOTERO_SHOULD_START_AS_CONNECTOR") {
|
||||||
// if Zotero should start as a connector, reload it
|
// if Zotero should start as a connector, reload it
|
||||||
return zContext.Zotero.shutdown()
|
return zContext.Zotero.shutdown()
|
||||||
|
@ -347,9 +344,10 @@ function ZoteroService() {
|
||||||
return zContext.Zotero.init(zInitOptions);
|
return zContext.Zotero.init(zInitOptions);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
throw e;
|
dump(e + "\n\n");
|
||||||
}
|
Components.utils.reportError(e);
|
||||||
|
throw e;
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
zContext.Zotero.debug("Initialized in "+(Date.now() - start)+" ms");
|
zContext.Zotero.debug("Initialized in "+(Date.now() - start)+" ms");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user