I'm trying to write a little of code for a custom button (using Custom Buttons ext.) that performs the following steps:
- enable quick filter for unread messages
- select all of them
- apply filters to selected messages
- disable quick filtering of unread messages
My script should wait for each step to be executed before executing next one.
To accomplish this, I've tried to use Promise, as explained here https://developer.mozilla.org/en-US/doc ... m/Examples
But this doesn't work, I think because I can't just turn something asynchronous into a promise... or maybe I do it wrong.
This is what I have:
Code: Select all
var promiseFilter = promiseApplyFiltersToSelection();
promiseFilter.then(
function(success) {
gFolderDisplay.clearSelection();
alert(uneval(success));
},
function(failure) {
alert("Something went wrong while applying filters: " + uneval(failure));
}
);
function promiseApplyFiltersToSelection() {
try {
document.getElementById("qfb-unread").click(); // select all unread
goDoCommand("cmd_applyFiltersToSelection"); // apply filters
return Promise.resolve('Filters applied'); // this makes the success function trigger
} catch(ex) {
return Promise.reject(ex);
}
}
Anyone can explain and/or point me in the right direction?
TIA,
rash*