From dca7dcccab900b68679a799de821f7c6340f10e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Thu, 28 Mar 2024 10:45:18 +0200 Subject: [PATCH] fx115: Changes for word processor plugin support --- .../integration/integrationDocPrefs.xhtml | 2 +- chrome/content/zotero/xpcom/integration.js | 49 ++++++++++--------- resource/word-processor-plugin-installer.js | 6 +-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/chrome/content/zotero/integration/integrationDocPrefs.xhtml b/chrome/content/zotero/integration/integrationDocPrefs.xhtml index 1317d5eff9..1c1c73186a 100644 --- a/chrome/content/zotero/integration/integrationDocPrefs.xhtml +++ b/chrome/content/zotero/integration/integrationDocPrefs.xhtml @@ -49,7 +49,7 @@ - + diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index f4df9f54a9..faa863132f 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -71,6 +71,12 @@ const TEMPLATE_VERSIONS = { const MENDELEY_URI_RE = /^http:\/\/www\.mendeley\.com\/documents\/\?uuid=(.*)/; +const PLUGIN_PATHS = { + LibreOffice: 'chrome://zotero-libreoffice-integration-components/content/zoteroLibreOfficeIntegration.mjs', + WinWord: 'chrome://zotero-winword-integration/content/zoteroWinWordIntegration.mjs', + MacWord: 'chrome://zotero-macword-integration/content/zoteroMacWordIntegration.mjs' +}; + Zotero.Integration = new function() { Components.utils.import("resource://gre/modules/Services.jsm"); @@ -84,24 +90,22 @@ Zotero.Integration = new function() { * Initialize LibreOffice, Word for Mac and Word for Windows plugin components. */ this.init = function () { - // TEMP - return; - if (Zotero.test) return; - let classNames = ["@zotero.org/Zotero/integration/initializer?agent=LibreOffice;1"]; + let entryPoints = [PLUGIN_PATHS.LibreOffice]; if (Zotero.isMac) { - classNames.push("@zotero.org/Zotero/integration/installer?agent=MacWord;1") - } else if (Zotero.isWindows) { - classNames.push("@zotero.org/Zotero/integration/initializer?agent=WinWord;1"); + entryPoints.push(PLUGIN_PATHS.MacWord); } - for (let className of classNames) { + else if (Zotero.isWindows) { + entryPoints.push(PLUGIN_PATHS.WinWord); + } + for (let entryPoint of entryPoints) { try { - Components.classes[className] - .getService(Components.interfaces.nsISupports); + const { init } = ChromeUtils.importESModule(entryPoint); + init(); } catch (e) { Zotero.logError(e); - } + } } } @@ -221,26 +225,23 @@ Zotero.Integration = new function() { } }); - this.getApplication = function(agent, command, docId) { + this.getApplication = function (agent, command, docId) { if (agent == 'http') { return new Zotero.HTTPIntegrationClient.Application(); } // Try to load the appropriate Zotero component; otherwise display an error - var component try { - var componentClass = "@zotero.org/Zotero/integration/application?agent="+agent+";1"; - Zotero.debug("Integration: Instantiating "+componentClass+" for command "+command+(docId ? " with doc "+docId : "")); - try { - return Components.classes[componentClass] - .getService(Components.interfaces.zoteroIntegrationApplication); - } catch (e) { - return Components.classes[componentClass] - .getService(Components.interfaces.nsISupports).wrappedJSObject; - } - } catch(e) { + // Replace MacWord2016 and MacWord16 with just MacWord. + agent = agent.startsWith('MacWord') ? 'MacWord' : agent; + var entryPoint = PLUGIN_PATHS[agent]; + Zotero.debug("Integration: Instantiating "+agent+" plugin handler for command "+command+(docId ? " with doc "+docId : "")); + const { Application } = ChromeUtils.importESModule(entryPoint); + return new Application(); + } + catch (e) { throw new Zotero.Exception.Alert("integration.error.notInstalled", [], "integration.error.title"); - } + } }; /** diff --git a/resource/word-processor-plugin-installer.js b/resource/word-processor-plugin-installer.js index 6ffdc13d86..877c6cd0ae 100644 --- a/resource/word-processor-plugin-installer.js +++ b/resource/word-processor-plugin-installer.js @@ -29,11 +29,7 @@ var EXPORTED_SYMBOLS = ["ZoteroPluginInstaller"]; -var Zotero = Components.classes["@zotero.org/Zotero;1"] - // Currently uses only nsISupports - //.getService(Components.interfaces.chnmIZoteroService). - .getService(Components.interfaces.nsISupports) - .wrappedJSObject; +var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); Components.utils.import("resource://gre/modules/Services.jsm");