diff options
Diffstat (limited to 'extension.js')
-rw-r--r-- | extension.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/extension.js b/extension.js index e3284e7..491e935 100644 --- a/extension.js +++ b/extension.js @@ -3,6 +3,7 @@ const Gio = imports.gi.Gio; const Mainloop = imports.mainloop; const GObject = imports.gi.GObject; +const GLib = imports.gi.GLib; const Lang = imports.lang; const St = imports.gi.St; const Main = imports.ui.main; @@ -57,7 +58,7 @@ const LocationInterface = '<node> \ const LocationProxy = Gio.DBusProxy.makeProxyWrapper(LocationInterface); // global variables -let text, button, label, client; +let client; const ISS_Above = new GObject.Class({ Name: 'ISS_Above', @@ -80,6 +81,8 @@ const ISS_Above = new GObject.Class({ 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; @@ -110,11 +113,13 @@ const ISS_Above = new GObject.Class({ }, run: function() { + let self = this; this.getISScoords(function () { print('run: processing new coords'); - this.task_queue = 1; - this.processResult(); + self.task_queue = 1; + self.processResult(); }); + return GLib.SOURCE_CONTINUE; }, onLocationUpdated: function (proxy, sender, [oldPath, newPath]) { @@ -135,7 +140,7 @@ const ISS_Above = new GObject.Class({ this.emit('processed_data'); }, - /** + /** * Calculate distance in km of two geographical points * * @param lat1 Number latitude of the first point @@ -193,12 +198,12 @@ const ISS_Above = new GObject.Class({ // https://developer.gnome.org/clutter/stable/ClutterActor.html if (dist < SOUGHT_DISTANCE) { // Make the label text completely opaque - label.set_opacity(255); + this.label.set_opacity(255); print('Make label opaque'); } else { // Make the label text completely transparent - label.set_opacity(0); + this.label.set_opacity(0); print('Make label transparent'); } } @@ -212,14 +217,14 @@ function init() { function enable() { print('ENABLING ISS Above'); - button = new St.Bin({ style_class: 'panel-button', + let button = new St.Bin({ style_class: 'panel-button', reactive: true, can_focus: true, x_fill: true, y_fill: false, track_hover: true }); // http://blog.fpmurphy.com/2011/04/replace-gnome-shell-activities-text-string-with-icon.html - label = new St.Label({ text: 'ISS' }); + let label = new St.Label({ text: 'ISS' }); print('button is ' + button); button.set_child(label); @@ -229,17 +234,15 @@ function enable() { client = new ISS_Above(); client.getISScoords(); + client.button = button; + client.label = label; client.timeout_source = Mainloop.timeout_add_seconds( - CHECK_INTERVAL, client.run); - - Mainloop.run(); + CHECK_INTERVAL, Lang.bind(client, client.run)); } function disable() { print('DISABLING ISS Above'); - Main.panel._rightBox.remove_child(button); + Main.panel._rightBox.remove_child(client.button); Mainloop.source_remove(client.timeout_source); - - Mainloop.quit(); } |