Skip to content

Commit

Permalink
Merge pull request #58 from rodolfomiranda/host_permisions
Browse files Browse the repository at this point in the history
Manifest update and timer set/reset
  • Loading branch information
rodolfomiranda committed Jan 12, 2024
2 parents 785e6f5 + fc7dedc commit 16c6ea2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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

0 comments on commit 16c6ea2

Please sign in to comment.