diff --git a/src/popup/components/Header.tsx b/src/popup/components/Header.tsx index 6055909b..314b2796 100644 --- a/src/popup/components/Header.tsx +++ b/src/popup/components/Header.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import browser from 'webextension-polyfill'; +import browser, { type Permissions } from 'webextension-polyfill'; import { useLocation } from 'react-router-dom'; import { ClassValue } from 'clsx'; import { LucideIcon, RotateCcw } from 'lucide-react'; @@ -7,6 +7,7 @@ import { Link } from 'react-router-dom'; import { ArrowLeft, List, Settings } from 'lucide-react'; import remote from '@/remote'; import { Button } from './ui/button'; +import { askOriginPermissions } from '@/utils'; type iconProps = { to: string; @@ -41,24 +42,30 @@ const HeaderIcon = (props: iconProps) => { const Banner = (props: BannerProps) => { if (!props.remoteAvailable) return ( -
+
Remote not available
); const [alarms, setAlarms] = useState([]); - + const [permissions, setPermissions] = useState( + {} + ); useEffect(() => { const fetchAlarms = async () => { const alarms = await browser.alarms.getAll(); setAlarms(alarms); }; + const fetchPermissions = async () => { + setPermissions(await browser.permissions.getAll()); + }; fetchAlarms(); + fetchPermissions(); }, []); if (alarms.length === 0) return ( -
+
Something went wrong, please restart the extension.
); + if (permissions.origins && permissions.origins.length === 0) + return ( +
+ Pop-a-loon is missing recommended permissions. + +
+ ); + return null; }; @@ -94,7 +118,7 @@ export default (props: HeaderProps) => { return ( <> -
+
{location.pathname !== '/' && }
diff --git a/src/utils.ts b/src/utils.ts index a0e722e4..f5f7bfb4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -130,3 +130,12 @@ export async function importStylesheet(id: string, href: string) { document.head.appendChild(style); } } + +export async function askOriginPermissions() { + const host_permissions = await browser.runtime.getManifest().host_permissions; + if (!host_permissions) return log.error('No host_permissions found'); + const permissions = await browser.permissions.request({ + origins: host_permissions, + }); + log.debug('Permissions granted for', permissions); +}