diff --git a/.gitignore b/.gitignore index 4d29575..2e4a1ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies diff --git a/package.json b/package.json index 0c13926..f6a3650 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", + "watch": "react-scripts build - -watch", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/public/background.js b/public/background.js new file mode 100644 index 0000000..d57c301 --- /dev/null +++ b/public/background.js @@ -0,0 +1,54 @@ +let socket; +const connectWebsocket = url => { + disconnectWebsocket() + socket = new WebSocket(url); + socket.onopen = () => { + chrome.runtime.sendMessage({status: "connected"}) + } + socket.onclose = () => { + chrome.runtime.sendMessage({status: "disconnected"}) + } +} + +const disconnectWebsocket = () => { + if (socket) { + try { + socket.close() + socket = null; + } catch (e) { + + } + } +} + +heartbeat = () => { + if (socket) { + if (socket.readyState === WebSocket.OPEN) { + try { + socket.send(JSON.stringify({ + "type": "heartbeat", + })) + } catch (e) { + console.error("Error sending heartbeat:", e); + } + } else { + disconnectWebsocket() + } + } +} +heartbeat() +setInterval(heartbeat, 3000) + +console.info("Chrome Extenstion Background is loaded") +chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { + if (msg.action === "connectWebsocket") { + console.info("Start to connect websocket") + connectWebsocket(msg.url) + } else if (msg.action === "init") { + if (socket) { + chrome.runtime.sendMessage({status: "connected"}) + } else { + chrome.runtime.sendMessage({status: "initialized"}) + } + } +}) diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100644 index a11777c..0000000 Binary files a/public/favicon.ico and /dev/null differ diff --git a/public/images/icon128.png b/public/images/icon128.png new file mode 100644 index 0000000..7df3a1c Binary files /dev/null and b/public/images/icon128.png differ diff --git a/public/images/icon16.png b/public/images/icon16.png new file mode 100644 index 0000000..a6ef813 Binary files /dev/null and b/public/images/icon16.png differ diff --git a/public/images/icon48.png b/public/images/icon48.png new file mode 100644 index 0000000..b59b6e6 Binary files /dev/null and b/public/images/icon48.png differ diff --git a/public/images/yakitlogo.png b/public/images/yakitlogo.png new file mode 100644 index 0000000..a2fa6f9 Binary files /dev/null and b/public/images/yakitlogo.png differ diff --git a/public/index.html b/public/index.html index aa069f2..8408e7a 100644 --- a/public/index.html +++ b/public/index.html @@ -1,43 +1,13 @@ -
- - - - - - - - - + + + +
- Edit src/App.js and save to reload.
-