Skip to content

Commit

Permalink
move resource: and skin: urls
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Jan 3, 2024
1 parent f616c2f commit 1e5d37f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions Zotero7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
34 changes: 22 additions & 12 deletions bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand All @@ -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) {
Expand Down Expand Up @@ -96,16 +91,26 @@ export async function install(): Promise<void> {
log('Installed')
}

let chromeHandle
export async function startup({ id, version, resourceURI, rootURI = resourceURI.spec }): Promise<void> {

Check warning on line 95 in bootstrap.ts

View workflow job for this annotation

GitHub Actions / release

Object pattern argument should be typed

Check warning on line 95 in bootstrap.ts

View workflow job for this annotation

GitHub Actions / release

Object pattern argument should be typed
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
Expand All @@ -128,6 +133,11 @@ export async function startup({ id, version, resourceURI, rootURI = resourceURI.
export function shutdown() {

Check warning on line 133 in bootstrap.ts

View workflow job for this annotation

GitHub Actions / release

Missing return type on function

Check warning on line 133 in bootstrap.ts

View workflow job for this annotation

GitHub Actions / release

Missing return type on function
log('Shutting down')

if (typeof chromeHandle !== 'undefined') {
chromeHandle.destruct()
chromeHandle = undefined
}

if (Zotero.EdTechHub) {
try {
Zotero.EdTechHub.shutdown()
Expand Down
4 changes: 0 additions & 4 deletions chrome.manifest
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes
11 changes: 9 additions & 2 deletions lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class EdTechHubMain {
public uninstalled = false

ui(win : Window) {
debug('building UI')
const doc = win.document

const NAMESPACE = {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file removed skin/overlay.css
Empty file.

0 comments on commit 1e5d37f

Please sign in to comment.