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

Manifest update and timer set/reset #58

Merged
merged 2 commits into from
Jan 12, 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
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"permissions": [
"activeTab",
"storage",
"tabs"
"tabs",
"alarms"
],
"content_scripts": [
{
Expand All @@ -46,6 +47,6 @@
}
],
"content_security_policy": {
"extension_pages": "default-src 'self' 'wasm-unsafe-eval'; connect-src 'self' data: https://keria-dev.rootsid.cloud"
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'"
}
}
29 changes: 23 additions & 6 deletions src/pages/background/services/signify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@ 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 * 60 * 1000;
const PASSCODE_TIMEOUT = 5;

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();
}
});

const setTimeoutAlarm = () => {
chrome.alarms.create('passcode-timeout', {
delayInMinutes: PASSCODE_TIMEOUT,
});
}

const resetTimeoutAlarm = async () => {
await chrome.alarms.clear('passcode-timeout')
setTimeoutAlarm();
}


const connect = async (url: string, passcode: string) => {
await ready();
_client = new SignifyClient(url, passcode, Tier.low);
await _client.connect();
setTimeout(async () => {
console.log("Timer expired, client and passcode zeroed out");
_client = null;
await userService.removePasscode();
}, PASSCODE_TIMEOUT);
setTimeoutAlarm();
}

const isConnected = async () => {
const passcode = await userService.getPasscode();
const url = await configService.getUrl();
if (url && passcode && !_client) {
await connect(url, passcode);
await resetTimeoutAlarm();
}

console.log(_client ? "Signify client is connected" : "Signify client is not connected");
Expand Down