diff options
-rw-r--r-- | extension.js | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/extension.js b/extension.js index d52ccb6..e3d2293 100644 --- a/extension.js +++ b/extension.js @@ -3,7 +3,6 @@ const Gio = imports.gi.Gio; const GObject = imports.gi.GObject; const GLib = imports.gi.GLib; -const Clutter = imports.gi.Clutter; const Lang = imports.lang; const St = imports.gi.St; const Main = imports.ui.main; @@ -18,8 +17,10 @@ const AccuracyLevel = { 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 = 500; -const CHECK_INTERVAL = 5 * 60; // how often (in sec) the check for ISS is done +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"> \ @@ -85,7 +86,6 @@ const ISS_Above = new Lang.Class({ this.button = null; this.label = null; this.task_queue = 2; // number of async process to complete - print('_init, task_queue = ' + this.task_queue); this.timeout_source = null; this.clientProxy = new ClientProxy(Gio.DBus.system, @@ -103,13 +103,10 @@ const ISS_Above = new Lang.Class({ 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]); - print('this.iss_coords = ' + this.iss_coords.toSource()); - print('cb_process = ' + cb_process); if (cb_process !== undefined) { cb_process(); } else { - print('emitting "processed_data" signal'); this.emit('processed_data'); } }); @@ -117,9 +114,7 @@ const ISS_Above = new Lang.Class({ run: function() { this.getISScoords(() => { - print('run: processing new coords'); this.task_queue = 1; - print('run, task_queue = ' + this.task_queue); this.processResult(); }); return GLib.SOURCE_CONTINUE; @@ -183,16 +178,9 @@ const ISS_Above = new Lang.Class({ }, processResult: function() { - print('processResult, start: task_queue = ' + this.task_queue); this.task_queue--; - print('processResult, deciding: task_queue = ' + this.task_queue); if (this.task_queue === 0) { - print('processResult: our location: ' + - this.current_location.toSource()); - print('processResult: 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, @@ -201,18 +189,10 @@ const ISS_Above = new Lang.Class({ // https://developer.gnome.org/clutter/stable/ClutterActor.html if (dist < SOUGHT_DISTANCE) { - // Make the label text completely opaque - // this.label.set_opacity(255); - this.label.set_background_color( - Clutter.Color.get_static(Clutter.StaticColor.RED)); - print('Make label opaque'); + this.label.text = VISIBLE_TEXT; } else { - // Make the label text completely transparent - // this.label.set_opacity(0); - this.label.set_background_color( - Clutter.Color.get_static(Clutter.StaticColor.GREEN)); - print('Make label transparent'); + this.label.text = INVISIBLE_TEXT; } } return false; @@ -232,12 +212,10 @@ function enable() { x_fill: true, y_fill: false, track_hover: true }); - // http://blog.fpmurphy.com/2011/04/replace-gnome-shell-activities-text-string-with-icon.html - let label = new St.Label({ text: 'ISS' }); - print('button is ' + button); - - button.set_child(label); - label.set_opacity(0); + 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); @@ -247,7 +225,8 @@ function enable() { client.label = label; client.timeout_source = GLib.timeout_add_seconds( - CHECK_INTERVAL, () => client.run()); + GLib.PRIORITY_DEFAULT, + CHECK_INTERVAL, () => client.run()); } function disable() { |