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

Timer reset if popup is open #102

Merged
merged 1 commit into from
Feb 20, 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src/pages/background/services/signify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ import { SignifyClient, Tier, ready, Authenticater } from "signify-ts";
import { userService } from "@pages/background/services/user";
import { configService } from "@pages/background/services/config";

const PASSCODE_TIMEOUT = 5;
const PASSCODE_TIMEOUT = 1;

const Signify = () => {
let _client: SignifyClient | null;

chrome.alarms.onAlarm.addListener(async (alarm) => {
if (alarm.name == "passcode-timeout") {
console.log("Timer expired, client and passcode zeroed out");
_client = null;
await userService.removePasscode();

try {
const response = await chrome.runtime.sendMessage({type: "popup", subtype: "isOpened"});
if (response.data.isOpened) {
console.log("Timer expired, but extsenion is open. Resetting timer.");
resetTimeoutAlarm();
}
} catch (error) {
console.log("Timer expired, client and passcode zeroed out");
_client = null;
await userService.removePasscode();
}

}
});

Expand Down
11 changes: 11 additions & 0 deletions src/pages/popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ function init() {
if (!rootContainer) throw new Error("Can't find Popup root element");
const root = createRoot(rootContainer);
root.render(<Popup />);

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (sender.url === "chrome-extension://" + chrome.runtime.id+ "/service-worker-loader.js" &&
request.type === "popup" &&
request.subtype === "isOpened") {
sendResponse({data: {isOpened: true}});
}
}
);

}

init();