add support for firefox android
This commit is contained in:
@@ -126,13 +126,23 @@ async function handleContentScriptMessage({type, params, host}) {
|
||||
// prompt will be resolved with true or false
|
||||
let accept = await new Promise((resolve, reject) => {
|
||||
openPrompt = {resolve, reject}
|
||||
const url = `${browser.runtime.getURL(
|
||||
'prompt.html'
|
||||
)}?${qs.toString()}`
|
||||
|
||||
if (browser.windows) {
|
||||
browser.windows.create({
|
||||
url: `${browser.runtime.getURL('prompt.html')}?${qs.toString()}`,
|
||||
url,
|
||||
type: 'popup',
|
||||
width: 600,
|
||||
height: 600
|
||||
})
|
||||
} else {
|
||||
browser.tabs.create({
|
||||
url,
|
||||
active: true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// denied, stop here
|
||||
@@ -205,6 +215,11 @@ async function handlePromptMessage({host, type, accept, conditions}, sender) {
|
||||
|
||||
// close prompt
|
||||
if (sender) {
|
||||
if (browser.windows) {
|
||||
browser.windows.remove(sender.tab.windowId)
|
||||
} else {
|
||||
// Android Firefox
|
||||
browser.tabs.remove(sender.tab.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
const EXTENSION = 'nostrconnect'
|
||||
|
||||
// inject the script that will provide window.nostr
|
||||
let script = document.createElement('script')
|
||||
script.setAttribute('async', 'false')
|
||||
@@ -12,7 +14,7 @@ window.addEventListener('message', async message => {
|
||||
if (message.source !== window) return
|
||||
if (!message.data) return
|
||||
if (!message.data.params) return
|
||||
if (message.data.ext !== 'nos2x') return
|
||||
if (message.data.ext !== EXTENSION) return
|
||||
|
||||
// pass on to background
|
||||
var response
|
||||
@@ -28,7 +30,7 @@ window.addEventListener('message', async message => {
|
||||
|
||||
// return response
|
||||
window.postMessage(
|
||||
{id: message.data.id, ext: 'nos2x', response},
|
||||
{id: message.data.id, ext: EXTENSION, response},
|
||||
message.origin
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const EXTENSION = 'nostrconnect'
|
||||
|
||||
window.nostr = {
|
||||
_requests: {},
|
||||
_pubkey: null,
|
||||
@@ -29,7 +31,7 @@ window.nostr = {
|
||||
_call(type, params) {
|
||||
let id = Math.random().toString().slice(-4)
|
||||
console.log(
|
||||
'%c[nos2x:%c' +
|
||||
'%c[nostrconnect:%c' +
|
||||
id +
|
||||
'%c]%c calling %c' +
|
||||
type +
|
||||
@@ -48,7 +50,7 @@ window.nostr = {
|
||||
window.postMessage(
|
||||
{
|
||||
id,
|
||||
ext: 'nos2x',
|
||||
ext: EXTENSION,
|
||||
type,
|
||||
params
|
||||
},
|
||||
@@ -63,13 +65,15 @@ window.addEventListener('message', message => {
|
||||
!message.data ||
|
||||
message.data.response === null ||
|
||||
message.data.response === undefined ||
|
||||
message.data.ext !== 'nos2x' ||
|
||||
message.data.ext !== EXTENSION ||
|
||||
!window.nostr._requests[message.data.id]
|
||||
)
|
||||
return
|
||||
|
||||
if (message.data.response.error) {
|
||||
let error = new Error('nos2x: ' + message.data.response.error.message)
|
||||
let error = new Error(
|
||||
`${EXTENSION}: ` + message.data.response.error.message
|
||||
)
|
||||
error.stack = message.data.response.error.stack
|
||||
window.nostr._requests[message.data.id].reject(error)
|
||||
} else {
|
||||
@@ -77,7 +81,7 @@ window.addEventListener('message', message => {
|
||||
}
|
||||
|
||||
console.log(
|
||||
'%c[nos2x:%c' +
|
||||
'%c[nostrconnect:%c' +
|
||||
message.data.id +
|
||||
'%c]%c result: %c' +
|
||||
JSON.stringify(
|
||||
|
||||
Reference in New Issue
Block a user