diff --git a/README.md b/README.md index 41e551f..39d6646 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,12 @@ The position of this GNOME Shell extension in the panel can be configured to eit gsettings set org.gnome.shell.extensions.weather position-in-panel left gsettings set org.gnome.shell.extensions.weather position-in-panel right +#### Refresh Interval (optional, 240 by default) + +The interval to refresh the weather information may be set arbitrarily and is specified in seconds. + + gsettings set org.gnome.shell.extensions.weather refresh-interval 240 + #### Restart GNOME Shell Don't forget to restart GNOME Shell: diff --git a/src/extension.js b/src/extension.js index 89fea0e..725761d 100644 --- a/src/extension.js +++ b/src/extension.js @@ -54,6 +54,7 @@ const WEATHER_USE_SYMBOLIC_ICONS_KEY = 'use-symbolic-icons'; const WEATHER_SHOW_TEXT_IN_PANEL_KEY = 'show-text-in-panel'; const WEATHER_POSITION_IN_PANEL_KEY = 'position-in-panel'; const WEATHER_SHOW_COMMENT_IN_PANEL_KEY = 'show-comment-in-panel'; +const WEATHER_REFRESH_INTERVAL = 'refresh-interval'; // Keep enums in sync with GSettings schemas const WeatherUnits = { @@ -90,6 +91,8 @@ WeatherMenuButton.prototype = { this._text_in_panel = this._settings.get_boolean(WEATHER_SHOW_TEXT_IN_PANEL_KEY); this._position_in_panel = this._settings.get_enum(WEATHER_POSITION_IN_PANEL_KEY); this._comment_in_panel = this._settings.get_boolean(WEATHER_SHOW_COMMENT_IN_PANEL_KEY); + this._refresh_interval = this._settings.get_int(WEATHER_REFRESH_INTERVAL); + global.log(this._refresh_interval); // Watch settings for changes let load_settings_and_refresh_weather = Lang.bind(this, function() { @@ -114,6 +117,10 @@ WeatherMenuButton.prototype = { this._forecast[1].Icon.icon_type = this._icon_type; this.refreshWeather(false); })); + this._settings.connect('changed::' + WEATHER_REFRESH_INTERVAL, Lang.bind(this, function() { + this._refresh_interval = this._settings.get_int(WEATHER_REFRESH_INTERVAL); + global.log(this._refresh_interval); + })); // Panel icon this._weatherIcon = new St.Icon({ @@ -460,6 +467,7 @@ WeatherMenuButton.prototype = { refreshWeather: function(recurse) { this.load_json_async(this.get_weather_url(), function(json) { + try { let weather = json.get_object_member('query').get_object_member('results').get_object_member('channel'); let weather_c = weather.get_object_member('item').get_object_member('condition'); let forecast = weather.get_object_member('item').get_array_member('forecast').get_elements(); @@ -539,11 +547,14 @@ WeatherMenuButton.prototype = { forecastUi.Icon.icon_name = this.get_weather_icon_safely(code); } + } catch(e) { + global.log('A ' + e.name + ' has occured: ' + e.message); + } }); // Repeatedly refresh weather if recurse is set if (recurse) { - Mainloop.timeout_add_seconds(60 * 4, Lang.bind(this, function() { + Mainloop.timeout_add_seconds(this._refresh_interval, Lang.bind(this, function() { this.refreshWeather(true); })); } diff --git a/src/org.gnome.shell.extensions.weather.gschema.xml.in b/src/org.gnome.shell.extensions.weather.gschema.xml.in index 95e9c9f..8a7964e 100644 --- a/src/org.gnome.shell.extensions.weather.gschema.xml.in +++ b/src/org.gnome.shell.extensions.weather.gschema.xml.in @@ -49,5 +49,10 @@ <_summary>Position in panel <_description>Set the position of this GNOME Shell extension in the panel to either 'center', 'left' or 'right' (requires restart). + + 240 + <_summary>Refresh interval in seconds + <_description>The interval in seconds to refresh the weather information. +