Skip to content

Commit

Permalink
Merge pull request #127 from HunnySajid/feat/action-badge
Browse files Browse the repository at this point in the history
feat: add action badge to show active status
  • Loading branch information
rodolfomiranda committed Mar 7, 2024
2 parents 71584aa + 92e270f commit d12fd39
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
28 changes: 23 additions & 5 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ console.log("Background script loaded");
chrome.runtime.onStartup.addListener(function () {
(async () => {
const vendorData = await configService.getData();
if(vendorData?.icon) {
setActionIcon(vendorData?.icon)
if (vendorData?.icon) {
setActionIcon(vendorData?.icon);
}
})()
})();

return true;
});
Expand Down Expand Up @@ -52,6 +52,24 @@ chrome.runtime.onMessage.addListener(function (
message.subtype
);

if (
message.type === "action-icon" &&
message.subtype === "set-action-icon"
) {
chrome.action.setBadgeBackgroundColor({ color: "#008000" }, () => {
chrome.action.setBadgeText({ text: "^" });
sendResponse({ data: { success: true } });
});
}

if (
message.type === "action-icon" &&
message.subtype === "unset-action-icon"
) {
chrome.action.setBadgeText({ text: "" });
sendResponse({ data: { success: true } });
}

if (
message.type === "vendor-info" &&
message.subtype === "get-vendor-data"
Expand All @@ -75,7 +93,7 @@ chrome.runtime.onMessage.addListener(function (
const resp = await (await fetch(vendorUrl)).json();
if (resp?.agentUrl) {
await configService.setAgentUrl(resp?.agentUrl);
await configService.setHasOnboarded(true)
await configService.setHasOnboarded(true);
}
await configService.setData(resp);
if (resp?.icon) {
Expand All @@ -102,7 +120,7 @@ chrome.runtime.onMessage.addListener(function (
});
return;
}

const signedHeaders = await signifyService.signHeaders(
// sigin can either have identifier or credential
autoSignin?.identifier
Expand Down
19 changes: 15 additions & 4 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ window.addEventListener(
case TAB_STATE.SELECT_CREDENTIAL:
case TAB_STATE.SELECT_ID_CRED:
case TAB_STATE.SELECT_AUTO_SIGNIN:
await chrome.runtime.sendMessage<IMessage<void>>({
type: "action-icon",
subtype: "set-action-icon",
});
const respVendorData = await chrome.runtime.sendMessage<
IMessage<void>
>({
Expand Down Expand Up @@ -192,10 +196,7 @@ function insertDialog(
signins={signins}
autoSigninObjExists={!!autoSigninObj}
eventType={eventType}
handleRemove={() => {
removeDialog();
setTabState(TAB_STATE.NONE);
}}
handleRemove={resetTabState}
/>
</LocaleProvider>
);
Expand All @@ -204,6 +205,16 @@ function insertDialog(
function removeDialog() {
const element = document.getElementById("__root");
if (element) element.remove();

chrome.runtime.sendMessage<IMessage<void>>({
type: "action-icon",
subtype: "unset-action-icon",
});
}

export function resetTabState() {
removeDialog();
setTabState(TAB_STATE.NONE);
}

// TODO: proper types for these params
Expand Down
7 changes: 2 additions & 5 deletions src/pages/dialog/signin.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { styled } from "styled-components";
import { Button, Text, Subtext } from "@components/ui";
import { TAB_STATE } from "@pages/popup/constants";
import { setTabState } from "@pages/content";
import { resetTabState } from "@pages/content";
import { ISignin } from "@config/types";

const StyledSigninItem = styled.div`
Expand All @@ -19,9 +18,7 @@ export const SigninItem = ({ signin }: { signin: ISignin }): JSX.Element => {
signin: signin,
},
});
const element = document.getElementById("__root");
if (element) element.remove();
setTabState(TAB_STATE.NONE);
resetTabState();
// Communicate headers to web page
window.postMessage({ type: "signify-signature", data: headers.data }, "*");
};
Expand Down

0 comments on commit d12fd39

Please sign in to comment.