Commit 54151a3d authored by CeRiAl's avatar CeRiAl

Beautify JS-code even more

parent cfe43c5b
...@@ -144,8 +144,9 @@ var MessageQueue = function () { ...@@ -144,8 +144,9 @@ var MessageQueue = function () {
} }
} }
}(); }();
// global variables
// global variables
var storage_keys = { var storage_keys = {
"IP_ADDRESS": 0, "IP_ADDRESS": 0,
"USERNAME": 1, "USERNAME": 1,
...@@ -229,6 +230,8 @@ function handleJsonRpcError(response) { ...@@ -229,6 +230,8 @@ function handleJsonRpcError(response) {
} }
} }
} }
// player methods // player methods
function getStatus() { function getStatus() {
g_player_id = -1; g_player_id = -1;
...@@ -360,6 +363,8 @@ function stop() { ...@@ -360,6 +363,8 @@ function stop() {
function changeTransportCb(result) { function changeTransportCb(result) {
getStatus(); getStatus();
} }
// Remote methods // Remote methods
function sendKey(input_key) { function sendKey(input_key) {
switch (input_key) { switch (input_key) {
...@@ -383,6 +388,8 @@ function sendKey(input_key) { ...@@ -383,6 +388,8 @@ function sendKey(input_key) {
break; break;
} }
} }
// Goto methods // Goto methods
function gotoFullscreen() { function gotoFullscreen() {
sendJsonRequest(new JsonRpcRequest("GUI.setFullScreen", { sendJsonRequest(new JsonRpcRequest("GUI.setFullScreen", {
...@@ -423,6 +430,8 @@ function gotoWeather() { ...@@ -423,6 +430,8 @@ function gotoWeather() {
"window": "weather" "window": "weather"
})); }));
} }
// Playlist methods // Playlist methods
function getMusicPlaylists() { function getMusicPlaylists() {
sendJsonRequest(new JsonRpcRequest("Files.GetDirectory", { sendJsonRequest(new JsonRpcRequest("Files.GetDirectory", {
...@@ -469,6 +478,8 @@ function playMusicPlaylist(payload) { ...@@ -469,6 +478,8 @@ function playMusicPlaylist(payload) {
})); }));
sendJsonRequest(requests); sendJsonRequest(requests);
} }
// Addon methods // Addon methods
function getAddons() { function getAddons() {
sendJsonRequest(new JsonRpcRequest("Addons.GetAddons", { sendJsonRequest(new JsonRpcRequest("Addons.GetAddons", {
...@@ -499,6 +510,8 @@ function executeAddon(payload) { ...@@ -499,6 +510,8 @@ function executeAddon(payload) {
"addonid": addonid "addonid": addonid
})); }));
} }
// Power methods // Power methods
function systemShutdown() { function systemShutdown() {
sendJsonRequest(new JsonRpcRequest("System.Shutdown")); sendJsonRequest(new JsonRpcRequest("System.Shutdown"));
...@@ -515,128 +528,127 @@ function systemHibernate() { ...@@ -515,128 +528,127 @@ function systemHibernate() {
function systemSuspend() { function systemSuspend() {
sendJsonRequest(new JsonRpcRequest("System.Suspend")); sendJsonRequest(new JsonRpcRequest("System.Suspend"));
} }
// Event listeners // Event listeners
Pebble.addEventListener("ready", Pebble.addEventListener("ready", function (e) {
function (e) { console.log("Rockodi copyright (c) 2015, Douglas Otwell");
console.log("Rockodi copyright (c) 2015, Douglas Otwell"); g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS);
g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS); g_username = localStorage.getItem(storage_keys.USERNAME);
g_username = localStorage.getItem(storage_keys.USERNAME); g_password = localStorage.getItem(storage_keys.PASSWORD);
g_password = localStorage.getItem(storage_keys.PASSWORD); });
}
);
Pebble.addEventListener("showConfiguration", function (e) { Pebble.addEventListener("showConfiguration", function (e) {
var query_string = encodeURI("?ip_address=" + g_ip_address + "&username=" + g_username + "&password=" + g_password); var query_string = encodeURI("?ip_address=" + g_ip_address + "&username=" + g_username + "&password=" + g_password);
Pebble.openURL("http://www.dkographicdetails.com/rockodi/config/config-page.html" + query_string); Pebble.openURL("http://www.dkographicdetails.com/rockodi/config/config-page.html" + query_string);
}); });
Pebble.addEventListener("webviewclosed",
function (e) { Pebble.addEventListener("webviewclosed", function (e) {
var configuration = JSON.parse(decodeURIComponent(e.response)); var configuration = JSON.parse(decodeURIComponent(e.response));
if (typeof configuration.ip_address !== "undefined") { if (typeof configuration.ip_address !== "undefined") {
localStorage.setItem(storage_keys.IP_ADDRESS, configuration.ip_address); localStorage.setItem(storage_keys.IP_ADDRESS, configuration.ip_address);
localStorage.setItem(storage_keys.USERNAME, configuration.username); localStorage.setItem(storage_keys.USERNAME, configuration.username);
localStorage.setItem(storage_keys.PASSWORD, configuration.password); localStorage.setItem(storage_keys.PASSWORD, configuration.password);
g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS); g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS);
g_username = localStorage.getItem(storage_keys.USERNAME); g_username = localStorage.getItem(storage_keys.USERNAME);
g_password = localStorage.getItem(storage_keys.PASSWORD); g_password = localStorage.getItem(storage_keys.PASSWORD);
}
} }
); });
Pebble.addEventListener("appmessage",
function (e) { Pebble.addEventListener("appmessage", function (e) {
var cmd = e.payload.MSG_KEY_CMD; var cmd = e.payload.MSG_KEY_CMD;
switch (cmd) { switch (cmd) {
// Player messages // Player messages
case "GET_STATUS": case "GET_STATUS":
getStatus(); getStatus();
break; break;
case "PLAY_PAUSE": case "PLAY_PAUSE":
playPause(); playPause();
break; break;
case "VOLUME_UP": case "VOLUME_UP":
raiseVolume(); raiseVolume();
break; break;
case "VOLUME_DOWN": case "VOLUME_DOWN":
lowerVolume(); lowerVolume();
break; break;
case "NEXT": case "NEXT":
next(); next();
break; break;
case "STOP": case "STOP":
stop(); stop();
break; break;
case "PREVIOUS": case "PREVIOUS":
previous(); previous();
break; break;
// Remote messages // Remote messages
case "KEY_SELECT": case "KEY_SELECT":
sendKey(cmd); sendKey(cmd);
break; break;
case "KEY_UP": case "KEY_UP":
sendKey(cmd); sendKey(cmd);
break; break;
case "KEY_DOWN": case "KEY_DOWN":
sendKey(cmd); sendKey(cmd);
break; break;
case "KEY_BACK": case "KEY_BACK":
sendKey(cmd); sendKey(cmd);
break; break;
case "KEY_LEFT": case "KEY_LEFT":
sendKey(cmd); sendKey(cmd);
break; break;
case "KEY_RIGHT": case "KEY_RIGHT":
sendKey(cmd); sendKey(cmd);
break; break;
// Goto messages // Goto messages
case "GO_FULL": case "GO_FULL":
gotoFullscreen(); gotoFullscreen();
break; break;
case "GO_INFO": case "GO_INFO":
gotoInfo(); gotoInfo();
break; break;
case "GO_HOME": case "GO_HOME":
gotoHome(); gotoHome();
break; break;
case "GO_MUSIC": case "GO_MUSIC":
gotoMusic(); gotoMusic();
break; break;
case "GO_VIDEO": case "GO_VIDEO":
gotoVideo(); gotoVideo();
break; break;
case "GO_PICS": case "GO_PICS":
gotoPictures(); gotoPictures();
break; break;
case "GO_WEATHER": case "GO_WEATHER":
gotoWeather(); gotoWeather();
break; break;
// Playlist messages // Playlist messages
case "GET_MUSIC_PLAYLISTS": case "GET_MUSIC_PLAYLISTS":
getMusicPlaylists(); getMusicPlaylists();
break; break;
case "PLAY_MUSIC_PLAYLIST": case "PLAY_MUSIC_PLAYLIST":
playMusicPlaylist(e.payload); playMusicPlaylist(e.payload);
break; break;
// Addons messages // Addons messages
case "GET_ADDONS": case "GET_ADDONS":
getAddons(); getAddons();
break; break;
case "EXE_ADDON": case "EXE_ADDON":
executeAddon(e.payload); executeAddon(e.payload);
break; break;
// Power messages // Power messages
case "PWR_SHUTDOWN": case "PWR_SHUTDOWN":
systemShutdown(); systemShutdown();
break; break;
case "PWR_REBOOT": case "PWR_REBOOT":
systemReboot(); systemReboot();
break; break;
case "PWR_SUSPEND": case "PWR_SUSPEND":
systemSuspend(); systemSuspend();
break; break;
case "PWR_HIBERNATE": case "PWR_HIBERNATE":
systemHibernate(); systemHibernate();
break; break;
default: default:
console.log("Command is not defined: " + cmd + "; payload: " + e.payload); console.log("Command is not defined: " + cmd + "; payload: " + e.payload);
}
} }
); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment