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

feat: add action badge to show active status #127

Merged
merged 1 commit into from
Mar 7, 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
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