Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Schaffrath committed Dec 30, 2012
0 parents commit 9dcc958
Show file tree
Hide file tree
Showing 33 changed files with 8,299 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
*.pyc
*.cache
*.sublime-project
.DS_Store
*.swp
*.tmp
Binary file added 32bit/select.pyd
Binary file not shown.
Binary file added 64bit/select.pyd
Binary file not shown.
9 changes: 9 additions & 0 deletions browser_plugins/chrome/src/css/bootstrap.min.css

Large diffs are not rendered by default.

Binary file added browser_plugins/chrome/src/img/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added browser_plugins/chrome/src/img/icon_active.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions browser_plugins/chrome/src/js/background.coffee
@@ -0,0 +1,126 @@
#localhost:1025
#192.169.0.2:1025

class tabFactory
constructor: () ->
@tabs = []
return

# adds a new tab instance to the tabs array
addTab: (tabId) ->
tab = new tabHandler(tabId, @)
@tabs[tabId] = tab
return tab

# sets a tab to undefinde after it called the disconnect method of it
removeTab: (tabId) ->
tab = @getTab tabId
if tab isnt false
tab.disconnect()
@tabs[tabId] = undefined
return

# returns a tab if available, else false
getTab: (tabId) ->
if @tabs[tabId] is undefined
return false
else
return @tabs[tabId]

# console.logs all tabs
logTabs: ->
console.log @tabs
return



class tabHandler
constructor: (@tabId, @factory, @isClosed = false) ->

connect: (host, port) ->
@host = if host is null or host is "" then "localhost" else host
@port = if port is null or port is "" or port > 65535 or port < 1 then 1025 else port

@socket = new WebSocket("ws://#{@host}:#{@port}")
@socket.tabHandler = @

@socket.onopen = (data) ->
@tabHandler.setTabIcon()
return

@socket.onclose = (data) ->
if not @tabHandler.getIsClosed() then @tabHandler.setTabIcon()
@tabHandler.factory.removeTab @tabHandler.tabId
return

@socket.onmessage = (data) ->
if data.data is "refresh"
chrome.tabs.update @tabHandler.tabId, {selected: true}
chrome.tabs.reload @tabHandler.tabId
return

@socket.onerror = (data) ->
return

disconnect: () ->
@socket.close()

refreshTab: () ->

setTabIcon: () ->
icon = "icon.png"
# 0: connection has not yet been established
# 1: connection is established and communication is possible
# 2: connection is going through the closing handshake
# 3: connection has been closed or could not be opened
icon = "icon_active.png" if @socket.readyState is 1
chrome.tabs.get @tabId, (tab) ->
if tab then chrome.browserAction.setIcon {path:"img/#{icon}", tabId: tab.id}

getHost: -> return @host
getPort: -> return @port
getTab: -> return @tab
getSocket: -> return @socket
getIsClosed: -> return @isClosed

setIsClosed: (closed) ->
@isClosed = closed

getInformation: () ->
return {host: @host, port: @port}


class socketStates
constructor: ->
@NONE = 0
@CONNECTING = 1
@CONNECTED = 2
@ERROR = 3


factory = new tabFactory()

connect = (host, port) ->
chrome.tabs.query {active: yes, currentWindow: yes}, (tabs) ->
tab = factory.addTab tabs[0].id
tab.connect(host, port)

disconnect = ->
chrome.tabs.query {active: yes, currentWindow: yes}, (tabs) ->
tab = factory.getTab tabs[0].id
if tab isnt false then factory.removeTab tabs[0].id

chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) ->
tab = factory.getTab tabId
if tab isnt false then tab.setTabIcon()

chrome.tabs.onRemoved.addListener (tabId, removeInfo) ->
factory.removeTab(tabId)

chrome.extension.onMessage.addListener (request, sender, sendResponse) ->
chrome.tabs.query {active: yes, currentWindow: yes}, (tabs) ->
tab = factory.getTab tabs[0].id
if request.command is "getInformation"
if tab isnt false
sendResponse tab.getInformation()
return true
197 changes: 197 additions & 0 deletions browser_plugins/chrome/src/js/background.js

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

2 changes: 2 additions & 0 deletions browser_plugins/chrome/src/js/libs/jquery-1.8.3.min.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions browser_plugins/chrome/src/js/plugin.coffee
@@ -0,0 +1,25 @@
$(document).ready ->
background = chrome.extension.getBackgroundPage()
hostField = $('form#socketform #host')
portField = $('form#socketform #port')
connectButton = $('form#socketform #connect')
disconnectButton = $('form#socketform #disconnect')

$('#connect').on "click", (e) ->
e.preventDefault()
return if $(e.target).hasClass("disabled")
background.connect hostField.val(), portField.val()
window.close()

$('#disconnect').on "click", (e) ->
e.preventDefault()
return if $(e.target).hasClass("disabled")
background.disconnect()
window.close()


chrome.extension.sendMessage {command: "getInformation"}, (response) ->
hostField.val response.host
portField.val response.port
connectButton.addClass 'disabled'
disconnectButton.removeClass 'disabled'
34 changes: 34 additions & 0 deletions browser_plugins/chrome/src/js/plugin.js

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

0 comments on commit 9dcc958

Please sign in to comment.