Working state

* Options working
* Junk and trash cleaning working
* Done notification working
This commit is contained in:
Mahesh Asolkar 2018-10-28 18:02:36 -07:00
parent b19d1a0038
commit f89dcc8b1e
3 changed files with 55 additions and 23 deletions

View File

@ -3,20 +3,54 @@
// //
"use strict"; "use strict";
// Browser actions async function runTasks() {
function emptyEm() { let prefs = await getPrefs();
console.log("Empty-em: Emptying.. Start"); console.log("Empty 'em: Emptying.. Start");
browser.folder_actions.emptyTrashFolders();
browser.folder_actions.emptyJunkFolders(); //
console.log("Empty-em: Emptying.. Done"); // Empty Junk folders before Trash. That way, the Junk messages sent to Trash will be cleaned as well.
//
if (prefs.prefs.selectJunkDelete) {
console.log("Empty 'em: Emptying Junk folders");
await browser.folder_actions.emptyJunkFolders();
} else {
console.log("Empty 'em: Skipping Junk folders by preference");
}
//
// Empty Trash folders
//
if (prefs.prefs.selectTrashDelete) {
console.log("Empty 'em: Emptying Trash folders");
await browser.folder_actions.emptyTrashFolders();
} else {
console.log("Empty 'em: Skipping Trash folders by preference");
}
//
// Once done, send the Done notification
//
console.log("Empty 'em: Emptying.. Done");
if (prefs.prefs.disableDoneNotification) {
console.log("Empty 'em: Not sending Done notification by preference");
} else {
let msg = (prefs.prefs.selectTrashDelete && prefs.prefs.selectJunkDelete) ? "Cleaned Trash and Junk folders" :
(prefs.prefs.selectJunkDelete) ? "Cleaned Junk folders" :
(prefs.prefs.selectTrashDelete) ? "Cleaned Trash folders" :
"Nothing selected to be cleaned";
// TODO: Do this on done event
browser.notifications.create("emptyem-done-notify", { browser.notifications.create("emptyem-done-notify", {
"type": "basic", "type": "basic",
"iconUrl": browser.extension.getURL("icons/icon.png"), "iconUrl": browser.extension.getURL("icons/icon.png"),
"title": "Empty 'em done!", "title": "Empty 'em done!",
"message": "Cleaned Trash and Junk folders" "message": msg
}); });
}
}
// Browser actions
function emptyEm() {
runTasks();
} }
// Handlers // Handlers

View File

@ -96,10 +96,8 @@ this.folder_actions = class extends ExtensionAPI {
} }
debugMsg(msg) { debugMsg(msg) {
if (this.provider.options.consoleDebug > 0) {
console.log(msg); console.log(msg);
} }
}
getFolderInfo() { getFolderInfo() {
let data = []; let data = [];
@ -160,26 +158,26 @@ this.folder_actions = class extends ExtensionAPI {
return { return {
folder_actions: { folder_actions: {
emptyFolder: function(folderName) { emptyFolder: async function(folderName) {
let finfo = self.getFolderInfo(); let finfo = self.getFolderInfo();
}, },
emptyTrashFolders: function() { emptyTrashFolders: async function() {
let finfo = self.getFolderInfo(); let finfo = self.getFolderInfo();
finfo.map(function(info) { finfo.map(async function(info) {
if (info.trashFolder) { if (info.trashFolder) {
self.debugMsg("emptyTrashFolders: Considering " + info.trashFolder.URI); self.debugMsg("emptyTrashFolders: Considering " + info.trashFolder.URI);
self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.trashFolder.canDeleteMessages); self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.trashFolder.canDeleteMessages);
self.debugMsg("emptyTrashFolders: hasSubFolders? " + info.trashFolder.hasSubFolders); self.debugMsg("emptyTrashFolders: hasSubFolders? " + info.trashFolder.hasSubFolders);
self.debugMsg(info.trashFolder); self.debugMsg(info.trashFolder);
info.trashFolder.emptyTrash(null,null); await info.trashFolder.emptyTrash(null,null);
} }
}); });
}, },
emptyJunkFolders: function() { emptyJunkFolders: async function() {
let finfo = self.getFolderInfo(); let finfo = self.getFolderInfo();
finfo.map(function(info) { finfo.map(async function(info) {
if (info.junkFolder) { if (info.junkFolder) {
self.debugMsg("emptyTrashFolders: Considering " + info.junkFolder.URI); self.debugMsg("emptyTrashFolders: Considering " + info.junkFolder.URI);
self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.junkFolder.canDeleteMessages); self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.junkFolder.canDeleteMessages);
@ -194,7 +192,7 @@ this.folder_actions = class extends ExtensionAPI {
junk_msgs.appendElement(msg_hdr, false); junk_msgs.appendElement(msg_hdr, false);
} }
if (junk_msgs.length) { if (junk_msgs.length) {
info.junkFolder.deleteMessages(junk_msgs, mw, false, false, null, true); await info.junkFolder.deleteMessages(junk_msgs, mw, false, false, null, true);
} }
} }
}); });

View File

@ -31,7 +31,7 @@
}, },
"background": { "background": {
"scripts": ["data/actions.js"] "scripts": ["data/jquery.min.js", "data/common.js", "data/actions.js"]
}, },
"experiment_apis": { "experiment_apis": {