From 32f6409ac312f31821f791c3a376168289f0e4f4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 23 Mar 2022 10:50:12 -0300 Subject: all the browser related code move into one place, making it easy for specific platform code or mocking for testing --- .../src/hooks/useExtendedPermissions.ts | 53 ++++++++++++++-------- 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts') diff --git a/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts index 6bf6a7bdf..66d710705 100644 --- a/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts +++ b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts @@ -16,7 +16,7 @@ import { useState, useEffect } from "preact/hooks"; import * as wxApi from "../wxApi"; -import { getPermissionsApi } from "../compat"; +import { platform } from "../platform/api"; import { getReadRequestPermissions } from "../permissions"; export function useExtendedPermissions(): [boolean, () => Promise] { @@ -40,24 +40,41 @@ async function handleExtendedPerm(isEnabled: boolean, onChange: (value: boolean) if (!isEnabled) { // We set permissions here, since apparently FF wants this to be done // as the result of an input event ... - return new Promise((res) => { - getPermissionsApi().request(getReadRequestPermissions(), async (granted: boolean) => { - console.log("permissions granted:", granted); - if (chrome.runtime.lastError) { - console.error("error requesting permissions"); - console.error(chrome.runtime.lastError); - onChange(false); - return; - } - try { - const res = await wxApi.setExtendedPermissions(granted); - onChange(res.newValue); - } finally { - res() - } + const granted = await platform.getPermissionsApi().request(getReadRequestPermissions()); + console.log("permissions granted:", granted); + const lastError = platform.getLastError(); + if (lastError) { + console.error("error requesting permissions"); + console.error(lastError); + onChange(false); + return; + } + // try { + const res = await wxApi.setExtendedPermissions(granted); + onChange(res.newValue); + // } finally { + // return + // } + + // return new Promise((res) => { + // platform.getPermissionsApi().request(getReadRequestPermissions(), async (granted: boolean) => { + // console.log("permissions granted:", granted); + // const lastError = getLastError() + // if (lastError) { + // console.error("error requesting permissions"); + // console.error(lastError); + // onChange(false); + // return; + // } + // try { + // const res = await wxApi.setExtendedPermissions(granted); + // onChange(res.newValue); + // } finally { + // res() + // } - }); - }) + // }); + // }) } await wxApi.setExtendedPermissions(false).then(r => onChange(r.newValue)); return -- cgit v1.2.3