-
Notifications
You must be signed in to change notification settings - Fork 17
/
filtaquilla-background.js
133 lines (113 loc) · 6.27 KB
/
filtaquilla-background.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(async () => {
// main background script for FiltaQuilla
messenger.WindowListener.registerDefaultPrefs("defaults/preferences/filtaquilla.js");
// dropped ["resource", "filtaquilla", "skin/"],
messenger.WindowListener.registerChromeUrl([
["resource", "filtaquilla", "content/"], // resource://
["resource", "filtaquilla-skin", "skin/"], // make a separate resource (we can't have 2 different resources mapped to to the same name)
["content", "filtaquilla", "content/"], // chrome://path
["locale", "filtaquilla", "en", "locale/en/"],
["locale", "filtaquilla", "sv", "locale/sv/"],
["locale", "filtaquilla", "de", "locale/de/"],
["locale", "filtaquilla", "nl", "locale/nl/"],
["locale", "filtaquilla", "ru", "locale/ru/"]
]
);
messenger.WindowListener.registerOptionsPage("chrome://filtaquilla/content/options.xhtml");
/* OVERLAY CONVERSIONS */
// overlay chrome://messenger/content/messenger.xul chrome://filtaquilla/content/filtaquilla.xul
messenger.WindowListener.registerWindow("chrome://messenger/content/messenger.xhtml", "content/scripts/filtaquilla-messenger.js");
// overlay chrome://messenger/content/FilterEditor.xul chrome://filtaquilla/content/filterEditorOverlay.xul
messenger.DomContentScript.registerWindow("chrome://messenger/content/FilterEditor.xhtml", "chrome://filtaquilla/content/fq_FilterEditor.js");
messenger.WindowListener.registerWindow("chrome://messenger/content/FilterEditor.xhtml", "content/scripts/filtaquilla-filterEditor-css.js");
// overlay chrome://messenger/content/SearchDialog.xul chrome://filtaquilla/content/filterEditorOverlay.xul
messenger.DomContentScript.registerWindow("chrome://messenger/content/SearchDialog.xhtml", "chrome://filtaquilla/content/fq_FilterEditor.js");
messenger.WindowListener.registerWindow("chrome://messenger/content/SearchDialog.xhtml", "content/scripts/filtaquilla-filterEditor-css.js");
// overlay chrome://messenger/content/mailViewSetup.xul chrome://filtaquilla/content/filterEditorOverlay.xul
messenger.DomContentScript.registerWindow("chrome://messenger/content/mailViewSetup.xhtml", "chrome://filtaquilla/content/fq_FilterEditor.js");
messenger.WindowListener.registerWindow("chrome://messenger/content/mailViewSetup.xhtml", "content/scripts/filtaquilla-filterEditor-css.js");
// overlay chrome://messenger/content/virtualFolderProperties.xul chrome://filtaquilla/content/filterEditorOverlay.xul
messenger.DomContentScript.registerWindow("chrome://messenger/content/virtualFolderProperties.xhtml", "chrome://filtaquilla/content/fq_FilterEditor.js");
messenger.WindowListener.registerWindow("chrome://messenger/content/virtualFolderProperties.xhtml", "content/scripts/filtaquilla-filterEditor-css.js");
messenger.NotifyTools.onNotifyBackground.addListener(async (data) => {
const Legacy_Root = "extensions.filtaquilla.",
PrintingTools_Addon_Name = "[email protected]",
SmartTemplates_Name = "[email protected]";
let isLog = await messenger.LegacyPrefs.getPref(Legacy_Root + "debug.notifications");
if (isLog && data.func) {
console.log ("================================\n" +
"FQ BACKGROUND LISTENER received: " + data.func + "\n" +
"================================");
}
switch (data.func) {
case "printMessage": // [issue 152] - PrintingTools NG support
{
// third "options" parameter must be passed to be able to have extensionId as 1st parameter , not sure whether it requires a particular format, or null is allowed
let options = {},
msgKey = data.msgKey;
let isPrintLog = await messenger.LegacyPrefs.getPref(Legacy_Root + "debug.PrintingToolsNG");
if (isPrintLog) {
console.log("printMessage", `( '${msgKey.subject}' - ${msgKey.date.toLocaleDateString()} ${msgKey.date.toLocaleTimeString()} )`);
}
let result = await messenger.runtime.sendMessage(
PrintingTools_Addon_Name,
{
command: "printMessage",
messageHeader: msgKey
},
options
);
}
break;
case "forwardMessageST": // [issue 153] - Implement new filter action "Forward with SmartTemplate"
{
let isSTlog = await messenger.LegacyPrefs.getPref(Legacy_Root + "debug.SmartTemplates");
let result = await messenger.runtime.sendMessage(
SmartTemplates_Name,
{ command: "forwardMessageWithTemplate", messageHeader: data.msgKey, templateURL: data.fileURL }
);
if (isSTlog) {
console.log("FQ: after sending forwardMessageWithTemplate");
}
}
break;
case "replyMessageST": // [issue 153]
{
let isSTlog = await messenger.LegacyPrefs.getPref(Legacy_Root + "debug.SmartTemplates");
let result = await messenger.runtime.sendMessage(
SmartTemplates_Name,
{ command: "replyMessageWithTemplate", messageHeader: data.msgKey, templateURL: data.fileURL }
);
if (isSTlog) {
console.log("FQ: after sending replyMessageWithTemplate");
}
}
break;
case "getAddonInfo": // needed for version no.
{
let info = await messenger.management.getSelf()
return info;
}
break;
case "openLinkInTab":
// https://webextension-api.thunderbird.net/en/stable/tabs.html#query-queryinfo
{
let baseURI = data.baseURI || data.URL;
let found = await browser.tabs.query( { url:baseURI } );
if (found.length) {
let tab = found[0]; // first result
await browser.tabs.update(
tab.id,
{active:true, url: data.URL}
);
return;
}
browser.tabs.create(
{ active:true, url: data.URL }
);
}
break;
}
});
messenger.WindowListener.startListening();
})();