-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackground.js
47 lines (42 loc) · 1.12 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { LocalStream } from 'extension-streams'
import InternalMessage from '@/messages/internal'
import * as MsgTypes from './messages/types'
export default class Background {
constructor() {
this.setupInternalMessaging()
}
setupInternalMessaging() {
console.log('messaging')
LocalStream.watch((request, sendResponse) => {
console.log(request)
const message = InternalMessage.fromJson(request)
this.dispatchMessage(sendResponse, message)
})
}
dispatchMessage(sendResponse, message) {
switch (message.type) {
case MsgTypes.TRANSFER:
this.transfer(sendResponse, message.payload)
break
}
}
transfer(sendResponse, payload) {
var promptURL = chrome.extension.getURL('pages/prompt.html')
var queryString = new URLSearchParams(payload).toString()
console.log(promptURL, queryString)
chrome.windows.create(
{
url: `${promptURL}#transfer?${queryString}`,
type: 'popup',
width: 350,
height: 623,
top: 0,
left: 0
},
() => {
sendResponse(true)
}
)
}
}
new Background()