mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 18:13:25 +00:00
add permission page
This commit is contained in:
28
src/hooks/usePermission.ts
Normal file
28
src/hooks/usePermission.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export async function hasPermission() {
|
||||
return chrome.permissions.contains({
|
||||
origins: ['<all_urls>'],
|
||||
});
|
||||
}
|
||||
|
||||
export function usePermission() {
|
||||
const [permission, setPermission] = useState(false);
|
||||
|
||||
const grantPermission = async () => {
|
||||
const granted = await chrome.permissions.request({
|
||||
origins: ['<all_urls>'],
|
||||
});
|
||||
setPermission(granted);
|
||||
return granted;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
hasPermission().then((has) => setPermission(has));
|
||||
}, []);
|
||||
|
||||
return {
|
||||
hasPermission: permission,
|
||||
grantPermission,
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user