Skip to content

Commit

Permalink
Fixed some errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
memeller committed Nov 2, 2023
1 parent 7eb877f commit 80e8f2c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions api/shrunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI {
composeMenuItem.label = localeData.localizeMessage("context.unsupportedFile");
}
}
composeMenuItem.disabled=true;
composeMenuItem.disabled=isDisabled;

});

Expand Down Expand Up @@ -375,7 +375,6 @@ function changeExtensionIfNeeded(filename) {
}
else
return src;

}
function imageIsAccepted(url) {
let src = url.toLowerCase();
Expand Down
23 changes: 18 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
});
});
Expand All @@ -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);
});;
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -155,6 +165,9 @@ function beginResize(tab, file, notification = true) {
} else {
browser.shrunked.showNotification(tab, 0);
}
}).catch(error => {
if(logenabled)
console.error('beginResize', error);
});
}

Expand Down
3 changes: 2 additions & 1 deletion compose_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "5.5",
"version": "5.62",
"applications": {
"gecko": {
"id": "[email protected]",
Expand Down

0 comments on commit 80e8f2c

Please sign in to comment.