27 lines
754 B
TypeScript
27 lines
754 B
TypeScript
import { Colors } from "../deps.ts";
|
|
|
|
export const checkPermOrExit = (name: string, err: string) =>
|
|
Deno.permissions.query({ name: name as any }).then((res) => {
|
|
if (res.state !== "granted") {
|
|
console.log(Colors.bold(Colors.red(err)));
|
|
Deno.exit(1);
|
|
}
|
|
});
|
|
|
|
export const requestPermOrExit = (name: string, err: string) => {
|
|
Deno.permissions
|
|
.query({ name: name as any })
|
|
.then((res) => {
|
|
if (res.state === "prompt") {
|
|
return Deno.permissions.request({ name: name as any });
|
|
}
|
|
return res;
|
|
})
|
|
.then((res) => {
|
|
if (res.state !== "granted") {
|
|
console.log(Colors.bold(Colors.red(err)));
|
|
Deno.exit(1);
|
|
}
|
|
});
|
|
};
|