diff --git a/Zotero7.md b/Zotero7.md index 937f294..b74ca75 100644 --- a/Zotero7.md +++ b/Zotero7.md @@ -9,5 +9,6 @@ The main changes are: * Stuff that lived in `EdTechHubMain.constructor` and `EdTechHubMain.init` have been moved into `EdTechHubMain.startup`, which is called on startup. * Overlays don't work anymore in Zotero 7, so the UI construction has been moved into `EdTechHubMain.ui`. This adds a convenience method to create XUL elements for the ui. These have a CSS class to mark them for removal if the ETH plugin is shut down/removed. * Translations have been moved to `locale/en-US/zotero-edtechhub.ftl`. This is the new localization system for Zotero 7. It does not work for Zotero 6, so I've added a kludge; since the ETH plugin only has english translations anyway, I have the build bake the strings into the plugin. This will have to change in due time, but we can probably wait until Zotero 7 is GA and remove the kludge. Should it be necessary I have a way to load the strings for other languages, but this is simplest for now. +* Zotero 7 doesn't support resource: and skin: URLs anymore, so moved these both to content, which is still supported with the aom loader in bootstrap.ts I think this is broadly it. Please go over the code and ask about things that are unclear. The easiest way to get an overview of what changed is to run a `git diff` between the `gh-88` branch and the `master` branch. diff --git a/bootstrap.ts b/bootstrap.ts index 0c9f308..593ae06 100644 --- a/bootstrap.ts +++ b/bootstrap.ts @@ -3,13 +3,8 @@ declare const dump: (msg: string) => void declare const Components: any declare const ChromeUtils: any -declare var Services: any -const { - interfaces: Ci, - results: Cr, - utils: Cu, - Constructor: CC, -} = Components + +var Services: any if (typeof Zotero == 'undefined') { var Zotero @@ -32,7 +27,7 @@ async function waitForZotero() { } // eslint-disable-next-line @typescript-eslint/no-shadow - var { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm') + Services = ChromeUtils.import('resource://gre/modules/Services.jsm').Services var windows = Services.wm.getEnumerator('navigator:browser') var found = false while (windows.hasMoreElements()) { @@ -48,8 +43,8 @@ async function waitForZotero() { var listener = { onOpenWindow(aWindow) { // Wait for the window to finish loading - const domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow) + const domWindow = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowInternal || Components.interfaces.nsIDOMWindow) domWindow.addEventListener('load', function() { domWindow.removeEventListener('load', arguments.callee, false) if (domWindow.Zotero) { @@ -96,16 +91,26 @@ export async function install(): Promise { log('Installed') } +let chromeHandle export async function startup({ id, version, resourceURI, rootURI = resourceURI.spec }): Promise { await waitForZotero() try { - log('Starting') + log(`Starting ${rootURI}`) + + if (Zotero.platformMajorVersion >= 102) { // eslint-disable-line @typescript-eslint/no-magic-numbers + const aomStartup = Components.classes['@mozilla.org/addons/addon-manager-startup;1'].getService(Components.interfaces.amIAddonManagerStartup) + const manifestURI = Services.io.newURI(`${rootURI}manifest.json`) + chromeHandle = aomStartup.registerChrome(manifestURI, [ + [ 'content', 'zotero-edtechhub', 'content/' ], + [ 'locale' , 'zotero-edtechhub', 'en-US' , 'locale/en-US/' ], + ]) + } // 'Services' may not be available in Zotero 6 if (typeof Services == 'undefined') { // eslint-disable-next-line @typescript-eslint/no-shadow - var { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm') + Services = ChromeUtils.import('resource://gre/modules/Services.jsm').Services } // Read prefs from prefs.js when the plugin in Zotero 6 @@ -128,6 +133,11 @@ export async function startup({ id, version, resourceURI, rootURI = resourceURI. export function shutdown() { log('Shutting down') + if (typeof chromeHandle !== 'undefined') { + chromeHandle.destruct() + chromeHandle = undefined + } + if (Zotero.EdTechHub) { try { Zotero.EdTechHub.shutdown() diff --git a/chrome.manifest b/chrome.manifest index 3641565..9b6f1eb 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -1,6 +1,2 @@ content zotero-edtechhub content/ locale zotero-edtechhub en-US locale/en-US/ -skin zotero-edtechhub default skin/ -resource zotero-edtechhub resource/ - -overlay chrome://zotero/content/zoteroPane.xul chrome://zotero-edtechhub/content/overlay.xul diff --git a/resource/Bjoern2A_BjoernCitationStringTagged.js b/content/resource/Bjoern2A_BjoernCitationStringTagged.js similarity index 100% rename from resource/Bjoern2A_BjoernCitationStringTagged.js rename to content/resource/Bjoern2A_BjoernCitationStringTagged.js diff --git a/resource/Bjoern2B_BjoernCitationStringTagged.js b/content/resource/Bjoern2B_BjoernCitationStringTagged.js similarity index 100% rename from resource/Bjoern2B_BjoernCitationStringTagged.js rename to content/resource/Bjoern2B_BjoernCitationStringTagged.js diff --git a/resource/Bjoern2C_BjoernCitationStringTagged.js b/content/resource/Bjoern2C_BjoernCitationStringTagged.js similarity index 100% rename from resource/Bjoern2C_BjoernCitationStringTagged.js rename to content/resource/Bjoern2C_BjoernCitationStringTagged.js diff --git a/resource/Bjoern7_ETHref.js b/content/resource/Bjoern7_ETHref.js similarity index 100% rename from resource/Bjoern7_ETHref.js rename to content/resource/Bjoern7_ETHref.js diff --git a/skin/edtechhub.png b/content/skin/edtechhub.png similarity index 100% rename from skin/edtechhub.png rename to content/skin/edtechhub.png diff --git a/lib.ts b/lib.ts index 45e028f..28cf057 100644 --- a/lib.ts +++ b/lib.ts @@ -233,6 +233,7 @@ class EdTechHubMain { public uninstalled = false ui(win : Window) { + debug('building UI') const doc = win.document const NAMESPACE = { @@ -415,7 +416,13 @@ class EdTechHubMain { flash('Zutilo not installed', 'The Zutilo plugin is not available, please install it from https://github.com/willsALMANJ/Zutilo') } - await this.installTranslators() + try { + debug('installing translators') + await this.installTranslators() + } + catch (err) { + debug(`translator installation failed: ${err}`) + } ready.resolve(true) @@ -607,7 +614,7 @@ class EdTechHubMain { } private async installTranslator(name) { - const translator: string = Zotero.File.getContentsFromURL(`resource://zotero-edtechhub/${name}`) + const translator: string = Zotero.File.getContentsFromURL(`chrome://zotero-edtechhub/content/resource/${name}`) const sep = '\n}\n' const split = translator.indexOf(sep) + sep.length const header = JSON.parse(translator.slice(0, split)) diff --git a/package.json b/package.json index 9177d09..8a0c6fe 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "postbuild": "zotero-plugin-zipup build zotero-edtechhub", "release": "zotero-plugin-release", "postversion": "git push --follow-tags", - "start": "zotero-start" + "start": "zotero-start", + "beta": "zotero-start --beta" }, "repository": { "type": "git", diff --git a/skin/overlay.css b/skin/overlay.css deleted file mode 100644 index e69de29..0000000