add basic dev boostrap

This commit is contained in:
VillanCh
2024-03-21 09:23:52 +08:00
parent acb8307c98
commit 96141b9d30
6 changed files with 257 additions and 19 deletions
+10 -5
View File
@@ -40,15 +40,20 @@ heartbeat()
setInterval(heartbeat, 3000)
console.info("Chrome Extenstion Background is loaded")
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === "connectWebsocket") {
if (msg.action === "connect") {
console.info("Start to connect websocket")
connectWebsocket(msg.url)
} else if (msg.action === "init") {
const host = msg['host'] || "127.0.0.1"
const port = msg['port'] || 11212
connectWebsocket(`ws://${host}:${port}/?token=${"a"}`)
} else if (msg.action === 'disconnect') {
disconnectWebsocket()
} else if (msg.action === "status") {
if (socket) {
chrome.runtime.sendMessage({status: "connected"})
chrome.runtime.sendMessage({connected: true})
} else {
chrome.runtime.sendMessage({status: "initialized"})
chrome.runtime.sendMessage({connected: false})
}
}
})