diff options
-rw-r--r-- | geoclue.js | 8 | ||||
-rw-r--r-- | gnome-shell-ISS_Above.desktop | 2 | ||||
-rw-r--r-- | iss-now.json | 8 | ||||
-rw-r--r-- | iss_get_data.js | 97 |
4 files changed, 108 insertions, 7 deletions
@@ -3,7 +3,7 @@ const GLib = imports.gi.GLib; const Gio = imports.gi.Gio; -const Geocode = imports.gi.GeocodeGlib; +const Json = imports.gi.Json; const Lang = imports.lang; const Mainloop = imports.mainloop; @@ -56,10 +56,6 @@ function onLocationUpdated(proxy, sender, [oldPath, newPath]) { let geoclueLocation = new LocationProxy(Gio.DBus.system, "org.freedesktop.GeoClue2", newPath); - let location = new Geocode.Location({ latitude: geoclueLocation.Latitude, - longitude: geoclueLocation.Longitude, - accuracy: geoclueLocation.Accuracy, - description: geoclueLocation.Description }); print('location:'); print('\tlatitude = ' + geoclueLocation.Latitude); print('\tlongitude = ' + geoclueLocation.Longitude); @@ -76,7 +72,7 @@ let [clientAddr] = _managerProxy.GetClientSync(); let clientProxy = new ClientProxy(Gio.DBus.system, 'org.freedesktop.GeoClue2', clientAddr); -clientProxy.DesktopId = 'geoclue-test-simple'; +clientProxy.DesktopId = 'gnome-shell-ISS_Above'; clientProxy.DistanceThreshold = 10000; clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT; let updatedId = clientProxy.connectSignal('LocationUpdated', diff --git a/gnome-shell-ISS_Above.desktop b/gnome-shell-ISS_Above.desktop index 0870237..0559ceb 100644 --- a/gnome-shell-ISS_Above.desktop +++ b/gnome-shell-ISS_Above.desktop @@ -2,7 +2,7 @@ Name=ISS Above Gnome-Shell extension GenericName=ISS Above Gnome-Shell extension Keywords=geolocation;gnome-shell -Exec=/home/matej/archiv/2015/projekty/ISS_Above@mcepl.cepl.eu/extension.js +Exec=/home/matej/archiv/2015/projekty/ISS_Above@mcepl.cepl.eu/iss_get_data.js Icon=mark-location-symbolic NoDisplay=true Terminal=false diff --git a/iss-now.json b/iss-now.json new file mode 100644 index 0000000..6fcdc7b --- /dev/null +++ b/iss-now.json @@ -0,0 +1,8 @@ +{ + "iss_position": { + "latitude": 50.73479883411104, + "longitude": -45.52410215782167 + }, + "message": "success", + "timestamp": 1430582644 +}
\ No newline at end of file diff --git a/iss_get_data.js b/iss_get_data.js new file mode 100644 index 0000000..cf97015 --- /dev/null +++ b/iss_get_data.js @@ -0,0 +1,97 @@ +#!/usr/bin/gjs +/* global imports */ + +const Json = imports.gi.Json; +const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; +const Lang = imports.lang; +const Mainloop = imports.mainloop; + +const AccuracyLevel = { + COUNTRY: 1, + CITY: 4, + NEIGHBORHOOD: 5, + STREET: 6, + EXACT: 8 +}; + +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); + +function get_ISS_coords() { + const API_URL = 'http://api.open-notify.org/iss-now.json'; + // let iss_api = Gio.file_new_for_uri(API_URL); + let iss_api = Gio.file_new_for_uri(API_URL); + print('filename: ' + iss_api + '\n---------------'); + iss_api.load_contents_async(null, function(data) { + print('data = ' + data); + let iss_coords = JSON.parse(data); + print(Object.keys(iss_coords)); + print(iss_coords.toSource()); + iss_api.load_contents_finish(data); + }); +} + +function onLocationUpdated(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._updateLocation(location); + Mainloop.quit(); +} + +const _managerProxy = new ManagerProxy(Gio.DBus.system, + 'org.freedesktop.GeoClue2', '/org/freedesktop/GeoClue2/Manager'); + +const [clientAddr] = _managerProxy.GetClientSync(); + +const clientProxy = new ClientProxy(Gio.DBus.system, + 'org.freedesktop.GeoClue2', clientAddr); +clientProxy.DesktopId = 'gnome-shell-ISS_Above'; +clientProxy.DistanceThreshold = 10000; +clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT; +let updatedId = clientProxy.connectSignal('LocationUpdated', + onLocationUpdated); +clientProxy.StartRemote(); + +get_ISS_coords(); + +Mainloop.run(); |