Skip to content

Commit

Permalink
Merge pull request #102 from rodolfomiranda/alarm_when_open
Browse files Browse the repository at this point in the history
Timer reset if popup is open
  • Loading branch information
rodolfomiranda committed Feb 20, 2024
2 parents 5846364 + e1f0824 commit 07aefe8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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();

0 comments on commit 07aefe8

Please sign in to comment.