From dcfddac519e6bcb9842b6279ed13525ce95563ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Mon, 19 Jun 2017 12:18:48 +0300 Subject: [PATCH] Refactor Connector.callMethod calls to use the promisified form --- chrome/content/zotero/xpcom/progressWindow.js | 32 ++++++------------- .../zotero/xpcom/translation/translate.js | 14 ++++---- chrome/content/zotero/zoteroPane.js | 12 ------- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js index e565f056a..09ea7440c 100644 --- a/chrome/content/zotero/xpcom/progressWindow.js +++ b/chrome/content/zotero/xpcom/progressWindow.js @@ -404,30 +404,18 @@ Zotero.ProgressWindow = function(options = {}) { }; this.Translation.scrapingTo = function(libraryID, collection) { - if(Zotero.isConnector) { - Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) { - if(status !== 200) { - self.changeHeadline(Zotero.getString("ingester.scraping")); - } else { - self.changeHeadline(Zotero.getString("ingester.scrapingTo"), - "chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png", - response.name+"\u2026"); - } - }); + var name; + if(collection) { + name = collection.name; + } else if(libraryID) { + name = Zotero.Libraries.getName(libraryID); } else { - var name; - if(collection) { - name = collection.name; - } else if(libraryID) { - name = Zotero.Libraries.getName(libraryID); - } else { - name = Zotero.getString("pane.collections.library"); - } - - self.changeHeadline(Zotero.getString("ingester.scrapingTo"), - "chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png", - name+"\u2026"); + name = Zotero.getString("pane.collections.library"); } + + self.changeHeadline(Zotero.getString("ingester.scrapingTo"), + "chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png", + name+"\u2026"); }; this.Translation.doneHandler = function(obj, returnValue) { diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 132878102..8201141e3 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1206,12 +1206,11 @@ Zotero.Translate.Base.prototype = { uri: this.location.toString(), cookie: this.document.cookie, html: this.document.documentElement.innerHTML - }, - function (rpcTranslators) { + }).catch(() => false).then(function (rpcTranslators) { this._waitingForRPC = false; // if there are translators, add them to the list of found translators - if(rpcTranslators) { + if (rpcTranslators) { for(var i=0, n=rpcTranslators.length; i me._translateRPCComplete(obj)); } else if(runMode === Zotero.Translator.RUN_MODE_ZOTERO_SERVER) { var me = this; Zotero.API.createItem({"url":this.document.location.href.toString()}, @@ -2093,8 +2091,8 @@ Zotero.Translate.Web.prototype._translateRPCComplete = function(obj, failureCode this._runHandler("select", obj.selectItems, function(selectedItems) { Zotero.Connector.callMethod("selectItems", - {"instanceID":obj.instanceID, "selectedItems":selectedItems}, - function(obj) { me._translateRPCComplete(obj) }) + {"instanceID":obj.instanceID, "selectedItems":selectedItems}) + .then((obj) => me._translateRPCComplete(obj)) } ); } else { diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index a59e9139e..4af7e4029 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -3670,18 +3670,6 @@ var ZoteroPane = new function() * @return {Promise|false} */ this.addItemFromPage = Zotero.Promise.method(function (itemType, saveSnapshot, row) { - if(Zotero.isConnector) { - // In connector, save page via Zotero Standalone - var doc = window.content.document; - Zotero.Connector.callMethod("saveSnapshot", {"url":doc.location.toString(), - "cookie":doc.cookie, "html":doc.documentElement.innerHTML, - "skipSnapshot": saveSnapshot === false || (saveSnapshot === true ? false : undefined)}, - function(returnValue, status) { - _showPageSaveStatus(doc.title); - }); - return false; - } - if (row == undefined && this.collectionsView && this.collectionsView.selection) { row = this.collectionsView.selection.currentIndex; }