|
|
@ -49,6 +49,7 @@ const PopupMenu = imports.ui.popupMenu; |
|
|
|
// Settings
|
|
|
|
// Settings
|
|
|
|
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather'; |
|
|
|
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather'; |
|
|
|
const WEATHER_UNIT_KEY = 'unit'; |
|
|
|
const WEATHER_UNIT_KEY = 'unit'; |
|
|
|
|
|
|
|
const WEATHER_WIND_SPEED_UNIT_KEY = 'wind-speed-unit'; |
|
|
|
const WEATHER_CITY_KEY = 'city'; |
|
|
|
const WEATHER_CITY_KEY = 'city'; |
|
|
|
const WEATHER_ACTUAL_CITY_KEY = 'actual-city'; |
|
|
|
const WEATHER_ACTUAL_CITY_KEY = 'actual-city'; |
|
|
|
const WEATHER_TRANSLATE_CONDITION_KEY = 'translate-condition'; |
|
|
|
const WEATHER_TRANSLATE_CONDITION_KEY = 'translate-condition'; |
|
|
@ -63,12 +64,24 @@ const WeatherUnits = { |
|
|
|
CELSIUS: 0, |
|
|
|
CELSIUS: 0, |
|
|
|
FAHRENHEIT: 1 |
|
|
|
FAHRENHEIT: 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const WeatherWindSpeedUnits = { |
|
|
|
|
|
|
|
KPH: 0, |
|
|
|
|
|
|
|
MPH: 1, |
|
|
|
|
|
|
|
MPS: 2, |
|
|
|
|
|
|
|
KNOTS: 3 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const WeatherPosition = { |
|
|
|
const WeatherPosition = { |
|
|
|
CENTER: 0, |
|
|
|
CENTER: 0, |
|
|
|
RIGHT: 1, |
|
|
|
RIGHT: 1, |
|
|
|
LEFT: 2 |
|
|
|
LEFT: 2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const WEATHER_CONV_MPH_IN_MPS = 2.23693629; |
|
|
|
|
|
|
|
const WEATHER_CONV_KPH_IN_MPS = 3.6; |
|
|
|
|
|
|
|
const WEATHER_CONV_KNOTS_IN_MPS = 1.94384449; |
|
|
|
|
|
|
|
|
|
|
|
// Soup session (see https://bugzilla.gnome.org/show_bug.cgi?id=661323#c64) (Simon Legner)
|
|
|
|
// Soup session (see https://bugzilla.gnome.org/show_bug.cgi?id=661323#c64) (Simon Legner)
|
|
|
|
const _httpSession = new Soup.SessionAsync(); |
|
|
|
const _httpSession = new Soup.SessionAsync(); |
|
|
|
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); |
|
|
|
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); |
|
|
@ -221,6 +234,20 @@ WeatherMenuButton.prototype = { |
|
|
|
this._settings.set_enum(WEATHER_UNIT_KEY,v); |
|
|
|
this._settings.set_enum(WEATHER_UNIT_KEY,v); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get _wind_speed_units() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!this._settings) |
|
|
|
|
|
|
|
this.loadConfig(); |
|
|
|
|
|
|
|
return this._settings.get_enum(WEATHER_WIND_SPEED_UNIT_KEY); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set _wind_speed_units(v) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!this._settings) |
|
|
|
|
|
|
|
this.loadConfig(); |
|
|
|
|
|
|
|
this._settings.set_enum(WEATHER_WIND_SPEED_UNIT_KEY,v); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get _cities() |
|
|
|
get _cities() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!this._settings) |
|
|
|
if(!this._settings) |
|
|
@ -739,10 +766,47 @@ global.log(a); |
|
|
|
this._currentWeatherTemperature.text = temperature + ' ' + this.unit_to_unicode(); |
|
|
|
this._currentWeatherTemperature.text = temperature + ' ' + this.unit_to_unicode(); |
|
|
|
this._currentWeatherHumidity.text = humidity; |
|
|
|
this._currentWeatherHumidity.text = humidity; |
|
|
|
this._currentWeatherPressure.text = pressure + ' ' + pressure_unit; |
|
|
|
this._currentWeatherPressure.text = pressure + ' ' + pressure_unit; |
|
|
|
this._currentWeatherWind.text = (wind_direction && wind > 0 ? wind_direction + ' ' : '') + wind + ' ' + wind_unit; |
|
|
|
|
|
|
|
this._currentWeatherSunrise.text = sunrise; |
|
|
|
this._currentWeatherSunrise.text = sunrise; |
|
|
|
this._currentWeatherSunset.text = sunset; |
|
|
|
this._currentWeatherSunset.text = sunset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Override wind units with our preference
|
|
|
|
|
|
|
|
// Need to consider what units the Yahoo API has returned it in
|
|
|
|
|
|
|
|
switch (this._wind_speed_units) { |
|
|
|
|
|
|
|
case WeatherWindSpeedUnits.KPH: |
|
|
|
|
|
|
|
// Round to whole units
|
|
|
|
|
|
|
|
if (this._units == WeatherUnits.FAHRENHEIT) { |
|
|
|
|
|
|
|
wind = Math.round (wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KPH_IN_MPS); |
|
|
|
|
|
|
|
wind_unit = 'km/h'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Otherwise no conversion needed - already in correct units
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherWindSpeedUnits.MPH: |
|
|
|
|
|
|
|
// Round to whole units
|
|
|
|
|
|
|
|
if (this._units == WeatherUnits.CELSIUS) { |
|
|
|
|
|
|
|
wind = Math.round (wind / WEATHER_CONV_KPH_IN_MPS * WEATHER_CONV_MPH_IN_MPS); |
|
|
|
|
|
|
|
wind_unit = 'mph'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Otherwise no conversion needed - already in correct units
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherWindSpeedUnits.MPS: |
|
|
|
|
|
|
|
// Precision to one decimal place as 1 m/s is quite a large unit
|
|
|
|
|
|
|
|
if (this._units == WeatherUnits.CELSIUS) |
|
|
|
|
|
|
|
wind = Math.round ((wind / WEATHER_CONV_KPH_IN_MPS) * 10)/ 10; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
wind = Math.round ((wind / WEATHER_CONV_MPH_IN_MPS) * 10)/ 10; |
|
|
|
|
|
|
|
wind_unit = 'm/s'; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherWindSpeedUnits.KNOTS: |
|
|
|
|
|
|
|
// Round to whole units
|
|
|
|
|
|
|
|
if (this._units == WeatherUnits.CELSIUS) |
|
|
|
|
|
|
|
wind = Math.round (wind / WEATHER_CONV_KPH_IN_MPS * WEATHER_CONV_KNOTS_IN_MPS); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
wind = Math.round (wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KNOTS_IN_MPS); |
|
|
|
|
|
|
|
wind_unit = 'knots'; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this._currentWeatherWind.text = (wind_direction && wind > 0 ? wind_direction + ' ' : '') + wind + ' ' + wind_unit; |
|
|
|
|
|
|
|
|
|
|
|
// Refresh forecast
|
|
|
|
// Refresh forecast
|
|
|
|
let date_string = [_('Today'), _('Tomorrow')]; |
|
|
|
let date_string = [_('Today'), _('Tomorrow')]; |
|
|
|
for (let i = 0; i <= 1; i++) { |
|
|
|
for (let i = 0; i <= 1; i++) { |
|
|
|