-
Notifications
You must be signed in to change notification settings - Fork 8
/
bootstrap.js
64 lines (54 loc) · 2.25 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-disable @typescript-eslint/no-unused-vars */
var chromeHandle;
async function startup({ id, version, resourceURI, rootURI }, reason) {
await Zotero.initializationPromise;
Zotero.debug('~~~~~~ __addonName__ startup ~~~~~~');
var aomStartup = Cc['@mozilla.org/addons/addon-manager-startup;1'].getService(Ci.amIAddonManagerStartup);
var manifestURI = Services.io.newURI(rootURI + 'manifest.json');
chromeHandle = aomStartup.registerChrome(manifestURI, [
['locale', '__addonName__', 'en-US', rootURI + 'locale/en-US/'],
['locale', '__addonName__', 'zh-CN', rootURI + 'locale/zh-CN/'],
['locale', '__addonName__', 'ja-JP', rootURI + 'locale/ja-JP/'],
['locale', '__addonName__', 'it-IT', rootURI + 'locale/it-IT/'],
['content', '__addonName__', rootURI + 'content/'],
]);
const resProto = Cc['@mozilla.org/network/protocol;1?name=resource'].getService(
Ci.nsISubstitutingProtocolHandler,
),
uri = Services.io.newURI(rootURI + 'content/');
Zotero.debug(uri);
resProto.setSubstitutionWithFlags('__addonName__', uri, resProto.ALLOW_CONTENT_ACCESS);
const window = Zotero.getMainWindow();
// Global variables for plugin code
const ctx = {
rootURI,
// window,
// document: window.document,
// ZoteroPane: Zotero.getActiveZoteroPane(),
// Zotero_Tabs: window.Zotero_Tabs,
};
try {
Services.scriptloader.loadSubScript(rootURI + 'content/__addonName__.js', ctx);
} catch (error) {
window.console.debug(error);
}
addon.init();
}
async function onMainWindowLoad({ window }, reason) {
addon.init(window);
}
async function onMainWindowUnload({ window }, reason) {
window.document.querySelector('[href="chartero-prefs.ftl"]')?.remove();
}
async function shutdown({ id, version, resourceURI, rootURI }, reason) {
addon.log(reason);
if (reason === APP_SHUTDOWN) return;
await addon.unload();
// eslint-disable-next-line mozilla/use-services
Cc['@mozilla.org/intl/stringbundle;1'].getService(Ci.nsIStringBundleService).flushBundles();
Cu.unload(rootURI + 'content/__addonName__.js');
if (chromeHandle) {
chromeHandle.destruct();
chromeHandle = null;
}
}