@ -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 ++ ) {