@ -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,27 +1104,11 @@ 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 ( ! json )
return 0 ;
if ( Number ( json . cod ) != 200 )
return 0 ;
this . rebuildSelectCityItem ( ) ;
if ( this . _old _position _in _panel != this . _position _in _panel ) {
if ( this . _old _position _in _panel != this . _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
@ -1141,9 +1141,10 @@ weather-storm.png = weather-storm-symbolic.svg
this . _old _position _in _panel = this . _position _in _panel ;
this . _old _position _in _panel = this . _position _in _panel ;
}
}
let json = this . currentWeatherCache ;
// Refresh current weather
let location = this . extractLocation ( this . _city ) ;
let location = this . extractLocation ( this . _city ) ;
// Refresh current weather
let comment = json . weather [ 0 ] . description ;
let comment = json . weather [ 0 ] . description ;
if ( this . _translate _condition )
if ( this . _translate _condition )
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
@ -1162,18 +1163,16 @@ weather-storm.png = weather-storm-symbolic.svg
let sunrise = json . sys . sunrise ;
let sunrise = json . sys . sunrise ;
let sunset = json . sys . sunset ;
let sunset = json . sys . sunset ;
if ( typeof this . lastBuildId == "undefined" )
if ( typeof this . lastBuildId == 'undefined' )
this . lastBuildId = 0 ;
this . lastBuildId = 0 ;
if ( typeof this . lastBuildDate == "undefined" )
if ( typeof this . lastBuildDate == 'undefined' )
this . lastBuildDate = 0 ;
this . lastBuildDate = 0 ;
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
this . lastBuildId = json . dt ;
this . lastBuildId = json . dt ;
this . lastBuildDate = new Date ( ) ;
this . lastBuildDate = new Date ( this . lastBuildId * 1000 ) ;
}
}
let actualDate = new Date ( ) ;
let d = Math . floor ( ( actualDate . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
switch ( this . _pressure _units ) {
switch ( this . _pressure _units ) {
case WeatherPressureUnits . inHg :
case WeatherPressureUnits . inHg :
@ -1268,10 +1267,12 @@ weather-storm.png = weather-storm-symbolic.svg
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
}
}
if ( d >= 1 ) {
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
let d = Math . floor ( ( beginOfDay . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
if ( d < 0 ) {
lastBuild = _ ( "Yesterday" ) ;
lastBuild = _ ( "Yesterday" ) ;
if ( d > 1 )
if ( d < - 1 )
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , d ) ;
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , - 1 * d ) ;
}
}
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
@ -1334,45 +1335,62 @@ weather-storm.png = weather-storm-symbolic.svg
else // i.e. wind > 0 && wind_direction
else // i.e. wind > 0 && wind_direction
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
return 0 ;
} ) ;
// Repeatedly refresh weather if recurse is set
if ( recurse ) {
this . _timeoutCurrent = Mainloop . timeout _add _seconds ( this . _refresh _interval _current , Lang . bind ( this , function ( ) {
this . refreshWeatherCurrent ( true ) ;
} ) ) ;
}
return 0 ;
} ,
} ,
refreshWeatherForecas t : function ( recurse ) {
refreshWeatherCurrent : function ( recurse ) {
if ( ! this . extractId ( this . _city ) ) {
if ( ! this . extractId ( this . _city ) ) {
this . updateCities ( ) ;
this . updateCities ( ) ;
return 0 ;
return ;
}
}
this . oldLocation = this . extractCity ( this . _city ) ;
let params = {
let params = {
q : this . extractCity ( this . _city ) ,
q : this . oldLocation ,
units : 'metric' ,
units : 'metric'
cnt : '10'
} ;
} ;
if ( this . _appid )
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _FORECAS T , params , function ( json ) {
this . load _json _async ( WEATHER _URL _CURREN T , params , function ( json ) {
if ( ! json )
if ( ! json )
return 0 ;
return ;
if ( Number ( json . cod ) != 200 )
if ( Number ( json . cod ) != 200 )
return 0 ;
return ;
if ( this . currentWeatherCache != json )
this . currentWeatherCache = json ;
this . rebuildSelectCityItem ( ) ;
this . parseWeatherCurrent ( ) ;
this . parseWeatherForecast ( ) ;
} ) ;
// Repeatedly refresh weather if recurse is set
if ( recurse ) {
this . _timeoutCurrent = Mainloop . timeout _add _seconds ( this . _refresh _interval _current , Lang . bind ( this , function ( ) {
this . refreshWeatherCurrent ( true ) ;
} ) ) ;
}
} ,
parseWeatherForecast : function ( ) {
if ( this . forecastWeatherCache == 'undefined' ) {
this . refreshWeatherForecast ( ) ;
return ;
}
let forecast = json . list ;
let forecast = this . forecastWeatherCache ;
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
// Refresh forecast
// Refresh forecast
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
let forecastUi = this . _forecast [ i ] ;
let forecastUi = this . _forecast [ i ] ;
let forecastData = forecast [ i ] ;
let forecastData = forecast [ i ] ;
if ( forecastData == 'undefined' )
continue ;
let t _low = forecastData . temp . min ;
let t _low = forecastData . temp . min ;
let t _high = forecastData . temp . max ;
let t _high = forecastData . temp . max ;
@ -1424,25 +1442,52 @@ weather-storm.png = weather-storm-symbolic.svg
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let actualDate = new Date ( ) ;
let dayLeft = Math . floor ( ( forecastDate . getTime ( ) - beginOfDay . getTime ( ) ) / 86400000 ) ;
let dayLeft = Math . floor ( ( actualDate . getTime ( ) - forecastDate . getTime ( ) ) / 1000 / 60 / 60 / 24 ) ;
let date _string = _ ( "Today" ) ;
let date _string = _ ( "Today" ) ;
if ( dayLeft == - 1 )
if ( dayLeft == 1 )
date _string = _ ( "Tomorrow" ) ;
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 )
else if ( dayLeft > 1 )
date _string = _ ( "%s days ago" ) . replace ( "%s" , dayLeft ) ;
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 . 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 . 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 . Summary . text = comment ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
}
}
} ,
refreshWeatherForecast : function ( recurse ) {
if ( ! this . extractId ( this . _city ) ) {
this . updateCities ( ) ;
return 0 ;
return 0 ;
}
this . oldLocation = this . extractCity ( this . _city ) ;
let params = {
q : this . oldLocation ,
units : 'metric' ,
cnt : '13'
} ;
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _FORECAST , params , function ( json ) {
if ( ! json )
return ;
if ( Number ( json . cod ) != 200 )
return ;
if ( this . forecastWeatherCache != json . list )
this . forecastWeatherCache = json . list ;
this . parseWeatherForecast ( ) ;
} ) ;
} ) ;
// Repeatedly refresh weather if recurse is set
// Repeatedly refresh weather if recurse is set