Skip to content

Commit 4d56dc3

Browse files
committed
Merge branch 'background'
2 parents c444045 + f150341 commit 4d56dc3

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/Indicator.vala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ public class Weather.Indicator : Wingpanel.Indicator {
8383
}
8484

8585
private async void monitor_weather() {
86-
87-
var result = get_weather("",key);
88-
display_widget.update_state(result.short_discription,result.temperature);
89-
86+
//Fetch Report every 30 Minutes
87+
//TODO: Should be read from configuration file
88+
get_weather("",key, display_widget);
89+
GLib.Timeout.add_seconds (1800, () => {
90+
get_weather("",key, display_widget);
91+
return true;
92+
},GLib.Priority.DEFAULT);
93+
yield;
9094
}
9195

9296
public void connections () {}

src/lib/Weather.vala

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ string get_ip(Soup.Session session) {
1616

1717
}
1818

19-
weatherInfo get_weather(string location, string secret_key) {
19+
async void get_weather(string location, string secret_key, Weather.Widgets.DisplayWidget display_widget) {
2020

2121
//Init the session.
2222
var session = new Soup.Session ();
@@ -27,40 +27,38 @@ string get_ip(Soup.Session session) {
2727
string uri = "https://api.darksky.net/forecast/" + secret_key + "/";
2828

2929

30-
3130
// Get Location.
32-
double lat, lon;
31+
double lat=0, lon=0;
3332
var query_location = new Soup.Message ("GET", loc_uri);
3433
session.send_message (query_location);
3534

3635
try {
37-
var parser = new Json.Parser();
36+
var parser = new Json.Parser();
3837

39-
parser.load_from_data((string) query_location.response_body.flatten().data, -1);
38+
parser.load_from_data((string) query_location.response_body.flatten().data, -1);
4039

41-
var root_object = parser.get_root().get_object();
42-
lat = root_object.get_double_member("latitude");
43-
lon = root_object.get_double_member("longitude");
40+
var root_object = parser.get_root().get_object();
41+
lat = root_object.get_double_member("latitude");
42+
lon = root_object.get_double_member("longitude");
4443
var city = root_object.get_string_member("city");
4544

4645
stderr.printf("Location : lat : %g, lon : %g \n", lat, lon);
4746
stderr.printf("Location : City: %s \n", city);
4847

4948
}catch (Error e){
50-
stderr.printf(" Unable to get location\n");
51-
return info ;
49+
stderr.printf(" Unable to get location\n");
50+
// return;// info ;
5251
}
53-
54-
52+
5553

5654
var weather_uri = uri + lat.to_string() + "," + lon.to_string();
5755
var message = new Soup.Message ("GET", weather_uri);
5856
session.send_message (message);
5957

60-
58+
6159
try {
6260
var parser = new Json.Parser ();
63-
61+
6462
parser.load_from_data ((string) message.response_body.flatten().data, -1);
6563

6664
var root_object = parser.get_root ().get_object ();
@@ -71,12 +69,12 @@ string get_ip(Soup.Session session) {
7169
stderr.printf("current : %s\n", summary);
7270
info.short_discription = summary;
7371
info.temperature = temp;
74-
72+
7573

7674
} catch (Error e) {
7775
stderr.printf ("I guess something is not working... %s \n", e.message);
7876
}
79-
80-
return info;
81-
77+
display_widget.update_state(info.short_discription,info.temperature);
78+
79+
return;
8280
}

0 commit comments

Comments
 (0)