diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | extension.js | 236 | ||||
-rw-r--r-- | gnome-shell-ISS_Above.desktop | 9 | ||||
-rw-r--r-- | iss-now.json | 8 | ||||
-rwxr-xr-x | iss_get_data.js | 177 | ||||
-rw-r--r-- | metadata.json | 10 |
6 files changed, 0 insertions, 447 deletions
diff --git a/Makefile b/Makefile deleted file mode 100644 index b9bd7af..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: ISS_Above.zip - -ISS_Above.zip: extension.js metadata.json - zip -9vj $@ $^ - -clean: - rm -fv ISS_Above.zip *~ diff --git a/extension.js b/extension.js deleted file mode 100644 index d4ca8d7..0000000 --- a/extension.js +++ /dev/null @@ -1,236 +0,0 @@ -/* jshint moz: true, multistr: true */ -/* global imports */ -const Gio = imports.gi.Gio; -const GObject = imports.gi.GObject; -const GLib = imports.gi.GLib; -const Lang = imports.lang; -const St = imports.gi.St; -const Main = imports.ui.main; - -const AccuracyLevel = { - COUNTRY: 1, - CITY: 4, - NEIGHBORHOOD: 5, - STREET: 6, - EXACT: 8 -}; - -const API_URL = 'http://api.open-notify.org/iss-now.json'; -// The minimal distance in km for icon to be made visible -const SOUGHT_DISTANCE = 1000; -const CHECK_INTERVAL = 2 * 60; // how often (in sec) the check for ISS is done -const VISIBLE_TEXT = 'ISS'; -const INVISIBLE_TEXT = '___'; - -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); - -// global variables -let client; - -const ISS_Above = new Lang.Class({ - Name: 'ISS_Above', - Extends: GObject.Object, - - Signals: { - 'processed_data': { - param_types: [ - // GObject.TYPE_INT - ] - } - }, - - _init: function(params) { - this.parent(); - - this.managerProxy = new ManagerProxy(Gio.DBus.system, - 'org.freedesktop.GeoClue2', '/org/freedesktop/GeoClue2/Manager'); - - [this.clientAddr] = this.managerProxy.GetClientSync(); - - this.current_location = null; - this.iss_coords = null; - this.button = null; - this.label = null; - this.task_queue = 2; // number of async process to complete - this.timeout_source = null; - - 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', () => this.processResult()); - }, - - getISScoords: function (cb_process) { - let iss_api = Gio.file_new_for_uri(API_URL); - iss_api.load_contents_async(null, (iss_api, result) => { - this.iss_coords = JSON.parse(iss_api.load_contents_finish(result)[1]); - if (cb_process !== undefined) { - cb_process(); - } - else { - this.emit('processed_data'); - } - }); - }, - - run: function() { - this.getISScoords(() => { - this.task_queue = 1; - this.processResult(); - }); - return GLib.SOURCE_CONTINUE; - }, - - onLocationUpdated: function (proxy, sender, [oldPath, newPath]) { - let geoclueLocation = new LocationProxy(Gio.DBus.system, - "org.freedesktop.GeoClue2", - newPath); - - // Yes, I take both null and undefined - if (geoclueLocation.Latitude != null) { - this.current_location = { - Latitude: geoclueLocation.Latitude, - Longitude: geoclueLocation.Longitude, - Accuracy: geoclueLocation.Accuracy, - Description: geoclueLocation.Description - }; - } - - this.emit('processed_data'); - }, - - /** - * Calculate distance in km of two geographical points - * - * @param lat1 Number latitude of the first point - * @param long1 Number longitude of the first point - * @param lat2 Number latitude of the second point - * @param long2 Number longitude of the second point - * @return Number distance in km - * - * Described on https://en.wikipedia.org/wiki/Haversine_formula - */ - get_distance: function(lat1, long1, lat2, long2) { - // Mean radius of the Earth in km - const EARTH_R = 6371; - const PI_180 = Math.PI / 180; - - function haversin(fi) { - return (1 - Math.cos(fi)) / 2; - } - - lat1 = lat1 * PI_180; - long1 = long1 * PI_180; - lat2 = lat2 * PI_180; - long2 = long2 * PI_180; - - let dist = 2 * EARTH_R * - Math.asin(Math.sqrt(haversin(lat2 - lat1) + - Math.cos(lat1) * Math.cos(lat2) * haversin(long2 - long1))); - - let test_haversin = haversin(dist / EARTH_R); - if (test_haversin < 1) { - return dist.toFixed(3); - } - else { - throw new Error('haversine(d/r) cannot be over 1, but it is ' + - test_haversin); - } - }, - - processResult: function() { - this.task_queue--; - - if (this.task_queue === 0) { - let dist = this.get_distance(this.current_location.Latitude, - this.current_location.Longitude, - this.iss_coords.iss_position.latitude, - this.iss_coords.iss_position.longitude); - print('ISS is ' + dist + ' km away.'); - - // https://developer.gnome.org/clutter/stable/ClutterActor.html - if (dist < SOUGHT_DISTANCE) { - this.label.text = VISIBLE_TEXT; - } - else { - this.label.text = INVISIBLE_TEXT; - } - } - return false; - } -}); - -// END of ISS_Above object definition - -function init() { -} - -function enable() { - print('ENABLING ISS Above'); - let button = new St.Bin({ style_class: 'panel-button', - reactive: true, - can_focus: true, - x_fill: true, - y_fill: false, - track_hover: true }); - let label = new St.Label({ text: INVISIBLE_TEXT }); - button.child = label; - button.width = 30; - button.height = 21; - - Main.panel._rightBox.insert_child_at_index(button, 0); - - client = new ISS_Above(); - client.getISScoords(); - client.button = button; - client.label = label; - - client.timeout_source = GLib.timeout_add_seconds( - GLib.PRIORITY_DEFAULT, - CHECK_INTERVAL, () => client.run()); -} - -function disable() { - print('DISABLING ISS Above'); - Main.panel._rightBox.remove_child(client.button); - GLib.source_remove(client.timeout_source); -} diff --git a/gnome-shell-ISS_Above.desktop b/gnome-shell-ISS_Above.desktop deleted file mode 100644 index d96a250..0000000 --- a/gnome-shell-ISS_Above.desktop +++ /dev/null @@ -1,9 +0,0 @@ -[Desktop Entry] -Name=ISS Above Gnome-Shell extension -GenericName=ISS Above Gnome-Shell extension -Keywords=geolocation;gnome-shell -Exec=/home/matej/archiv/2015/projekty/ISS_Above/iss_get_data.js -Icon=mark-location-symbolic -NoDisplay=true -Terminal=false -Type=Application diff --git a/iss-now.json b/iss-now.json deleted file mode 100644 index 6fcdc7b..0000000 --- a/iss-now.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "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 deleted file mode 100755 index 0db03c8..0000000 --- a/iss_get_data.js +++ /dev/null @@ -1,177 +0,0 @@ -#!/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(); - - 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); - - 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'); - }, - - /** - * Calculate distance in km of two geographical points - * - * @param lat1 Number latitude of the first point - * @param long1 Number longitude of the first point - * @param lat2 Number latitude of the second point - * @param long2 Number longitude of the second point - * @return Number distance in km - * - * Described on https://en.wikipedia.org/wiki/Haversine_formula - */ - get_distance: function(lat1, long1, lat2, long2) { - // Mean radius of the Earth in km - const EARTH_R = 6371; - const PI_180 = Math.PI / 180; - - function haversin(fi) { - return (1 - Math.cos(fi)) / 2; - } - - lat1 = lat1 * PI_180; - long1 = long1 * PI_180; - lat2 = lat2 * PI_180; - long2 = long2 * PI_180; - - let dist = 2 * EARTH_R * - Math.asin(Math.sqrt(haversin(lat2 - lat1) + - Math.cos(lat1) * Math.cos(lat2) * haversin(long2 - long1))); - - let test_haversin = haversin(dist / EARTH_R); - if (test_haversin < 1) { - return dist.toFixed(3); - } - else { - throw new Error('haversine(d/r) cannot be over 1, but it is ' + - test_haversin); - } - }, - - processResult: function() { - this.task_queue--; - - if (this.task_queue === 0) { - // print('our location: ' + this.current_location.toSource()); - // print('iss coordinates: ' + this.iss_coords.toSource()); - - let dist = this.get_distance(this.current_location.Latitude, - this.current_location.Longitude, - this.iss_coords.iss_position.latitude, - this.iss_coords.iss_position.longitude) - - print('ISS is ' + dist + ' km away.'); - - Mainloop.quit(); - } - } -}); - -let client = new ISS_Above(); -client.run(); - -Mainloop.run(); diff --git a/metadata.json b/metadata.json deleted file mode 100644 index fb5a172..0000000 --- a/metadata.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "description": "Shows an icon when ISS is above you (+- 1000km)", - "name": "ISS Above", - "shell-version": [ - "3.26" - ], - "url": "https://gitlab.com/mcepl/gnome-shell-extension-ISS_Above/", - "uuid": "ISS_Above@mcepl.cepl.eu", - "version": 3 -} |