Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions extension/background.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
importScripts 'utils.js'

# TODO:
# - Add a config page to set port (and possibly host) of the server.

Expand All @@ -13,7 +15,7 @@ handleRequest = (sock) -> ({data}) ->
sock.send JSON.stringify extend request, response: ["ok"], error: false

else
obj = window
obj = self
for property in path.split "."
try
obj = obj[property]
Expand All @@ -32,7 +34,12 @@ reTryConnect = ->
console.log "disconnected, retry connection in #{config.timeout}ms..."
setTimeout tryConnect, config.timeout

sock = null

tryConnect = ->
if(sock && (sock.readyState == WebSocket.OPEN || sock.readyState == WebSocket.CONNECTING))
return

reTryFunction = makeIdempotent reTryConnect
try
url = "ws://#{config.host}:#{config.port}/"
Expand All @@ -43,5 +50,9 @@ tryConnect = ->
sock.onmessage = handleRequest sock
console.log "connected: #{url}"

tryConnect()
chrome.runtime.onInstalled.addListener tryConnect
chrome.runtime.onStartup.addListener tryConnect

chrome.alarms.create 'keepAlive', periodInMinutes: 0.4
chrome.alarms.onAlarm.addListener (alarm) ->
tryConnect() if alarm.name == 'keepAlive'
14 changes: 7 additions & 7 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Chromix-Too",
"version": "0.0.2",
"manifest_version": 2,
"version": "0.0.3",
"manifest_version": 3,
"description": "Command-line or scripted access to chrome's extension API.",

"permissions": [
Expand All @@ -13,13 +13,13 @@
"sessions",
"notifications",
"webNavigation",
"alarms"
],
"host_permissions": [
"<all_urls>"
],

"background": { "scripts":
[
"utils.js",
"background.js"
]
"background": {
"service_worker": "background.js"
}
}
2 changes: 1 addition & 1 deletion extension/utils.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
root = exports ? window
root = exports ? self

extend = root.extend = (hash1, hash2) ->
hash1[key] = hash2[key] for own key of hash2
Expand Down