Bug with duplicate "Activate Telldus Live!" menu options on TC server reconnect fixed.

This commit is contained in:
Stefan Persson 2010-12-14 13:07:39 +00:00
parent 75ece58416
commit 0b4fd7477e

View file

@ -3,6 +3,7 @@ __setupPackage__( __extension__ );
com.telldus.live = function() { com.telldus.live = function() {
var socket = null; var socket = null;
var menuId = 0; var menuId = 0;
var separatorId = 0;
var isRegistered = false; var isRegistered = false;
var supportedMethods = 0; var supportedMethods = 0;
@ -18,11 +19,10 @@ com.telldus.live = function() {
function notRegistered() { function notRegistered() {
isRegistered = false; isRegistered = false;
if (com.telldus.systray) { if (com.telldus.systray && !menuId) {
com.telldus.systray.addSeparator(); separatorId = com.telldus.systray.addSeparator();
menuId = com.telldus.systray.addMenuItem( "Activate Telldus Live!" ); menuId = com.telldus.systray.addMenuItem("Activate Telldus Live!");
com.telldus.systray.menuItem(menuId).triggered.connect(socket.activate); com.telldus.systray.menuItem(menuId).triggered.connect(socket.activate);
com.telldus.systray.addSeparator();
} }
} }
@ -39,13 +39,13 @@ com.telldus.live = function() {
function messageReceived(msg) { function messageReceived(msg) {
if (msg.name() == "turnon") { if (msg.name() == "turnon") {
com.telldus.core.turnOn( msg.argument(0).intVal() ); com.telldus.core.turnOn(msg.argument(0).intVal());
} else if (msg.name() == "turnoff") { } else if (msg.name() == "turnoff") {
com.telldus.core.turnOff( msg.argument(0).intVal() ); com.telldus.core.turnOff(msg.argument(0).intVal());
} else if (msg.name() == "dim") { } else if (msg.name() == "dim") {
com.telldus.core.dim( msg.argument(0).intVal(), msg.argument(1).intVal() ); com.telldus.core.dim(msg.argument(0).intVal(), msg.argument(1).intVal());
} else if (msg.name() == "bell") { } else if (msg.name() == "bell") {
com.telldus.core.bell( msg.argument(0).intVal() ); com.telldus.core.bell(msg.argument(0).intVal());
} }
print("Received: " + msg.name()); print("Received: " + msg.name());
} }
@ -53,7 +53,9 @@ com.telldus.live = function() {
function registered(msg) { function registered(msg) {
if (menuId > 0) { if (menuId > 0) {
com.telldus.systray.removeMenuItem(menuId); com.telldus.systray.removeMenuItem(menuId);
com.telldus.systray.removeMenuItem(separatorId);
menuId = 0; menuId = 0;
separatorId = 0;
} }
supportedMethods = msg.getInt('supportedMethods'); supportedMethods = msg.getInt('supportedMethods');
isRegistered = true; isRegistered = true;
@ -68,14 +70,14 @@ com.telldus.live = function() {
var count = com.telldus.core.getNumberOfDevices(); var count = com.telldus.core.getNumberOfDevices();
list = new LiveMessageToken(); list = new LiveMessageToken();
for(var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
var id = com.telldus.core.getDeviceId(i); var id = com.telldus.core.getDeviceId(i);
device = new LiveMessageToken(); device = new LiveMessageToken();
device.set('id', id); device.set('id', id);
device.set('name', com.telldus.core.getName(id)); device.set('name', com.telldus.core.getName(id));
device.set('methods', com.telldus.core.methods(id, supportedMethods) ); device.set('methods', com.telldus.core.methods(id, supportedMethods));
device.set('state', com.telldus.core.lastSentCommand(id, supportedMethods) ); device.set('state', com.telldus.core.lastSentCommand(id, supportedMethods));
device.set('stateValue', com.telldus.core.lastSentValue(id, supportedMethods) ); device.set('stateValue', com.telldus.core.lastSentValue(id, supportedMethods));
list.add(device); list.add(device);
} }
msg.appendToken(list); msg.appendToken(list);
@ -83,9 +85,9 @@ com.telldus.live = function() {
} }
return { //Public functions return { //Public functions
init:init init: init
} }
}(); } ();
__postInit__ = function() { __postInit__ = function() {
application.allDoneLoading.connect( com.telldus.live.init ); application.allDoneLoading.connect( com.telldus.live.init );