make interval configurable (fix #27)

yahoo_weather
simon04 13 years ago
parent 5aadd4ec56
commit 5c6848101c
  1. 6
      README.md
  2. 13
      src/extension.js
  3. 5
      src/org.gnome.shell.extensions.weather.gschema.xml.in

@ -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:

@ -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);
}));
}

@ -49,5 +49,10 @@
<_summary>Position in panel</_summary>
<_description>Set the position of this GNOME Shell extension in the panel to either 'center', 'left' or 'right' (requires restart).</_description>
</key>
<key name="refresh-interval" type="i">
<default>240</default>
<_summary>Refresh interval in seconds</_summary>
<_description>The interval in seconds to refresh the weather information.</_description>
</key>
</schema>
</schemalist>

Loading…
Cancel
Save