Skip to content

Commit bc1b315

Browse files
committed
chore: Implement double-click notification management in background and content scripts
1 parent 27d4fa2 commit bc1b315

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

scripts/background.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const MESSAGE_ACTIONS = {
5151
DELETE_OBJECT_URL: "deleteObjectURL",
5252
};
5353

54+
let doubleClickNotificationShown = false;
55+
5456
// ============================================================================
5557
// CONTEXT MENU MANAGEMENT
5658
// ============================================================================
@@ -323,6 +325,17 @@ async function handleRuntimeMessage(message, sender, sendResponse) {
323325
});
324326
break;
325327

328+
case "checkDoubleClickNotification":
329+
return Promise.resolve({ alreadyShown: doubleClickNotificationShown });
330+
331+
case "markDoubleClickNotificationShown":
332+
doubleClickNotificationShown = true;
333+
return Promise.resolve({ success: true });
334+
335+
case "clearDoubleClickNotification":
336+
doubleClickNotificationShown = false;
337+
return Promise.resolve({ success: true });
338+
326339
default:
327340
return false;
328341
}

scripts/content_script.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,23 @@ async function handleImageDoubleClickValidation() {
118118
if (isEnabled) {
119119
return isEnabled;
120120
} else {
121-
let notificationCount = parseInt(
122-
sessionStorage.getItem("doubleClickNotificationCount") || "0"
123-
);
121+
// Query the background script for notification state
122+
const response = await browser.runtime.sendMessage({
123+
action: "checkDoubleClickNotification",
124+
});
124125

125-
if (notificationCount < 2) {
126+
if (!response.alreadyShown) {
126127
const errorMessage =
127128
"Download por duplo clique desativado. Acesse as configurações.";
128129
showToast(errorMessage, TOAST_TYPES.ERROR);
129130

130-
notificationCount++;
131-
sessionStorage.setItem(
132-
"doubleClickNotificationCount",
133-
notificationCount.toString()
134-
);
131+
// Tell background script we've shown the notification
132+
browser.runtime.sendMessage({
133+
action: "markDoubleClickNotificationShown",
134+
});
135135
}
136+
137+
return false;
136138
}
137139
}
138140

scripts/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function handleSettingsButtonClick() {
2626
async function updateDoubleClickSetting(isEnabled) {
2727
try {
2828
await browser.storage.local.set({ doubleClickEnabled: isEnabled });
29+
30+
await browser.runtime.sendMessage({
31+
action: "clearDoubleClickNotification",
32+
});
2933
} catch (error) {
3034
console.error("Error updating double click setting:", error);
3135
}

scripts/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ async function addNewSuffix(suffixes) {
8383
async function updateDoubleClickSetting(isEnabled) {
8484
try {
8585
await browser.storage.local.set({ doubleClickEnabled: isEnabled });
86+
87+
await browser.runtime.sendMessage({
88+
action: "clearDoubleClickNotification",
89+
});
8690
} catch (error) {
8791
console.error("Error updating double click setting:", error);
8892
}

0 commit comments

Comments
 (0)