@ -284,8 +284,12 @@ const WeatherMenuButton = new Lang.Class({
this . _settings = Convenience . getSettings ( WEATHER _SETTINGS _SCHEMA ) ;
this . _settings = Convenience . getSettings ( WEATHER _SETTINGS _SCHEMA ) ;
this . _settingsC = this . _settings . connect ( "changed" , function ( ) {
this . _settingsC = this . _settings . connect ( "changed" , function ( ) {
that . rebuildFutureWeatherUi ( ) ;
that . rebuildFutureWeatherUi ( ) ;
that . refreshWeatherCurrent ( false ) ;
if ( that . locationChanged ( ) ) {
that . refreshWeatherForecast ( false ) ;
that . currentWeatherCache = 'undefined' ;
that . forecastWeatherCache = 'undefined' ;
}
that . parseWeatherCurrent ( ) ;
that . parseWeatherForecast ( ) ;
} ) ;
} ) ;
} ,
} ,
@ -298,11 +302,23 @@ const WeatherMenuButton = new Lang.Class({
schema : schemaInterface
schema : schemaInterface
} ) ;
} ) ;
this . _settingsInterfaceC = this . _settingsInterface . connect ( "changed" , function ( ) {
this . _settingsInterfaceC = this . _settingsInterface . connect ( "changed" , function ( ) {
that . refreshWeatherCurrent ( false ) ;
if ( that . locationChanged ( ) ) {
that . refreshWeatherForecast ( false ) ;
that . currentWeatherCache = 'undefined' ;
that . forecastWeatherCache = 'undefined' ;
}
that . parseWeatherCurrent ( ) ;
that . parseWeatherForecast ( ) ;
} ) ;
} ) ;
} ,
} ,
locationChanged : function ( ) {
let location = this . extractCity ( this . _city ) ;
if ( this . oldLocation != location ) {
return true ;
}
return false ;
} ,
get _clockFormat ( ) {
get _clockFormat ( ) {
if ( ! this . _settingsInterface )
if ( ! this . _settingsInterface )
this . loadConfigInterface ( ) ;
this . loadConfigInterface ( ) ;
@ -1088,253 +1104,268 @@ weather-storm.png = weather-storm-symbolic.svg
return 0 ;
return 0 ;
} ,
} ,
refresh WeatherCurrent: function ( recurse ) {
parse WeatherCurrent: function ( ) {
if ( ! this . extractId ( this . _city ) ) {
if ( this . currentWeatherCache == 'undefined' ) {
this . updateCities ( ) ;
this . refreshWeatherCurrent ( ) ;
return 0 ;
return ;
}
}
let params = {
q : this . extractCity ( this . _city ) ,
units : 'metric'
} ;
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _CURRENT , params , function ( json ) {
if ( this . _old _position _in _panel != this . _position _in _panel ) {
if ( ! json )
switch ( this . _old _position _in _panel ) {
return 0 ;
case WeatherPosition . LEFT :
Main . panel . _leftBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . CENTER :
Main . panel . _centerBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . RIGHT :
Main . panel . _rightBox . remove _actor ( this . actor ) ;
break ;
}
if ( Number ( json . cod ) != 200 )
let children = null ;
return 0 ;
switch ( this . _position _in _panel ) {
case WeatherPosition . LEFT :
children = Main . panel . _leftBox . get _children ( ) ;
Main . panel . _leftBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . CENTER :
children = Main . panel . _centerBox . get _children ( ) ;
Main . panel . _centerBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . RIGHT :
children = Main . panel . _rightBox . get _children ( ) ;
Main . panel . _rightBox . insert _child _at _index ( this . actor , 0 ) ;
break ;
}
this . _old _position _in _panel = this . _position _in _panel ;
}
this . rebuildSelectCityItem ( ) ;
let json = this . currentWeatherCache ;
// Refresh current weather
let location = this . extractLocation ( this . _city ) ;
let comment = json . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
if ( this . _old _position _in _panel != this . _position _in _panel ) {
let temperature = json . main . temp ;
switch ( this . _old _position _in _panel ) {
let cloudiness = json . clouds . all ;
case WeatherPosition . LEFT :
let humidity = json . main . humidity + ' %' ;
Main . panel . _leftBox . remove _actor ( this . actor ) ;
let pressure = json . main . pressure ;
break ;
let pressure _unit = 'hPa' ;
case WeatherPosition . CENTER :
Main . panel . _centerBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . RIGHT :
Main . panel . _rightBox . remove _actor ( this . actor ) ;
break ;
}
let children = null ;
switch ( this . _position _in _panel ) {
case WeatherPosition . LEFT :
children = Main . panel . _leftBox . get _children ( ) ;
Main . panel . _leftBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . CENTER :
children = Main . panel . _centerBox . get _children ( ) ;
Main . panel . _centerBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . RIGHT :
children = Main . panel . _rightBox . get _children ( ) ;
Main . panel . _rightBox . insert _child _at _index ( this . actor , 0 ) ;
break ;
}
this . _old _position _in _panel = this . _position _in _panel ;
}
let location = this . extractLocation ( this . _city ) ;
let wind _direction = this . get _wind _direction ( json . wind . deg ) ;
let wind = json . wind . speed ;
let wind _unit = 'm/s' ;
let iconname = this . get _weather _icon _safely ( json . weather [ 0 ] . id ) ;
// Refresh current weather
let sunrise = json . sys . sunrise ;
let comment = json . weather [ 0 ] . description ;
let sunset = json . sys . sunset ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
let temperature = json . main . temp ;
if ( typeof this . lastBuildId == 'undefined' )
let cloudiness = json . clouds . all ;
this . lastBuildId = 0 ;
let humidity = json . main . humidity + ' %' ;
let pressure = json . main . pressure ;
let pressure _unit = 'hPa' ;
let wind _direction = this . get _wind _direction ( json . wind . deg ) ;
if ( typeof this . lastBuildDate == 'undefined' )
let wind = json . wind . speed ;
this . lastBuildDate = 0 ;
let wind _unit = 'm/s' ;
let iconname = this . get _weather _icon _safely ( json . weather [ 0 ] . id ) ;
let sunrise = json . sys . sunrise ;
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
let sunset = json . sys . sunset ;
this . lastBuildId = json . dt ;
this . lastBuildDate = new Date ( this . lastBuildId * 1000 ) ;
}
if ( typeof this . lastBuildId == "undefined" )
switch ( this . _pressure _units ) {
this . lastBuildId = 0 ;
case WeatherPressureUnits . inHg :
pressure = this . toInHg ( pressure ) ;
pressure _unit = "inHg" ;
break ;
if ( typeof this . lastBuildDate == "undefined" )
case WeatherPressureUnits . hPa :
this . lastBuildDate = 0 ;
pressure = Math . round ( pressure * 10 ) / 10 ;
pressure _unit = "hPa" ;
break ;
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
case WeatherPressureUnits . bar :
this . lastBuildId = json . dt ;
pressure = Math . round ( ( pressure / 1000 ) * 10 ) / 10 ;
this . lastBuildDate = new Date ( ) ;
pressure _unit = "bar" ;
}
break ;
let actualDate = new Date ( ) ;
let d = Math . floor ( ( actualDate . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
switch ( this . _pressure _units ) {
case WeatherPressureUnits . Pa :
case WeatherPressureUnits . inHg :
pressure = Math . round ( ( pressure * 100 ) * 10 ) / 10 ;
pressure = this . toInHg ( pressure ) ;
pressure _unit = "Pa" ;
pressure _unit = "inHg" ;
break ;
break ;
case WeatherPressureUnits . h Pa:
case WeatherPressureUnits . k Pa:
pressure = Math . round ( pressure * 10 ) / 10 ;
pressure = Math . round ( ( pressure / 10 ) * 10 ) / 10 ;
pressure _unit = "h Pa" ;
pressure _unit = "k Pa" ;
break ;
break ;
case WeatherPressureUnits . bar :
case WeatherPressureUnits . atm :
pressure = Math . round ( ( pressure / 1000 ) * 10 ) / 10 ;
pressure = Math . round ( ( pressure * 0.000986923267 ) * 10 ) / 10 ;
pressure _unit = "bar " ;
pressure _unit = "atm " ;
break ;
break ;
case WeatherPressureUnits . P a:
case WeatherPressureUnits . at :
pressure = Math . round ( ( pressure * 100 ) * 10 ) / 10 ;
pressure = Math . round ( ( pressure * 0.00101971621298 ) * 10 ) / 10 ;
pressure _unit = "P a" ;
pressure _unit = "at " ;
break ;
break ;
case WeatherPressureUnits . kPa :
case WeatherPressureUnits . Torr :
pressure = Math . round ( ( pressure / 10 ) * 10 ) / 10 ;
pressure = Math . round ( ( pressure * 0.750061683 ) * 10 ) / 10 ;
pressure _unit = "kPa " ;
pressure _unit = "Torr " ;
break ;
break ;
case WeatherPressureUnits . atm :
case WeatherPressureUnits . psi :
pressure = Math . round ( ( pressure * 0.000986923267 ) * 10 ) / 10 ;
pressure = Math . round ( ( pressure * 0.0145037738 ) * 10 ) / 10 ;
pressure _unit = "atm" ;
pressure _unit = "psi" ;
break ;
break ;
}
case WeatherPressureUnits . at :
switch ( this . _units ) {
pressure = Math . round ( ( pressure * 0.00101971621298 ) * 10 ) / 10 ;
case WeatherUnits . FAHRENHEIT :
pressure _unit = "at" ;
temperature = this . toFahrenheit ( temperature ) ;
break ;
break ;
case WeatherPressureUnits . Torr :
case WeatherUnits . CELSIUS :
pressure = Math . round ( ( pressure * 0.750061683 ) * 10 ) / 10 ;
temperature = Math . round ( temperature * 10 ) / 10 ;
pressure _unit = "Torr" ;
break ;
break ;
case WeatherPressureUnits . psi :
case WeatherUnits . KELVIN :
pressure = Math . round ( ( pressure * 0.0145037738 ) * 10 ) / 10 ;
temperature = this . toKelvin ( temperature ) ;
pressure _unit = "psi" ;
break ;
break ;
}
switch ( this . _units ) {
case WeatherUnits . RANKINE :
case WeatherUnits . FAHRENHEIT :
temperature = this . toRankine ( temperature ) ;
temperature = this . toFahrenheit ( temperature ) ;
break ;
break ;
case WeatherUnits . CELSIUS :
case WeatherUnits . REAUMUR :
temperature = Math . round ( temperature * 10 ) / 10 ;
temperature = this . toReaumur ( temperature ) ;
break ;
break ;
case WeatherUnits . KELVIN :
case WeatherUnits . ROEMER :
temperature = this . toKelvin ( temperature ) ;
temperature = this . toRoemer ( temperature ) ;
break ;
break ;
case WeatherUnits . RANKIN E:
case WeatherUnits . DELISL E:
temperature = this . toRankin e ( temperature ) ;
temperature = this . toDelisl e ( temperature ) ;
break ;
break ;
case WeatherUnits . REAUMUR :
case WeatherUnits . NEWTON :
temperature = this . toReaumur ( temperature ) ;
temperature = this . toNewton ( temperature ) ;
break ;
break ;
}
case WeatherUnits . ROEMER :
let lastBuild = '-' ;
temperature = this . toRoemer ( temperature ) ;
break ;
case WeatherUnits . DELISLE :
if ( this . _clockFormat == "24h" ) {
temperature = this . toDelisle ( temperature ) ;
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%R" ) ;
break ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%R" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%R" ) ;
} else {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
}
case WeatherUnits . NEWTON :
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
temperature = this . toNewton ( temperature ) ;
let d = Math . floor ( ( beginOfDay . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
break ;
if ( d < 0 ) {
}
lastBuild = _ ( "Yesterday" ) ;
if ( d < - 1 )
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , - 1 * d ) ;
}
let lastBuild = '-' ;
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
if ( this . _clockFormat == "24h" ) {
let weatherInfoC = "" ;
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%R" ) ;
let weatherInfoT = "" ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%R" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%R" ) ;
} else {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
}
if ( d >= 1 ) {
if ( this . _comment _in _panel )
lastBuild = _ ( "Yesterday" ) ;
weatherInfoC = comment ;
if ( d > 1 )
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , d ) ;
}
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
if ( this . _text _in _panel )
weatherInfoT = parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
let weatherInfoC = "" ;
this . _weatherInfo . text = weatherInfoC + ( ( weatherInfoC && weatherInfoT ) ? ", " : "" ) + weatherInfoT ;
let weatherInfoT = "" ;
if ( this . _comment _in _panel )
this . _currentWeatherSummary . text = comment + ", " + parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
weatherInfoC = comment ;
this . _currentWeatherLocation . text = location ;
this . _currentWeatherTemperature . text = cloudiness + ' %' ;
this . _currentWeatherHumidity . text = parseFloat ( humidity ) . toLocaleString ( ) + ' %' ;
this . _currentWeatherPressure . text = parseFloat ( pressure ) . toLocaleString ( ) + ' ' + pressure _unit ;
this . _currentWeatherSunrise . text = sunrise ;
this . _currentWeatherSunset . text = sunset ;
this . _currentWeatherBuild . text = lastBuild ;
if ( this . _text _in _panel )
// Override wind units with our preference
weatherInfoT = parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
switch ( this . _wind _speed _units ) {
case WeatherWindSpeedUnits . MPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _MPH ) * 10 ) / 10 ;
wind _unit = 'mph' ;
break ;
this . _weatherInfo . text = weatherInfoC + ( ( weatherInfoC && weatherInfoT ) ? ", " : "" ) + weatherInfoT ;
case WeatherWindSpeedUnits . KPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KPH ) * 10 ) / 10 ;
wind _unit = 'km/h' ;
break ;
this . _currentWeatherSummary . text = comment + ", " + parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
case WeatherWindSpeedUnits . MPS :
this . _currentWeatherLocation . text = location ;
wind = Math . round ( wind * 10 ) / 10 ;
this . _currentWeatherTemperature . text = cloudiness + ' %' ;
break ;
this . _currentWeatherHumidity . text = parseFloat ( humidity ) . toLocaleString ( ) + ' %' ;
this . _currentWeatherPressure . text = parseFloat ( pressure ) . toLocaleString ( ) + ' ' + pressure _unit ;
this . _currentWeatherSunrise . text = sunrise ;
this . _currentWeatherSunset . text = sunset ;
this . _currentWeatherBuild . text = lastBuild ;
// Override wind units with our preference
case WeatherWindSpeedUnits . KNOTS :
switch ( this . _wind _speed _units ) {
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KNOTS ) * 10 ) / 10 ;
case WeatherWindSpeedUnits . MPH :
wind _unit = 'kn' ;
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _MPH ) * 10 ) / 10 ;
break ;
wind _unit = 'mph' ;
break ;
case WeatherWindSpeedUnits . KPH :
case WeatherWindSpeedUnits . FPS :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KPH ) * 10 ) / 10 ;
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _FPS ) * 10 ) / 10 ;
wind _unit = 'km/h ' ;
wind _unit = 'ft/s ' ;
break ;
break ;
case WeatherWindSpeedUnits . MPS :
case WeatherWindSpeedUnits . BEAUFORT :
wind = Math . round ( wind * 10 ) / 10 ;
wind _unit = this . toBeaufort ( wind , true ) ;
break ;
wind = this . toBeaufort ( wind ) ;
}
case WeatherWindSpeedUnits . KNOTS :
if ( ! wind )
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KNOTS ) * 10 ) / 10 ;
this . _currentWeatherWind . text = '\u2013' ;
wind _unit = 'kn' ;
else if ( wind == 0 || ! wind _direction )
break ;
this . _currentWeatherWind . text = parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
else // i.e. wind > 0 && wind_direction
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
case WeatherWindSpeedUnits . FPS :
} ,
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _FPS ) * 10 ) / 10 ;
wind _unit = 'ft/s' ;
break ;
case WeatherWindSpeedUnits . BEAUFORT :
refreshWeatherCurrent : function ( recurse ) {
wind _unit = this . toBeaufort ( wind , true ) ;
if ( ! this . extractId ( this . _city ) ) {
wind = this . toBeaufort ( wind ) ;
this . updateCities ( ) ;
}
return ;
}
this . oldLocation = this . extractCity ( this . _city ) ;
if ( ! wind )
let params = {
this . _currentWeatherWind . text = '\u2013' ;
q : this . oldLocation ,
else if ( wind == 0 || ! wind _direction )
units : 'metric'
this . _currentWeatherWind . text = parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
} ;
else // i.e. wind > 0 && wind_direction
if ( this . _appid )
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _CURRENT , params , function ( json ) {
if ( ! json )
return ;
if ( Number ( json . cod ) != 200 )
return ;
if ( this . currentWeatherCache != json )
this . currentWeatherCache = json ;
this . rebuildSelectCityItem ( ) ;
this . parseWeatherCurrent ( ) ;
this . parseWeatherForecast ( ) ;
return 0 ;
} ) ;
} ) ;
// Repeatedly refresh weather if recurse is set
// Repeatedly refresh weather if recurse is set
@ -1343,7 +1374,91 @@ weather-storm.png = weather-storm-symbolic.svg
this . refreshWeatherCurrent ( true ) ;
this . refreshWeatherCurrent ( true ) ;
} ) ) ;
} ) ) ;
}
}
return 0 ;
} ,
parseWeatherForecast : function ( ) {
if ( this . forecastWeatherCache == 'undefined' ) {
this . refreshWeatherForecast ( ) ;
return ;
}
let forecast = this . forecastWeatherCache ;
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
// Refresh forecast
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
let forecastUi = this . _forecast [ i ] ;
let forecastData = forecast [ i ] ;
if ( forecastData == 'undefined' )
continue ;
let t _low = forecastData . temp . min ;
let t _high = forecastData . temp . max ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
t _low = this . toFahrenheit ( t _low ) ;
t _high = this . toFahrenheit ( t _high ) ;
break ;
case WeatherUnits . CELSIUS :
t _low = Math . round ( t _low * 10 ) / 10 ;
t _high = Math . round ( t _high * 10 ) / 10 ;
break ;
case WeatherUnits . KELVIN :
t _low = this . toKelvin ( t _low ) ;
t _high = this . toKelvin ( t _high ) ;
break ;
case WeatherUnits . RANKINE :
t _low = this . toRankine ( t _low ) ;
t _high = this . toRankine ( t _high ) ;
break ;
case WeatherUnits . REAUMUR :
t _low = this . toReaumur ( t _low ) ;
t _high = this . toReaumur ( t _high ) ;
break ;
case WeatherUnits . ROEMER :
t _low = this . toRoemer ( t _low ) ;
t _high = this . toRoemer ( t _high ) ;
break ;
case WeatherUnits . DELISLE :
t _low = this . toDelisle ( t _low ) ;
t _high = this . toDelisle ( t _high ) ;
break ;
case WeatherUnits . NEWTON :
t _low = this . toNewton ( t _low ) ;
t _high = this . toNewton ( t _high ) ;
break ;
}
let comment = forecastData . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let dayLeft = Math . floor ( ( forecastDate . getTime ( ) - beginOfDay . getTime ( ) ) / 86400000 ) ;
let date _string = _ ( "Today" ) ;
if ( dayLeft == 1 )
date _string = _ ( "Tomorrow" ) ;
else if ( dayLeft > 1 )
date _string = _ ( "In %s days" ) . replace ( "%s" , dayLeft ) ;
else if ( dayLeft == - 1 )
date _string = _ ( "Yesterday" ) ;
else if ( dayLeft < - 1 )
date _string = _ ( "%s days ago" ) . replace ( "%s" , - 1 * dayLeft ) ;
forecastUi . Day . text = date _string + ' (' + this . get _locale _day ( forecastDate . getDay ( ) ) + ')' ;
forecastUi . Temperature . text = '\u2193 ' + parseFloat ( t _low ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) + ' \u2191 ' + parseFloat ( t _high ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
forecastUi . Summary . text = comment ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
}
} ,
} ,
refreshWeatherForecast : function ( recurse ) {
refreshWeatherForecast : function ( recurse ) {
@ -1352,97 +1467,27 @@ weather-storm.png = weather-storm-symbolic.svg
return 0 ;
return 0 ;
}
}
this . oldLocation = this . extractCity ( this . _city ) ;
let params = {
let params = {
q : this . extractCity ( this . _city ) ,
q : this . oldLocation ,
units : 'metric' ,
units : 'metric' ,
cnt : '10 '
cnt : '13 '
} ;
} ;
if ( this . _appid )
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _FORECAST , params , function ( json ) {
this . load _json _async ( WEATHER _URL _FORECAST , params , function ( json ) {
if ( ! json )
if ( ! json )
return 0 ;
return ;
if ( Number ( json . cod ) != 200 )
if ( Number ( json . cod ) != 200 )
return 0 ;
return ;
let forecast = json . list ;
if ( this . forecastWeatherCache != json . list )
this . forecastWeatherCache = json . list ;
// Refresh forecast
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
this . parseWeatherForecast ( ) ;
let forecastUi = this . _forecast [ i ] ;
let forecastData = forecast [ i ] ;
let t _low = forecastData . temp . min ;
let t _high = forecastData . temp . max ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
t _low = this . toFahrenheit ( t _low ) ;
t _high = this . toFahrenheit ( t _high ) ;
break ;
case WeatherUnits . CELSIUS :
t _low = Math . round ( t _low * 10 ) / 10 ;
t _high = Math . round ( t _high * 10 ) / 10 ;
break ;
case WeatherUnits . KELVIN :
t _low = this . toKelvin ( t _low ) ;
t _high = this . toKelvin ( t _high ) ;
break ;
case WeatherUnits . RANKINE :
t _low = this . toRankine ( t _low ) ;
t _high = this . toRankine ( t _high ) ;
break ;
case WeatherUnits . REAUMUR :
t _low = this . toReaumur ( t _low ) ;
t _high = this . toReaumur ( t _high ) ;
break ;
case WeatherUnits . ROEMER :
t _low = this . toRoemer ( t _low ) ;
t _high = this . toRoemer ( t _high ) ;
break ;
case WeatherUnits . DELISLE :
t _low = this . toDelisle ( t _low ) ;
t _high = this . toDelisle ( t _high ) ;
break ;
case WeatherUnits . NEWTON :
t _low = this . toNewton ( t _low ) ;
t _high = this . toNewton ( t _high ) ;
break ;
}
let comment = forecastData . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let actualDate = new Date ( ) ;
let dayLeft = Math . floor ( ( actualDate . getTime ( ) - forecastDate . getTime ( ) ) / 1000 / 60 / 60 / 24 ) ;
let date _string = _ ( "Today" ) ;
if ( dayLeft == - 1 )
date _string = _ ( "Tomorrow" ) ;
else if ( dayLeft < - 1 )
date _string = _ ( "In %s days" ) . replace ( "%s" , - 1 * dayLeft ) ;
else if ( dayLeft == 1 )
date _string = _ ( "Yesterday" ) ;
else if ( dayLeft > 1 )
date _string = _ ( "%s days ago" ) . replace ( "%s" , dayLeft ) ;
forecastUi . Day . text = date _string + ' (' + this . get _locale _day ( forecastDate . getDay ( ) ) + ')' ;
forecastUi . Temperature . text = '\u2193 ' + parseFloat ( t _low ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) + ' \u2191 ' + parseFloat ( t _high ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
forecastUi . Summary . text = comment ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
}
return 0 ;
} ) ;
} ) ;
// Repeatedly refresh weather if recurse is set
// Repeatedly refresh weather if recurse is set