Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add trycatch and persist actionIcon #125

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import {

console.log("Background script loaded");

chrome.runtime.onStartup.addListener(function () {
(async () => {
const vendorData = await configService.getData();
if(vendorData?.icon) {
setActionIcon(vendorData?.icon)
}
})()

return true;
});

chrome.runtime.onInstalled.addListener(function (object) {
if (object.reason === chrome.runtime.OnInstalledReason.INSTALL) {
console.log("Signify Browser Extension installed");
Expand Down Expand Up @@ -297,7 +308,7 @@ chrome.runtime.onMessage.addListener(function (
const aidIssuee = indentifiers.aids.find((aid: IIdentifier) => {
return aid.prefix === issueePrefix;
});
credential.issueeName = aidIssuee.name;
credential.issueeName = aidIssuee?.name;
});

sendResponse({ data: { credentials: credentials ?? [] } });
Expand Down
25 changes: 15 additions & 10 deletions src/pages/background/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const senderIsPopup = (sender: chrome.runtime.MessageSender) => {
return ((sender.url?.startsWith('moz-extension://') || sender.url?.startsWith('chrome-extension://'))&&
sender.url?.endsWith('/src/pages/popup/index.html') &&
sender.id === chrome.runtime.id);
return (
(sender.url?.startsWith("moz-extension://") ||
sender.url?.startsWith("chrome-extension://")) &&
sender.url?.endsWith("/src/pages/popup/index.html") &&
sender.id === chrome.runtime.id
);
};

export const isValidUrl = (str: string) => {
Expand Down Expand Up @@ -54,11 +57,13 @@ export const removeWhiteSpace = (s: string, replace = "") => {
};

export const setActionIcon = async (iconUrl: string) => {
const imageBlob = await fetch(iconUrl).then((r) => r.blob());
const bitmap = await createImageBitmap(imageBlob);
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
const context = canvas.getContext("2d");
context?.drawImage(bitmap, 0, 0);
const imageData = context?.getImageData(0, 0, bitmap.width, bitmap.height);
chrome.action.setIcon({ imageData: imageData });
try {
const imageBlob = await fetch(iconUrl).then((r) => r.blob());
const bitmap = await createImageBitmap(imageBlob);
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
const context = canvas.getContext("2d");
context?.drawImage(bitmap, 0, 0);
const imageData = context?.getImageData(0, 0, bitmap.width, bitmap.height);
chrome.action.setIcon({ imageData: imageData });
} catch (error) {}
};