-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiangyu
committed
Dec 15, 2022
1 parent
7de5e38
commit 6f752cd
Showing
8 changed files
with
440 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,23 @@ | ||
import AddonEvents from "./events"; | ||
import AddonPrefs from "./prefs"; | ||
import AddonUtils from "./utils"; | ||
import AddonViews from "./views"; | ||
|
||
const { addonName } = require("../package.json"); | ||
|
||
class Addon { | ||
public Zotero: _ZoteroConstructable; | ||
public events: AddonEvents; | ||
public views: AddonViews; | ||
public prefs: AddonPrefs; | ||
public utils: AddonUtils; | ||
// root path to access the resources | ||
public rootURI: string; | ||
|
||
constructor() { | ||
this.events = new AddonEvents(this); | ||
this.views = new AddonViews(this); | ||
this.prefs = new AddonPrefs(this); | ||
this.utils = new AddonUtils(this); | ||
} | ||
} | ||
|
||
function getZotero(): _ZoteroConstructable { | ||
if (typeof Zotero === "undefined") { | ||
return Components.classes["@zotero.org/Zotero;1"].getService( | ||
Components.interfaces.nsISupports | ||
).wrappedJSObject; | ||
} | ||
return Zotero; | ||
} | ||
|
||
function isZotero7(): boolean { | ||
return Zotero.platformMajorVersion >= 102; | ||
} | ||
|
||
function createXULElement(doc: Document, type: string): XUL.Element { | ||
if (isZotero7()) { | ||
// @ts-ignore | ||
return doc.createXULElement(type); | ||
} else { | ||
return doc.createElementNS( | ||
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", | ||
type | ||
) as XUL.Element; | ||
} | ||
} | ||
|
||
export { addonName, Addon, getZotero, isZotero7, createXULElement }; | ||
export default Addon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Addon, getZotero } from "./addon"; | ||
import Addon from "./addon"; | ||
|
||
const Zotero = getZotero(); | ||
const Zotero = Components.classes["@zotero.org/Zotero;1"].getService( | ||
Components.interfaces.nsISupports | ||
).wrappedJSObject; | ||
|
||
if (!Zotero.AddonTemplate) { | ||
Zotero.AddonTemplate = new Addon(); | ||
Zotero.AddonTemplate.events.onInit(); | ||
Zotero.AddonTemplate.events.onInit(Zotero); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.