Skip to content

Commit

Permalink
Refresh every 30 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
iiska committed Feb 7, 2012
1 parent 58cbcd9 commit 4cc7c86
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions linnanmaa-weather@iiska.kapsi.fi/extension.js
Expand Up @@ -21,15 +21,22 @@ function _getData(callback) {
});
}

function _updateData() {
function _updateData(recurse) {
_getData(function(s,r) {
let response = r.response_body.data.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");
let data = new XML(response);
text.set_text(data.weather.tempnow + data.weather.tempnow.@unit);
text.set_text(data.weather.tempnow + ' ' + data.weather.tempnow.@unit);
});

if (recurse) {
Mainloop.timeout_add_seconds(1800, function() {
_updateData(true);
});
}
}

function _showDetails() {
// TODO: Open popup menu with detailed weather data
}

function init() {
Expand All @@ -50,20 +57,14 @@ function init() {
hbox.add(text);

button.set_child(hbox);
button.connect('button-press-event', _updateData);
button.connect('button-press-event', _showDetails);
}

function enable() {
Main.panel._centerBox.insert_actor(button, 0);
_updateData();

//Mainloop.timeout_add_seconds(1800, function() {
// _updateData();
//});
//Mainloop.run('updatedata');
_updateData(true);
}

function disable() {
//Mainloop.quit('updatedata');
Main.panel._centerBox.remove_actor(button);
}

0 comments on commit 4cc7c86

Please sign in to comment.