1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#!/usr/bin/gjs
/* jshint moz: true, multistr: true */
/* global imports */
const Gio = imports.gi.Gio;
const Mainloop = imports.mainloop;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
const AccuracyLevel = {
COUNTRY: 1,
CITY: 4,
NEIGHBORHOOD: 5,
STREET: 6,
EXACT: 8
};
const API_URL = 'http://api.open-notify.org/iss-now.json';
const ManagerIface = '<node> \
<interface name="org.freedesktop.GeoClue2.Manager"> \
<method name="GetClient"> \
<arg type="o" name="client" direction="out"/> \
</method> \
</interface> \
</node>';
const ManagerProxy = Gio.DBusProxy.makeProxyWrapper(ManagerIface);
const ClientInterface = '<node> \
<interface name="org.freedesktop.GeoClue2.Client"> \
<property name="Location" type="o" access="read"/> \
<property name="DesktopId" type="s" access="readwrite"/> \
<property name="RequestedAccuracyLevel" type="u" access="readwrite"/> \
<property name="DistanceThreshold" type="u" access="readwrite"/> \
<property name="Active" type="b" access="read"/> \
<method name="Start"/> \
<method name="Stop"/> \
<signal name="LocationUpdated"> \
<arg name="old" type="o"/> \
<arg name="new" type="o"/> \
</signal> \
</interface> \
</node>';
const ClientProxy = Gio.DBusProxy.makeProxyWrapper(ClientInterface);
const LocationInterface = '<node> \
<interface name="org.freedesktop.GeoClue2.Location"> \
<property name="Latitude" type="d" access="read"/> \
<property name="Longitude" type="d" access="read"/> \
<property name="Accuracy" type="d" access="read"/> \
<property name="Description" type="s" access="read"/> \
</interface> \
</node>';
const LocationProxy = Gio.DBusProxy.makeProxyWrapper(LocationInterface);
const ISS_Above = new GObject.Class({
Name: 'ISS_Above',
Extends: GObject.Object,
Signals: {
'processed_data': {
param_types: [
// GObject.TYPE_INT
]
}
},
_init: function(params) {
this.parent(params);
this.managerProxy = new ManagerProxy(Gio.DBus.system,
'org.freedesktop.GeoClue2', '/org/freedesktop/GeoClue2/Manager');
[this.clientAddr] = this.managerProxy.GetClientSync();
print('this.clientAddr = ' + this.clientAddr);
this.current_location = {};
this.iss_coords = null;
this.task_queue = 2; // number of async process to complete
this.clientProxy = new ClientProxy(Gio.DBus.system,
'org.freedesktop.GeoClue2', this.clientAddr);
this.clientProxy.DesktopId = 'gnome-shell-ISS_Above';
this.clientProxy.DistanceThreshold = 10000;
this.clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT;
this.clientProxy.connectSignal('LocationUpdated',
Lang.bind(this, this.onLocationUpdated));
this.clientProxy.StartRemote();
this.connect('processed_data', Lang.bind(this, this.processResult));
},
run: function() {
this.getISScoords();
},
getISScoords: function () {
let self = this;
let iss_api = Gio.file_new_for_uri(API_URL);
iss_api.load_contents_async(null, function(iss_api, result) {
self.iss_coords = JSON.parse(iss_api.load_contents_finish(result)[1]);
print(self.iss_coords.toSource());
self.emit('processed_data');
});
},
onLocationUpdated: function (proxy, sender, [oldPath, newPath]) {
let geoclueLocation = new LocationProxy(Gio.DBus.system,
"org.freedesktop.GeoClue2",
newPath);
print('location:');
print('\tlatitude = ' + geoclueLocation.latitude);
print('\tlongitude = ' + geoclueLocation.longitude);
print('\taccuracy = ' + geoclueLocation.accuracy);
print('\tdescription = ' + geoclueLocation.description);
// this.current_location.latitude = geoclueLocation.latitude;
// this.current_location.longitude = geoclueLocation.longitude;
// this.current_location.accuracy = geoclueLocation.accuracy;
// this.current_location.description = geoclueLocation.description;
this.emit('processed_data');
},
processResult: function() {
this.task_queue--;
print('this.task_queue = ' + this.task_queue);
if (this.task_queue === 0) {
print('location:');
print('\tlatitude = ' + this.current_location.latitude);
print('\tlongitude = ' + this.current_location.longitude);
print('\taccuracy = ' + this.current_location.accuracy);
print('\tdescription = ' + this.current_location.description);
print('\n\niss coordinates: ' + this.iss_coords.toSource());
Mainloop.quit();
}
}
});
let client = new ISS_Above();
client.run();
Mainloop.run();
|