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

Commit

Permalink
Fix bugs, add few comments, move sources into src
Browse files Browse the repository at this point in the history
  • Loading branch information
artemkonenko committed Feb 3, 2013
1 parent 2f90de7 commit 839744a
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 105 deletions.
137 changes: 69 additions & 68 deletions 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 added browser_plugins/opera/LiveRefresh_0.8.oex
Binary file not shown.
@@ -1,8 +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.5">
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="http://github.com/yadummer" email="yadummer@gmail.com">Konenko [yadummer] Artem</author>
<author href="https://github.com/dummer" email="yadummer@gmail.com">Konenko [yadummer] Artem</author>
</widget>
File renamed without changes.
Expand Up @@ -6,34 +6,37 @@ var background =
, tabs: new Array() // tabId -> tab:BrowserTab, socket:WebSocket, host, port
, Init: function()
{
window.addEventListener("load", this.onLoad(), false); // Constructor for the widget
window.addEventListener("load", this.onLoad(), false); // Call constructor after load
}
, onLoad: function()
, onLoad: function() // Constructor for the extension
{
var self = this; // The crutch for access to object into anonymous function.

var ToolbarUIItemProperties =
{
title: "LiveRefreshDev"
title: "LiveRefresh"
, icon: "img/icon.png"
, popup: {
href: "popup.html",
width: 400,
height: 40
}
};
this.button = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
this.button = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
opera.contexts.toolbar.addItem(this.button);

opera.extension.tabs.onfocus = function() { self.onFocus(); };
opera.extension.onconnect = function(event)
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;
// It's magic, but our extension drops, when we try used host and port fields
// I will try fix it in next iteration
var host = 'Localhost'; // self.tabs[tabId].host;
var port = 1025; // self.tabs[tabId].port;

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
Expand All @@ -56,7 +59,7 @@ var background =
this.updateIcon('passive');
}
}
, onMessage: function(event)
, onMessage: function(event) // Handler for incoming messages
{
var action = event.data.action;
var tabId = opera.extension.tabs.getFocused().id;
Expand All @@ -81,7 +84,6 @@ var background =
{
this.disconnect(tabId);
}

}
, connect: function(host, port, tabId)
{
Expand All @@ -95,9 +97,10 @@ var background =
}

this.tabs[tabId].socket.onopen = function () { self.onSocketOpen(); };
this.tabs[tabId].socket.onclose = function(event) { self.onSocketClose(event); };
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 ()
{
Expand All @@ -118,14 +121,9 @@ var background =
{
this.updateIcon('active');
}
, onSocketClose: function (event)
, onSocketClose: function (event, tabId)
{
if (event.wasClean) {
// Closed as normal
} else {
// Break connection
}
opera.postError('Socket closed');
this.disconnect( tabId ); // If the connection aborted we close socket
}
, onSocketMessage: function (event, refresh)
{
Expand All @@ -134,7 +132,6 @@ var background =
, onSocketError: function (error)
{
// We have the problem, but I don't know what we should do :(
opera.postError('Error');
}
, updateIcon: function (type)
{
Expand Down
@@ -1,6 +1,5 @@
$(document).ready(function() {
var source;
var self = this;
var source; // The channel for messaging

var hostField = $('form#socketform #host');
var portField = $('form#socketform #port');
Expand All @@ -9,26 +8,22 @@ $(document).ready(function() {

var update = function( status, host, port )
{
if ( status == true )
if ( status )
{
connectButton.addClass('disabled');
disconnectButton.removeClass('disabled');
hostField.attr( 'placeholder', host );
portField.attr( 'placeholder', port );
}
else
{
connectButton.removeClass('disabled');
disconnectButton.addClass('disabled');
}

hostField.attr( 'placeholder', host );
portField.attr( 'placeholder', port );
}

opera.extension.onmessage = function(event)
opera.extension.onmessage = function(event) // Initialisation after connect with background.js
{
source = event.source;

update( event.data.status, event.data.host, event.data.port );
source = event.source;
update( event.data.status, event.data.host, event.data.port );
}

connectButton.on("click",
Expand All @@ -43,7 +38,7 @@ $(document).ready(function() {
, 'port': portField.val()
} );

return window.close();
return window.close(); // Popup of Opera's extension not close in development mode. Use oex archive
});

disconnectButton.on("click",
Expand All @@ -56,6 +51,6 @@ $(document).ready(function() {
'action': 'disconnect'
} );

return window.close();
return window.close(); // Popup of Opera's extension not close in development mode. Use oex archive
});
});
File renamed without changes.

0 comments on commit 839744a

Please sign in to comment.