diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-06-03 16:21:09 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-06-03 16:21:21 +0530 |
commit | e15e56c65a07b5b39c9f781099909469d65eefba (patch) | |
tree | 8559db0839b0f5c881da08d9501f63c8c7eee38c /src/webex/compat.ts | |
parent | a3354306c629ab3ab5f45617f31b90976416105a (diff) | |
download | wallet-core-e15e56c65a07b5b39c9f781099909469d65eefba.tar.xz |
make permissions work for firefox
Diffstat (limited to 'src/webex/compat.ts')
-rw-r--r-- | src/webex/compat.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/webex/compat.ts b/src/webex/compat.ts index 1cbf34a2c..4635abd80 100644 --- a/src/webex/compat.ts +++ b/src/webex/compat.ts @@ -33,3 +33,53 @@ export function isFirefox(): boolean { export function isNode(): boolean { return typeof process !== "undefined" && process.release.name === "node"; } + +/** + * Compatibility API that works on multiple browsers. + */ +export interface CrossBrowserPermissionsApi { + contains( + permissions: chrome.permissions.Permissions, + callback: (result: boolean) => void, + ): void; + + addPermissionsListener( + callback: (permissions: chrome.permissions.Permissions) => void, + ): void; + + request( + permissions: chrome.permissions.Permissions, + callback?: (granted: boolean) => void, + ): void; + + remove( + permissions: chrome.permissions.Permissions, + callback?: (removed: boolean) => void, + ): void; +} + +export function getPermissionsApi(): CrossBrowserPermissionsApi { + const myBrowser = (globalThis as any).browser; + if ( + typeof myBrowser === "object" && + typeof myBrowser.permissions === "object" + ) { + return { + addPermissionsListener: () => { + // Not supported yet. + }, + contains: myBrowser.permissions.contains, + request: myBrowser.permissions.request, + remove: myBrowser.permissions.remove, + }; + } else { + return { + addPermissionsListener: chrome.permissions.onAdded.addListener.bind( + chrome.permissions.onAdded, + ), + contains: chrome.permissions.contains, + request: chrome.permissions.request, + remove: chrome.permissions.remove, + }; + } +} |