Skip to content

Commit

Permalink
Merge branch 'master' of ssh://gitlab.papers.tech:10022/papers/airgap…
Browse files Browse the repository at this point in the history
…/beacon-extension
  • Loading branch information
pascuin committed Feb 27, 2020
2 parents f53a88f + 302c310 commit 69bdf0c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 26 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "5.0.0",
"airgap-coin-lib": "0.7.3-beta.0",
"airgap-coin-lib": "0.7.3-beta.1",
"angular2-qrcode": "^2.0.3",
"bignumber.js": "^9.0.0",
"bip39": "^3.0.2",
Expand Down
10 changes: 10 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ export class AppComponent {
this.beaconRequest(deserialized)
}
})

chrome.runtime.sendMessage({ data: 'Handshake' })
chrome.runtime.onMessage.addListener((message, _sender, _sendResponse) => {
console.log('GOT DATA FROM BACKGROUND', message.data)
const serializer = new Serializer()

const deserialized = serializer.deserialize(message.data) as BaseMessage

this.beaconRequest(deserialized)
})
}

public async beaconRequest(request: BaseMessage): Promise<void> {
Expand Down
84 changes: 62 additions & 22 deletions src/extension/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,70 @@ const sendToPage = (data: string): void => {
})
}

const connectToPopup = cb => {
chrome.runtime.onConnect.addListener(port => {
port.onMessage.addListener((message, sender) => {
console.log('Popup message!', message, sender)
cb()
})
port.onDisconnect.addListener(async _event => {
console.log('Popup disconnected!')
})
port.postMessage('MY MESSAGE')
})
}
let popupId: number | undefined

// const connectToPopup = cb => {
// chrome.runtime.onConnect.addListener(port => {
// port.onMessage.addListener((message, sender) => {
// console.log('Popup message!', message, sender)
// cb()
// })
// port.onDisconnect.addListener(async _event => {
// console.log('Popup disconnected!')
// })
// port.postMessage('MY MESSAGE')
// })
// }

const queue: any[] = []

chrome.runtime.onMessage.addListener(function(message, _sender, _sendResponse) {
console.log('got message from popup', message)
while (queue.length > 0) {
console.log('items in queue', queue.length)
const item = queue.pop()
chrome.runtime.sendMessage({ data: item })
}
})

const openPopup = message => {
return new Promise((resolve, _reject) => {
chrome.windows.create({
url: `./index.html/#/home/?d=${message.payload}`,
type: 'popup',
height: 680,
width: 420
})
connectToPopup(res => {
resolve(res)
})
if (popupId) {
chrome.windows.update(popupId, { focused: true })
console.log('sending message')
chrome.runtime.sendMessage({ data: message })
console.log(' message sent')

return
}
const cb = currentPopup => {
popupId = currentPopup.id
console.log('popupInfo', currentPopup)
}

chrome.windows.onRemoved.addListener(removedPopupId => {
console.log('popup removed!', removedPopupId)
popupId = undefined
})

return new Promise((_resolve, _reject) => {
const POPUP_HEIGHT: number = 680
const POPUP_WIDTH: number = 420

queue.push(message.payload)

chrome.windows.create(
{
url: `${chrome.extension.getURL('index.html')}`,
type: 'popup',
focused: true,
height: POPUP_HEIGHT,
width: POPUP_WIDTH
},
cb
)
// connectToPopup(res => {
// resolve(res)
// })
})
}

Expand Down

0 comments on commit 69bdf0c

Please sign in to comment.