Working state
* Options working * Junk and trash cleaning working * Done notification working
This commit is contained in:
parent
b19d1a0038
commit
f89dcc8b1e
@ -3,20 +3,54 @@
|
||||
//
|
||||
"use strict";
|
||||
|
||||
async function runTasks() {
|
||||
let prefs = await getPrefs();
|
||||
console.log("Empty 'em: Emptying.. Start");
|
||||
|
||||
//
|
||||
// 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";
|
||||
|
||||
browser.notifications.create("emptyem-done-notify", {
|
||||
"type": "basic",
|
||||
"iconUrl": browser.extension.getURL("icons/icon.png"),
|
||||
"title": "Empty 'em done!",
|
||||
"message": msg
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Browser actions
|
||||
function emptyEm() {
|
||||
console.log("Empty-em: Emptying.. Start");
|
||||
browser.folder_actions.emptyTrashFolders();
|
||||
browser.folder_actions.emptyJunkFolders();
|
||||
console.log("Empty-em: Emptying.. Done");
|
||||
|
||||
// TODO: Do this on done event
|
||||
browser.notifications.create("emptyem-done-notify", {
|
||||
"type": "basic",
|
||||
"iconUrl": browser.extension.getURL("icons/icon.png"),
|
||||
"title": "Empty 'em done!",
|
||||
"message": "Cleaned Trash and Junk folders"
|
||||
});
|
||||
runTasks();
|
||||
}
|
||||
|
||||
// Handlers
|
||||
|
@ -96,9 +96,7 @@ this.folder_actions = class extends ExtensionAPI {
|
||||
}
|
||||
|
||||
debugMsg(msg) {
|
||||
if (this.provider.options.consoleDebug > 0) {
|
||||
console.log(msg);
|
||||
}
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
getFolderInfo() {
|
||||
@ -160,26 +158,26 @@ this.folder_actions = class extends ExtensionAPI {
|
||||
return {
|
||||
folder_actions: {
|
||||
|
||||
emptyFolder: function(folderName) {
|
||||
emptyFolder: async function(folderName) {
|
||||
let finfo = self.getFolderInfo();
|
||||
},
|
||||
|
||||
emptyTrashFolders: function() {
|
||||
emptyTrashFolders: async function() {
|
||||
let finfo = self.getFolderInfo();
|
||||
finfo.map(function(info) {
|
||||
finfo.map(async function(info) {
|
||||
if (info.trashFolder) {
|
||||
self.debugMsg("emptyTrashFolders: Considering " + info.trashFolder.URI);
|
||||
self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.trashFolder.canDeleteMessages);
|
||||
self.debugMsg("emptyTrashFolders: hasSubFolders? " + info.trashFolder.hasSubFolders);
|
||||
self.debugMsg(info.trashFolder);
|
||||
info.trashFolder.emptyTrash(null,null);
|
||||
await info.trashFolder.emptyTrash(null,null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
emptyJunkFolders: function() {
|
||||
emptyJunkFolders: async function() {
|
||||
let finfo = self.getFolderInfo();
|
||||
finfo.map(function(info) {
|
||||
finfo.map(async function(info) {
|
||||
if (info.junkFolder) {
|
||||
self.debugMsg("emptyTrashFolders: Considering " + info.junkFolder.URI);
|
||||
self.debugMsg("emptyTrashFolders: canDeleteMessages? " + info.junkFolder.canDeleteMessages);
|
||||
@ -194,7 +192,7 @@ this.folder_actions = class extends ExtensionAPI {
|
||||
junk_msgs.appendElement(msg_hdr, false);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -31,7 +31,7 @@
|
||||
},
|
||||
|
||||
"background": {
|
||||
"scripts": ["data/actions.js"]
|
||||
"scripts": ["data/jquery.min.js", "data/common.js", "data/actions.js"]
|
||||
},
|
||||
|
||||
"experiment_apis": {
|
||||
|
Loading…
Reference in New Issue
Block a user