add request permission button
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import { havePermission } from "./permissions";
|
||||
import { havePermission, addPermissionListener } from "./permissions";
|
||||
|
||||
async function init() {
|
||||
let hasAlreadySetup = false;
|
||||
|
||||
async function setupContentScript() {
|
||||
if (await havePermission('tabs')) {
|
||||
if (hasAlreadySetup) return;
|
||||
hasAlreadySetup = true;
|
||||
|
||||
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
browser.tabs.executeScript(tabId, {
|
||||
file: 'content_script/input_tools.js',
|
||||
@@ -16,4 +21,5 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
addPermissionListener(setupContentScript);
|
||||
setupContentScript();
|
||||
|
||||
@@ -5,6 +5,7 @@ import "./content-script";
|
||||
|
||||
import { handleNewRandomAlias } from "./create-alias";
|
||||
import { handleOnClickContextMenu } from "./context-menu";
|
||||
import { firePermissionListener } from "./permissions";
|
||||
|
||||
global.isBackgroundJS = true;
|
||||
|
||||
@@ -30,6 +31,8 @@ browser.runtime.onMessage.addListener(async function (request, sender) {
|
||||
return await handleNewRandomAlias(sender.tab);
|
||||
} else if (request.tag === "GET_APP_SETTINGS") {
|
||||
return await handleGetAppSettings();
|
||||
} else if (request.tag === "PERMISSIONS_CHANGED") {
|
||||
return await firePermissionListener();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
const listeners = [];
|
||||
|
||||
function addPermissionListener(callback) {
|
||||
listeners.push(callback);
|
||||
}
|
||||
|
||||
function firePermissionListener() {
|
||||
listeners.forEach(callback => callback());
|
||||
}
|
||||
|
||||
async function havePermission(name) {
|
||||
return await browser.permissions.contains({
|
||||
permissions: [ name ],
|
||||
@@ -8,10 +18,11 @@ async function havePermission(name) {
|
||||
}
|
||||
|
||||
async function requestPermission(name) {
|
||||
return await browser.permissions.request({
|
||||
const result = await browser.permissions.request({
|
||||
permissions: [ name ],
|
||||
origins: [ 'http://*/*', 'https://*/* '],
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export { havePermission, requestPermission };
|
||||
export { havePermission, requestPermission, addPermissionListener, firePermissionListener };
|
||||
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<button @click="askTabsPermission()">Request Tabs Permission</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import { havePermission, requestPermission } from '../background/permissions';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
},
|
||||
methods: {
|
||||
async askTabsPermission() {
|
||||
if (await requestPermission('tabs')) {
|
||||
// TODO: hide ask permission button
|
||||
alert('accepted');
|
||||
const _browser = window.chrome || browser;
|
||||
_browser.runtime.sendMessage({ tag: "PERMISSIONS_CHANGED" });
|
||||
} else {
|
||||
// TODO: show warning
|
||||
alert('refused');
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>SimpleLogin Extension</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
import Vue from "vue";
|
||||
import Onboarding from "./Onboarding";
|
||||
import "./styles.scss";
|
||||
|
||||
/* eslint-disable no-new */
|
||||
new Vue({
|
||||
el: "#app",
|
||||
render: (h) => h(Onboarding),
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
margin: 0 0;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ const config = {
|
||||
entry: {
|
||||
'background': './background/index.js',
|
||||
'popup/popup': './popup/popup.js',
|
||||
'onboarding/index': './onboarding/index.js',
|
||||
},
|
||||
output: {
|
||||
path: __dirname + '/dist',
|
||||
@@ -87,6 +88,7 @@ const config = {
|
||||
{ from: 'images', to: 'images' },
|
||||
{ from: 'content_script', to: 'content_script' },
|
||||
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
||||
{ from: 'onboarding/index.html', to: 'onboarding/index.html' },
|
||||
{
|
||||
from: 'manifest.json',
|
||||
to: 'manifest.json',
|
||||
|
||||
Reference in New Issue
Block a user