Skip to content

Commit d58e909

Browse files
miczkewisch
authored andcommitted
feat: Added a notification for each operation
1 parent 20c10f3 commit d58e909

7 files changed

Lines changed: 524 additions & 5 deletions

File tree

src/_locales/en/messages.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,44 @@
118118
},
119119
"searchAccountName": {
120120
"message": "Search for keywords also within the account name"
121+
},
122+
"operationAction.move": {
123+
"message": "Moved $num_messages$ message to folder $destination$;Moved $num_messages$ messages to folder $destination$",
124+
"description": "List all plural forms for this sentence, separated by ';', following your language's plural rules. The order must match the language's pluralization pattern: singular first, then all plural variations. Example: 'apple;apples' (English), 'pomme;pommes' (French), 'jabłko;jabłka;jabłek' (Polish), 'تفاح;تفاحة;تفاحتان;تفاحات;تفاحة;تفاح' (Arabic).",
125+
"placeholders": {
126+
"num_messages": {
127+
"content": "$1"
128+
},
129+
"destination": {
130+
"content": "$2"
131+
}
132+
}
133+
},
134+
"operationAction.copy": {
135+
"message": "Copied $num_messages$ message to folder $destination$;Copied $num_messages$ messages to folder $destination$",
136+
"description": "List all plural forms for this sentence, separated by ';', following your language's plural rules. The order must match the language's pluralization pattern: singular first, then all plural variations. Example: 'apple;apples' (English), 'pomme;pommes' (French), 'jabłko;jabłka;jabłek' (Polish), 'تفاح;تفاحة;تفاحتان;تفاحات;تفاحة;تفاح' (Arabic).",
137+
"placeholders": {
138+
"num_messages": {
139+
"content": "$1"
140+
},
141+
"destination": {
142+
"content": "$2"
143+
}
144+
}
145+
},
146+
"operationAction.tag": {
147+
"message": "Tagged $num_messages$ message with tag $destination$;Tagged $num_messages$ messages with tag $destination$",
148+
"description": "List all plural forms for this sentence, separated by ';', following your language's plural rules. The order must match the language's pluralization pattern: singular first, then all plural variations. Example: 'apple;apples' (English), 'pomme;pommes' (French), 'jabłko;jabłka;jabłek' (Polish), 'تفاح;تفاحة;تفاحتان;تفاحات;تفاحة;تفاح' (Arabic).",
149+
"placeholders": {
150+
"num_messages": {
151+
"content": "$1"
152+
},
153+
"destination": {
154+
"content": "$2"
155+
}
156+
}
157+
},
158+
"notificationActive": {
159+
"message": "Show a notification for each operation"
121160
}
122161
}

src/background.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
* Portions Copyright (C) Philipp Kewisch */
55

6+
import { showNotification } from "../common/util.js";
7+
import { DEFAULT_PREFERENCES } from "./common/util.js";
8+
69
const DEFAULT_ACTION_URL = "/popup/popup.html?action=move&allowed=move,copy,goto,tag";
710

811
// Manifest v3: this needs to go into state memory or be queried for
@@ -42,7 +45,7 @@ async function spinWith(func, ...args) {
4245
}
4346

4447
async function processSelectedMessages(folder, operation="move", goToFolder=false) {
45-
let { markAsRead } = await browser.storage.local.get({ markAsRead: true });
48+
let { markAsRead, notificationActive, operationCounters } = await browser.storage.local.get({ markAsRead: DEFAULT_PREFERENCES.markAsRead, notificationActive: DEFAULT_PREFERENCES.notificationActive, operationCounters: DEFAULT_PREFERENCES.operationCounters });
4649

4750
let ops = [];
4851

@@ -53,6 +56,7 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
5356

5457
let folderId = folder.id;
5558
let messagePages;
59+
let numMessages = 0;
5660
if (tab.type == "messageDisplay") {
5761
messagePages = [browser.messageDisplay.getDisplayedMessages(tab.id)];
5862
} else if (tab.type == "mail") {
@@ -67,6 +71,8 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
6771

6872
for await (let messages of messagePages) {
6973
let ids = messages.map(message => message.id);
74+
numMessages += messages.length;
75+
operationCounters[operation] += messages.length;
7076
let op = Promise.resolve();
7177
if (markAsRead) {
7278
op = op.then(() => Promise.all(ids.map(id => browser.messages.update(id, { read: true }))));
@@ -81,6 +87,7 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
8187
ops.push(op);
8288
}
8389

90+
await browser.storage.local.set({ operationCounters });
8491
await Promise.all(ops);
8592

8693
if (majorVersion < 137) {
@@ -91,14 +98,20 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
9198
if (goToFolder) {
9299
await browser.mailTabs.update(tab.id, { displayedFolder: folderId }).catch(() => {});
93100
}
101+
102+
if (operation != "goto" && notificationActive) {
103+
showNotification(operation, numMessages, folderId);
104+
}
94105
}
95106
async function applyTags(tag) {
96-
let { markAsRead } = await browser.storage.local.get({ markAsRead: true });
97-
107+
let { markAsRead, notificationActive, operationCounters } = await browser.storage.local.get({ markAsRead: DEFAULT_PREFERENCES.markAsRead, notificationActive: DEFAULT_PREFERENCES.notificationActive, operationCounters: DEFAULT_PREFERENCES.operationCounters });
98108
let ops = [];
109+
let numMessages = 0;
99110

100111
for await (let messages of selectedMessagePages()) {
101112
let ids = messages.map(message => message.id);
113+
numMessages += messages.length;
114+
operationCounters.tag += messages.length;
102115
ops.push(Promise.all(ids.map(async (id) => {
103116
let msg = await browser.messages.get(id);
104117
let tagset = new Set(msg.tags);
@@ -114,10 +127,15 @@ async function applyTags(tag) {
114127
if (markAsRead) {
115128
data.read = true;
116129
}
130+
if (notificationActive) {
131+
showNotification("tag", numMessages, tag);
132+
}
133+
117134
return browser.messages.update(id, data);
118135
})));
119136
}
120137

138+
await browser.storage.local.set({ operationCounters });
121139
await Promise.all(ops);
122140
}
123141

0 commit comments

Comments
 (0)