Permalink
Browse files

Merge pull request #2 from dummer/master

Extension for Opera
thanks @dummer
  • Loading branch information...
2 parents df87dd7 + 839744a commit ae820a37f05221da133a775f36c4fab4e2df5026 @phisch committed Feb 10, 2013
View
137 README.md
@@ -1,69 +1,70 @@
-# LiveRefresh - SublimeText2 Plugin
-
-Your SublimeText2 will include a websocket-server which sends a signal to all clients when you save a file.
-This repository includes the browser- extensions/plugins too.
-
-### Supported Browsers
-
-* Google Chrome
-
-## Installation
-
-You have three ways to install LiveRefresh: using git, installing it manually or using the SublimeText2 "Package Controll" (Available here: http://wbond.net/sublime_packages/package_control)
-
-### Install using git
-
-To install this Plugin via git, simply browse to your 'Packages' folder like this:
-
-for Windows
-
- cd %APPDATA%/Sublime Text 2/Packages
-
-for OS X
-
- cd ~/Library/Application Support/Sublime Text 2/Packages
-
-for Linux
-
- cd ~/.Sublime Text 2/Packages
-
-for Portable Installations
-
- cd PATH_TO_PORTABLE_INSTALLATION/Sublime Text 2/Data/Packages
-
-and clone this repository
-
- git clone https://github.com/PhilippSchaffrath/LiveRefresh
-
-
-### Install manually
-
-* Download the files using the GitHub .zip download option
-* Unzip the files and rename the folder to 'LiveRefresh'
-* Copy the folder to your Sublime Text 2 'Packages' directory
-
-### Install using Package Control (NOT AVAILABLE AT THIS MOMENT)
-
-If you are familiar with Package Control you definetly know what to do, if not, go to [SublimeText2 - Package Control](http://wbond.net/sublime_packages/package_control) click on 'Install' and follow the instructions
-
-## How it works
-
-The WebsocketServer running in SublimeText listens at port 1025. If you save a File, it will send "refresh" to all connected clients.
-
-The included Chrome Extension allows you to connect to your SublimeText2. Simply insert host and port (defaults to 127.0.0.1:1025 if empty) and click "Connect", ready to go, your browser will now refresh and focus this tab when you save a File in SublimeText2.
-
-
-## Usage
-
-* Install the SublimeText2 Plugin and restart the Application
-* Install the Browser Plugin/Extension and restart the Browser
-* Open both and start the Browser Plugin
-* Connect the Browser to your IP and let it refresh :)
-
-## Release Notes
-
-LiveRefresh is designed to work with the latest [development build](http://www.sublimetext.com/dev) of Sublime Text 2
-
-## Development
-
+# LiveRefresh - SublimeText2 Plugin
+
+Your SublimeText2 will include a websocket-server which sends a signal to all clients when you save a file.
+This repository includes the browser- extensions/plugins too.
+
+### Supported Browsers
+
+* Google Chrome
+* Opera
+
+## Installation
+
+You have three ways to install LiveRefresh: using git, installing it manually or using the SublimeText2 "Package Controll" (Available here: http://wbond.net/sublime_packages/package_control)
+
+### Install using git
+
+To install this Plugin via git, simply browse to your 'Packages' folder like this:
+
+for Windows
+
+ cd %APPDATA%/Sublime Text 2/Packages
+
+for OS X
+
+ cd ~/Library/Application Support/Sublime Text 2/Packages
+
+for Linux
+
+ cd ~/.Sublime Text 2/Packages
+
+for Portable Installations
+
+ cd PATH_TO_PORTABLE_INSTALLATION/Sublime Text 2/Data/Packages
+
+and clone this repository
+
+ git clone https://github.com/PhilippSchaffrath/LiveRefresh
+
+
+### Install manually
+
+* Download the files using the GitHub .zip download option
+* Unzip the files and rename the folder to 'LiveRefresh'
+* Copy the folder to your Sublime Text 2 'Packages' directory
+
+### Install using Package Control (NOT AVAILABLE AT THIS MOMENT)
+
+If you are familiar with Package Control you definetly know what to do, if not, go to [SublimeText2 - Package Control](http://wbond.net/sublime_packages/package_control) click on 'Install' and follow the instructions
+
+## How it works
+
+The WebsocketServer running in SublimeText listens at port 1025. If you save a File, it will send "refresh" to all connected clients.
+
+The included Chrome Extension allows you to connect to your SublimeText2. Simply insert host and port (defaults to 127.0.0.1:1025 if empty) and click "Connect", ready to go, your browser will now refresh and focus this tab when you save a File in SublimeText2.
+
+
+## Usage
+
+* Install the SublimeText2 Plugin and restart the Application
+* Install the Browser Plugin/Extension and restart the Browser
+* Open both and start the Browser Plugin
+* Connect the Browser to your IP and let it refresh :)
+
+## Release Notes
+
+LiveRefresh is designed to work with the latest [development build](http://www.sublimetext.com/dev) of Sublime Text 2
+
+## Development
+
The intension behind this, was because of personal sloth. If you want any new features or plugins or something, feel free to contact me, but also feel free to do them on your own. I cant promise to add any new functionallity.
Binary file not shown.
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets"
+ id="https://github.com/PhilippSchaffrath/LiveRefresh"
+ version="0.8">
+ <name>LiveRefresh</name>
+ <description>Lets you independently connect your tabs to WebSocket-Server. Each time, a tab received "refresh" it will focus and refresh.</description>
+ <author href="https://github.com/dummer" email="yadummer@gmail.com">Konenko [yadummer] Artem</author>
+</widget>

Large diffs are not rendered by default.

Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,8 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <script type="text/javascript" src="/js/background.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
@@ -0,0 +1,147 @@
+// Sorry for bad english in the comments :) [dummer]
+
+var background =
+{
+ button: null // Widget button
+ , tabs: new Array() // tabId -> tab:BrowserTab, socket:WebSocket, host, port
+ , Init: function()
+ {
+ window.addEventListener("load", this.onLoad(), false); // Call constructor after load
+ }
+ , onLoad: function() // Constructor for the extension
+ {
+ var self = this; // The crutch for access to object into anonymous function.
+
+ var ToolbarUIItemProperties =
+ {
+ title: "LiveRefresh"
+ , icon: "img/icon.png"
+ , popup: {
+ href: "popup.html",
+ width: 400,
+ height: 40
+ }
+ };
+ this.button = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
+ opera.contexts.toolbar.addItem(this.button);
+
+ opera.extension.tabs.onfocus = function() { self.onFocus(); }; // Action for each switching tabs
+ opera.extension.onconnect = function(event) // Post message to popup with status connection of current tab
+ {
+ var tabId = opera.extension.tabs.getFocused().id;
+ var status = self.tabs[tabId] != undefined;
+
+ var host, port;
+ if (status) // If connection exist, we write current host/port to inputs placeholder
+ {
+ host = self.tabs[tabId].host;
+ port = self.tabs[tabId].port;
+ }
+
+ event.source.postMessage( {
+ 'tabId': tabId
+ , 'status': status
+ , 'host': host
+ , 'port': port
+ } );
+ }
+
+ opera.extension.onmessage = function(event) { self.onMessage(event); };
+ }
+ , onFocus: function () // Handler for changing the active tab
+ {
+ if ( this.tabs[opera.extension.tabs.getFocused().id] != undefined )
+ {
+ this.updateIcon('active');
+ }
+ else
+ {
+ this.updateIcon('passive');
+ }
+ }
+ , onMessage: function(event) // Handler for incoming messages
+ {
+ var action = event.data.action;
+ var tabId = opera.extension.tabs.getFocused().id;
+
+ if ( action == 'connect' )
+ {
+ var host = event.data.host;
+ var port = event.data.port;
+
+ if (host.length == 0)
+ {
+ host = 'localhost';
+ }
+ if (port.length == 0)
+ {
+ port = '1025';
+ }
+
+ this.connect(host, port, tabId);
+ }
+ else if ( action == 'disconnect' )
+ {
+ this.disconnect(tabId);
+ }
+ }
+ , connect: function(host, port, tabId)
+ {
+ var self = this; // The crutche for access to object into anonymous function.
+
+ this.tabs[tabId] = {
+ 'tab': opera.extension.tabs.getFocused()
+ , 'socket': new WebSocket('ws://' + host + ':' + port)
+ , 'host': host
+ , 'port': port
+ }
+
+ this.tabs[tabId].socket.onopen = function () { self.onSocketOpen(); };
+ this.tabs[tabId].socket.onclose = function(event) { self.onSocketClose( event, tabId ); };
+ this.tabs[tabId].socket.onmessage = function(event)
+ {
+ // Refreshing the target tab after receive message through socket
+ self.onSocketMessage( event,
+ function ()
+ {
+ self.tabs[tabId].tab.refresh();
+ }
+ );
+ };
+ this.tabs[tabId].socket.onerror = function(event) { self.onSocketError(event); };
+ }
+ , disconnect: function(tabId)
+ {
+ this.tabs[tabId].socket.onclose = function(event) {};
+ this.tabs[tabId].socket.close();
+ this.tabs[tabId] = null;
+ this.updateIcon('passive');
+ }
+ , onSocketOpen: function ()
+ {
+ this.updateIcon('active');
+ }
+ , onSocketClose: function (event, tabId)
+ {
+ this.disconnect( tabId ); // If the connection aborted we close socket
+ }
+ , onSocketMessage: function (event, refresh)
+ {
+ refresh();
+ }
+ , onSocketError: function (error)
+ {
+ // We have the problem, but I don't know what we should do :(
+ }
+ , updateIcon: function (type)
+ {
+ if (type == 'active')
+ {
+ this.button.icon = "img/icon_active.png";
+ } else {
+ this.button.icon = "img/icon.png";
+ }
+ }
+};
+
+background.Init();

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,56 @@
+$(document).ready(function() {
+ var source; // The channel for messaging
+
+ var hostField = $('form#socketform #host');
+ var portField = $('form#socketform #port');
+ var connectButton = $('form#socketform #connect');
+ var disconnectButton = $('form#socketform #disconnect');
+
+ var update = function( status, host, port )
+ {
+ if ( status )
+ {
+ connectButton.addClass('disabled');
+ hostField.attr( 'placeholder', host );
+ portField.attr( 'placeholder', port );
+ }
+ else
+ {
+ disconnectButton.addClass('disabled');
+ }
+ }
+
+ opera.extension.onmessage = function(event) // Initialisation after connect with background.js
+ {
+ source = event.source;
+ update( event.data.status, event.data.host, event.data.port );
+ }
+
+ connectButton.on("click",
+ function(e)
+ {
+ e.preventDefault();
+ if ($(e.target).hasClass("disabled")) { return; }
+
+ source.postMessage( {
+ 'action': 'connect'
+ , 'host': hostField.val()
+ , 'port': portField.val()
+ } );
+
+ return window.close(); // Popup of Opera's extension not close in development mode. Use oex archive
+ });
+
+ disconnectButton.on("click",
+ function(e)
+ {
+ e.preventDefault();
+ if ($(e.target).hasClass("disabled")) { return; }
+
+ source.postMessage( {
+ 'action': 'disconnect'
+ } );
+
+ return window.close(); // Popup of Opera's extension not close in development mode. Use oex archive
+ });
+});
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+ <head>
+ <title>LiveRefresh</title>
+ <style>
+ body {
+ overflow-x:hidden;
+ padding: 5px;
+ width: 400px;
+ }
+ form#socketform { margin: 0; }
+ </style>
+
+ <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
+ <script src="js/libs/jquery-1.8.3.min.js"></script>
+ <script src="js/plugin.js"></script>
+ </head>
+ <body>
+ <form id="socketform" class="form-inline">
+ <div >
+ <input class="span2" type="text" id="host" placeholder="Host"/>
+ <input class="span1" type="text" id="port" placeholder="Port"/>
+
+ <button class="btn btn-primary" type="submit" id="connect">Connect</button>
+ <button class="btn" type="submit" id="disconnect">Disconnect</button>
+ </div>
+ </form>
+ </body>
+</html>

0 comments on commit ae820a3

Please sign in to comment.