From 80e8f2cc42a80197d6bc191fac752bae2e604df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Meller?= Date: Thu, 2 Nov 2023 18:54:43 +0100 Subject: [PATCH] Fixed some errors Fixed #10, #11 Fixed some errors being thrown and not catched Fixed method missing from options.js Fixed inline images context menu being disabled all the time --- CHANGELOG.md | 12 ++++++++++++ api/shrunked.js | 3 +-- background.js | 23 ++++++++++++++++++----- compose_script.js | 3 ++- content/options.js | 9 +++++++++ manifest.json | 2 +- 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad9a86a..e8857a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ # Changelog + + +## v5.61 + +- Fixed wrong version in manifest (#10) +- Fixed some errors being thrown to console (including #11) - added catch to promises and included checking of logging enabled +- Fixed inline image context menu being disabled all the time + +## v5.6 + +- Added quality slider to options window (#8) + ## v5.5a - Removed strict_max_version from manifest, checked briefly with Thunderbird v115.0 and it seems to be working fine diff --git a/api/shrunked.js b/api/shrunked.js index 3a38ce3..84fac1f 100644 --- a/api/shrunked.js +++ b/api/shrunked.js @@ -73,7 +73,7 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI { composeMenuItem.label = localeData.localizeMessage("context.unsupportedFile"); } } - composeMenuItem.disabled=true; + composeMenuItem.disabled=isDisabled; }); @@ -375,7 +375,6 @@ function changeExtensionIfNeeded(filename) { } else return src; - } function imageIsAccepted(url) { let src = url.toLowerCase(); diff --git a/background.js b/background.js index 882cac5..2d8aff0 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,5 @@ var tabMap = new Map(); - +let logenabled=true; async function shouldResize(attachment, checkSize = true) { if (!attachment.name.toLowerCase().match(/((\.jpe?g)|(\.png)|(\.bmp))$/)) { return false; @@ -14,7 +14,7 @@ async function shouldResize(attachment, checkSize = true) { //check options on start and forward the logenabled setting to shrunked api loadOptions().then((response)=> { - let logenabled=response.logenabled; + logenabled=response.logenabled; if(logenabled) console.info("Shrunked Extension: Debug is enabled"); browser.shrunked.setDebug(logenabled); @@ -63,9 +63,10 @@ browser.compose.onAttachmentAdded.addListener(async (tab, attachment) => { let file = await browser.compose.getAttachmentFile(attachment.id); let destFile = await beginResize(tab, file); - if (destFile === null) { + if (destFile === null || destFile === undefined) { return; } + await browser.compose.updateAttachment(tab.id, attachment.id, { file: destFile, name: changeExtensionIfNeeded(destFile.name) @@ -76,7 +77,10 @@ browser.compose.onAttachmentAdded.addListener(async (tab, attachment) => { browser.shrunked.onComposeContextClicked.addListener(async (tab, file) => { tabMap.delete(tab.id); return new Promise((resolve, reject) => { - beginResize(tab, file, false).then(resolve, reject); + beginResize(tab, file, false).then(resolve, reject).catch(error => { + if(logenabled) + console.error('onComposeContextClicked', error); + }); showOptionsDialog(tab); }); }); @@ -98,7 +102,10 @@ browser.shrunked.onAttachmentContextClicked.addListener(async (tab, indicies) => return; } browser.compose.updateAttachment(tab.id, a.id, { file: destFile, name: changeExtensionIfNeeded(destFile.name) }); - }); + }).catch(error => { + if(logenabled) + console.error('onAttachmentContextClicked', error); + });; } } @@ -126,6 +133,9 @@ browser.compose.onBeforeSend.addListener(async (tab, details) => { return; } await browser.compose.updateAttachment(tab.id, a.id, { file: destFile, name: changeExtensionIfNeeded(destFile.name) }); + }).catch(error => { + if(logenabled) + console.error('onBeforeSend', error); }); promises.push(promise); } @@ -155,6 +165,9 @@ function beginResize(tab, file, notification = true) { } else { browser.shrunked.showNotification(tab, 0); } + }).catch(error => { + if(logenabled) + console.error('beginResize', error); }); } diff --git a/compose_script.js b/compose_script.js index 8ce2d98..58d5428 100644 --- a/compose_script.js +++ b/compose_script.js @@ -137,7 +137,8 @@ async function maybeResizeInline(target) { target.removeAttribute("height"); target.setAttribute("shrunked:resized", "true"); } catch (ex) { - console.error(ex); + if (logenabled) + console.error(ex); } } else if (target.nodeType == Node.ELEMENT_NODE) { if (logenabled) diff --git a/content/options.js b/content/options.js index 54a53d3..03a8626 100644 --- a/content/options.js +++ b/content/options.js @@ -225,3 +225,12 @@ b_cancel.addEventListener("click", async () => { let thisWindow = await browser.windows.getCurrent(); browser.windows.remove(thisWindow.id); }); +function changeExtensionIfNeeded(filename) { + let src = filename.toLowerCase(); + //if it is a bmp we will save it as jpeg + if (src.startsWith("data:image/bmp") || src.endsWith(".bmp")) { + return src.replace("bmp", "jpg"); + } + else + return src; +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index de989e1..3392914 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "5.5", + "version": "5.62", "applications": { "gecko": { "id": "shrunked@mllr.pl",