forked from jobisoft/EAS-4-TbSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.js
60 lines (47 loc) · 2.03 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
/*
* This file is part of EAS-4-TbSync.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
//no need to create namespace, we are in a sandbox
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
let thisID = "";
let onInitDoneObserver = {
observe: Task.async (function* (aSubject, aTopic, aData) {
//it is now safe to import tbsync.jsm
Components.utils.import("chrome://tbsync/content/tbsync.jsm");
//load all providers of this provider add-on into TbSync (one at a time, obey order)
yield tbSync.loadProvider(thisID, "eas", "//eas4tbsync/content/provider/eas/eas.js");
})
}
function install(data, reason) {
}
function uninstall(data, reason) {
}
function startup(data, reason) {
//possible reasons: APP_STARTUP, ADDON_ENABLE, ADDON_INSTALL, ADDON_UPGRADE, or ADDON_DOWNGRADE.
//set default prefs
let branch = Services.prefs.getDefaultBranch("extensions.tbsync.");
branch.setIntPref("eas.synclimit", 7);
branch.setIntPref("eas.maxitems", 50);
branch.setCharPref("eas.clientID.type", "TbSync");
branch.setCharPref("eas.clientID.useragent", "Thunderbird ActiveSync");
thisID = data.id;
Services.obs.addObserver(onInitDoneObserver, "tbsync.init.done", false);
//during app startup, the load of the provider will be triggered by a "tbsync.init.done" notification,
//if load happens later, we need load manually
if (reason != APP_STARTUP) {
onInitDoneObserver.observe();
}
}
function shutdown(data, reason) {
Services.obs.removeObserver(onInitDoneObserver, "tbsync.init.done");
//unload this provider add-on and all its loaded providers from TbSync
try {
tbSync.unloadProviderAddon(data.id);
} catch (e) {}
Services.obs.notifyObservers(null, "chrome-flush-caches", null);
}