From b792b84a2d64e85afb2fb5a773665ea4e1fe2aac Mon Sep 17 00:00:00 2001 From: simon04 Date: Mon, 16 May 2011 21:20:38 +0200 Subject: [PATCH 1/2] Naive exception handling. --- weather@venemo.net/extension.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/weather@venemo.net/extension.js b/weather@venemo.net/extension.js index 4f54143..c9638d5 100644 --- a/weather@venemo.net/extension.js +++ b/weather@venemo.net/extension.js @@ -132,25 +132,22 @@ WeatherMenuButton.prototype = { } }, + load_json: function(url) { + var session = new Soup.SessionSync(); + var message = Soup.Message.new('GET', url); + stat = session.send_message(message); + jp = new Json.Parser(); + jp.load_from_data(message.response_body.data, -1); + return jp.get_root(); + }, + refreshWeather: function() { - // Fetching current weather - let weather; - { - var session = new Soup.SessionSync(); - var message = Soup.Message.new('GET', WEATHER_URL); - stat = session.send_message(message); - jp = new Json.Parser(); - jp.load_from_data(message.response_body.data, -1); - weather = jp.get_root().get_object(); - } + try { - /* - weather.constructor.prototype.get_data = function(a, b) { - return weather.get_object_member(a).get_strig_member(b); - }; - */ + // Fetching current weather + let weather = this.load_json(WEATHER_URL).get_object(); // Refreshing current weather let location = weather.get_object_member('location').get_string_member('city'); @@ -175,6 +172,10 @@ WeatherMenuButton.prototype = { this._currentWeatherPressure.text = pressure + ' ' + pressure_unit; this._currentWeatherWind.text = wind_direction + ' ' + wind + ' ' + wind_unit; + } catch (e) { + //TODO + } + // Repeatedly refresh weather here = this; Mainloop.timeout_add(1000*60*4, function() { From 5e05d0c2831dada512baea40c9cd13ce11676e45 Mon Sep 17 00:00:00 2001 From: simon04 Date: Mon, 16 May 2011 21:23:52 +0200 Subject: [PATCH 2/2] Refactoring. --- weather@venemo.net/extension.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/weather@venemo.net/extension.js b/weather@venemo.net/extension.js index c9638d5..741b98e 100644 --- a/weather@venemo.net/extension.js +++ b/weather@venemo.net/extension.js @@ -77,6 +77,7 @@ WeatherMenuButton.prototype = { topBox.add_actor(this._weatherIcon); topBox.add_actor(this._weatherInfo); this.actor.set_child(topBox); + Main.panel._centerBox.add(this.actor, { y_fill: true }); // Current weather this._currentWeather = new St.Bin(); @@ -146,8 +147,8 @@ WeatherMenuButton.prototype = { try { - // Fetching current weather - let weather = this.load_json(WEATHER_URL).get_object(); + // Fetching current weather + let weather = this.load_json(WEATHER_URL).get_object(); // Refreshing current weather let location = weather.get_object_member('location').get_string_member('city'); @@ -177,10 +178,7 @@ WeatherMenuButton.prototype = { } // Repeatedly refresh weather - here = this; - Mainloop.timeout_add(1000*60*4, function() { - here.refreshWeather(); - }); + Mainloop.timeout_add_seconds(60*4, Lang.bind(this, this.refreshWeather)); }, @@ -283,6 +281,5 @@ WeatherMenuButton.prototype = { function main() { this._weatherMenu = new WeatherMenuButton(); - Main.panel._centerBox.add(this._weatherMenu.actor, { y_fill: true }); }