Skip to content

Commit 1e5d37f

Browse files
committed
move resource: and skin: urls
1 parent f616c2f commit 1e5d37f

11 files changed

+34
-19
lines changed

Zotero7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ The main changes are:
99
* Stuff that lived in `EdTechHubMain.constructor` and `EdTechHubMain.init` have been moved into `EdTechHubMain.startup`, which is called on startup.
1010
* 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.
1111
* 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.
12+
* 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
1213

1314
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.

bootstrap.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
declare const dump: (msg: string) => void
44
declare const Components: any
55
declare const ChromeUtils: any
6-
declare var Services: any
7-
const {
8-
interfaces: Ci,
9-
results: Cr,
10-
utils: Cu,
11-
Constructor: CC,
12-
} = Components
6+
7+
var Services: any
138

149
if (typeof Zotero == 'undefined') {
1510
var Zotero
@@ -32,7 +27,7 @@ async function waitForZotero() {
3227
}
3328

3429
// eslint-disable-next-line @typescript-eslint/no-shadow
35-
var { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm')
30+
Services = ChromeUtils.import('resource://gre/modules/Services.jsm').Services
3631
var windows = Services.wm.getEnumerator('navigator:browser')
3732
var found = false
3833
while (windows.hasMoreElements()) {
@@ -48,8 +43,8 @@ async function waitForZotero() {
4843
var listener = {
4944
onOpenWindow(aWindow) {
5045
// Wait for the window to finish loading
51-
const domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
52-
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow)
46+
const domWindow = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
47+
.getInterface(Components.interfaces.nsIDOMWindowInternal || Components.interfaces.nsIDOMWindow)
5348
domWindow.addEventListener('load', function() {
5449
domWindow.removeEventListener('load', arguments.callee, false)
5550
if (domWindow.Zotero) {
@@ -96,16 +91,26 @@ export async function install(): Promise<void> {
9691
log('Installed')
9792
}
9893

94+
let chromeHandle
9995
export async function startup({ id, version, resourceURI, rootURI = resourceURI.spec }): Promise<void> {
10096
await waitForZotero()
10197

10298
try {
103-
log('Starting')
99+
log(`Starting ${rootURI}`)
100+
101+
if (Zotero.platformMajorVersion >= 102) { // eslint-disable-line @typescript-eslint/no-magic-numbers
102+
const aomStartup = Components.classes['@mozilla.org/addons/addon-manager-startup;1'].getService(Components.interfaces.amIAddonManagerStartup)
103+
const manifestURI = Services.io.newURI(`${rootURI}manifest.json`)
104+
chromeHandle = aomStartup.registerChrome(manifestURI, [
105+
[ 'content', 'zotero-edtechhub', 'content/' ],
106+
[ 'locale' , 'zotero-edtechhub', 'en-US' , 'locale/en-US/' ],
107+
])
108+
}
104109

105110
// 'Services' may not be available in Zotero 6
106111
if (typeof Services == 'undefined') {
107112
// eslint-disable-next-line @typescript-eslint/no-shadow
108-
var { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm')
113+
Services = ChromeUtils.import('resource://gre/modules/Services.jsm').Services
109114
}
110115

111116
// Read prefs from prefs.js when the plugin in Zotero 6
@@ -128,6 +133,11 @@ export async function startup({ id, version, resourceURI, rootURI = resourceURI.
128133
export function shutdown() {
129134
log('Shutting down')
130135

136+
if (typeof chromeHandle !== 'undefined') {
137+
chromeHandle.destruct()
138+
chromeHandle = undefined
139+
}
140+
131141
if (Zotero.EdTechHub) {
132142
try {
133143
Zotero.EdTechHub.shutdown()

chrome.manifest

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
content zotero-edtechhub content/
22
locale zotero-edtechhub en-US locale/en-US/
3-
skin zotero-edtechhub default skin/
4-
resource zotero-edtechhub resource/
5-
6-
overlay chrome://zotero/content/zoteroPane.xul chrome://zotero-edtechhub/content/overlay.xul
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class EdTechHubMain {
233233
public uninstalled = false
234234

235235
ui(win : Window) {
236+
debug('building UI')
236237
const doc = win.document
237238

238239
const NAMESPACE = {
@@ -415,7 +416,13 @@ class EdTechHubMain {
415416
flash('Zutilo not installed', 'The Zutilo plugin is not available, please install it from https://github.com/willsALMANJ/Zutilo')
416417
}
417418

418-
await this.installTranslators()
419+
try {
420+
debug('installing translators')
421+
await this.installTranslators()
422+
}
423+
catch (err) {
424+
debug(`translator installation failed: ${err}`)
425+
}
419426

420427
ready.resolve(true)
421428

@@ -607,7 +614,7 @@ class EdTechHubMain {
607614
}
608615

609616
private async installTranslator(name) {
610-
const translator: string = Zotero.File.getContentsFromURL(`resource://zotero-edtechhub/${name}`)
617+
const translator: string = Zotero.File.getContentsFromURL(`chrome://zotero-edtechhub/content/resource/${name}`)
611618
const sep = '\n}\n'
612619
const split = translator.indexOf(sep) + sep.length
613620
const header = JSON.parse(translator.slice(0, split))

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"postbuild": "zotero-plugin-zipup build zotero-edtechhub",
1010
"release": "zotero-plugin-release",
1111
"postversion": "git push --follow-tags",
12-
"start": "zotero-start"
12+
"start": "zotero-start",
13+
"beta": "zotero-start --beta"
1314
},
1415
"repository": {
1516
"type": "git",

0 commit comments

Comments
 (0)