fix notifications for people who haven't allowed them.
This commit is contained in:
@@ -12,7 +12,8 @@ import {Mutex} from 'async-mutex'
|
|||||||
import {
|
import {
|
||||||
NO_PERMISSIONS_REQUIRED,
|
NO_PERMISSIONS_REQUIRED,
|
||||||
getPermissionStatus,
|
getPermissionStatus,
|
||||||
updatePermission
|
updatePermission,
|
||||||
|
showNotification
|
||||||
} from './common'
|
} from './common'
|
||||||
|
|
||||||
const {encrypt, decrypt} = nip04
|
const {encrypt, decrypt} = nip04
|
||||||
@@ -101,44 +102,11 @@ async function handleContentScriptMessage({type, params, host}) {
|
|||||||
if (allowed === true) {
|
if (allowed === true) {
|
||||||
// authorized, proceed
|
// authorized, proceed
|
||||||
releasePromptMutex()
|
releasePromptMutex()
|
||||||
browser.notifications
|
showNotification(host, allowed, type, params)
|
||||||
.create(undefined, {
|
|
||||||
type: 'basic',
|
|
||||||
title: `${type} allowed for ${host}`,
|
|
||||||
message: JSON.stringify(
|
|
||||||
params?.event
|
|
||||||
? {
|
|
||||||
kind: params.event.kind,
|
|
||||||
content: params.event.content,
|
|
||||||
tags: params.event.tags
|
|
||||||
}
|
|
||||||
: params,
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
),
|
|
||||||
iconUrl: 'icons/48x48.png'
|
|
||||||
})
|
|
||||||
.then(console.log)
|
|
||||||
.catch(console.log)
|
|
||||||
} else if (allowed === false) {
|
} else if (allowed === false) {
|
||||||
// denied, just refuse immediately
|
// denied, just refuse immediately
|
||||||
releasePromptMutex()
|
releasePromptMutex()
|
||||||
browser.notifications.create(undefined, {
|
showNotification(host, allowed, type, params)
|
||||||
type: 'basic',
|
|
||||||
title: `${type} denied for ${host}`,
|
|
||||||
message: JSON.stringify(
|
|
||||||
params?.event
|
|
||||||
? {
|
|
||||||
kind: params.event.kind,
|
|
||||||
content: params.event.content,
|
|
||||||
tags: params.event.tags
|
|
||||||
}
|
|
||||||
: params,
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
),
|
|
||||||
iconUrl: 'icons/denied48.png'
|
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
error: 'denied'
|
error: 'denied'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,3 +91,26 @@ export async function removePermissions(host, accept, type) {
|
|||||||
delete policies[host]?.[accept]?.[type]
|
delete policies[host]?.[accept]?.[type]
|
||||||
browser.storage.local.set({policies})
|
browser.storage.local.set({policies})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function showNotification(host, answer, type, params) {
|
||||||
|
let ok = await browser.storage.local.get('notifications')
|
||||||
|
if (ok) {
|
||||||
|
let action = answer ? 'allowed' : 'denied'
|
||||||
|
browser.notifications.create(undefined, {
|
||||||
|
type: 'basic',
|
||||||
|
title: `${type} ${action} for ${host}`,
|
||||||
|
message: JSON.stringify(
|
||||||
|
params?.event
|
||||||
|
? {
|
||||||
|
kind: params.event.kind,
|
||||||
|
content: params.event.content,
|
||||||
|
tags: params.event.tags
|
||||||
|
}
|
||||||
|
: params,
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
),
|
||||||
|
iconUrl: 'icons/48x48.png'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nos2x",
|
"name": "nos2x",
|
||||||
"description": "Nostr Signer Extension",
|
"description": "Nostr Signer Extension",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"homepage_url": "https://github.com/fiatjaf/nos2x",
|
"homepage_url": "https://github.com/fiatjaf/nos2x",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"icons": {
|
"icons": {
|
||||||
|
|||||||
Reference in New Issue
Block a user