[gnome-shell-extensions/extension-live-disable: 10/11] systemMonitor: port to new extension API



commit 231e1f610a104c02e056c0701a09c1e2ba80e96b
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Aug 2 23:33:58 2011 +0200

    systemMonitor: port to new extension API
    
    main() has been	replaced by init(), enable() and disable()

 extensions/systemMonitor/extension.js |   35 ++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/extensions/systemMonitor/extension.js b/extensions/systemMonitor/extension.js
index e9231da..1ecf69e 100644
--- a/extensions/systemMonitor/extension.js
+++ b/extensions/systemMonitor/extension.js
@@ -9,6 +9,10 @@ const Shell = imports.gi.Shell;
 
 const Main = imports.ui.main;
 
+let _cpuIndicator;
+let _memIndicator;
+let _box;
+
 function Indicator() {
     this._init();
 }
@@ -24,13 +28,22 @@ Indicator.prototype = {
             app.open_new_window(-1);
         });
 
-	Mainloop.timeout_add(250, Lang.bind(this, function () {
+	this._timeoutId = Mainloop.timeout_add(250, Lang.bind(this, function () {
 	    this._updateValues();
             this.actor.queue_repaint();
             return true;
 	}));
     },
 
+    destroy: function() {
+        if (this._timeoutId) {
+            Mainloop.source_remove(this._timeoutId);
+            this._timeoutId = 0;
+        }
+
+        this.actor.destroy();
+    },
+
     _initValues: function() {
     },
 
@@ -125,9 +138,21 @@ MemoryIndicator.prototype = {
     }
 };
 
-function main() {
-    let box = new St.BoxLayout({ style_class: 'extension-systemMonitor-container' });
-    box.add((new CpuIndicator()).actor);
-    box.add((new MemoryIndicator()).actor);
+function init() {
+    // nothing to do here
+}
+
+function enable() {
+    _cpuIndicator = new CpuIndicator(); 
+    _memIndicator = new MemIndicator();
+    _box = new St.BoxLayout({ style_class: 'extension-systemMonitor-container' });
+    box.add(_cpuIndicator.actor);
+    box.add(_memIndicator.actor);
     Main.messageTray.actor.add_actor(box);
 }
+
+function disable() {
+    _cpuIndicator.destroy();
+    _memIndicator.destroy();
+    _box.destroy();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]