<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -43,9 +43,12 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const loader = Cc['@mozilla.org/moz/jssubscript-loader;1']
     .getService(Ci.mozIJSSubScriptLoader);
-const pref = Cc['@mozilla.org/preferences-service;1']
-    .getService(Ci.nsIPrefService)
-    .getBranch('extensions.mozrepl.');
+const srvPref = Cc['@mozilla.org/preferences-service;1']
+    .getService(Ci.nsIPrefService);
+const srvObserver = Cc['@mozilla.org/observer-service;1']
+    .getService(Ci.nsIObserverService);
+const pref = srvPref.getBranch('extensions.mozlab.mozrepl.');
+
 
 function REPL() {};
 loader.loadSubScript('chrome://mozrepl/content/repl.js', REPL.prototype);
@@ -85,11 +88,6 @@ var sessions = {
 };
 
 
-function init() {
-    if(pref.getBoolPref('autoStart'))
-        start(pref.getIntPref('port'));
-}
-
 function start(port) {
     try {
         serv = Cc['@mozilla.org/network/server-socket;1']
@@ -165,6 +163,29 @@ function isActive() {
         return true;
 }
 
+function observe(subject, topic, data) {
+    switch(topic) {
+    case 'app-startup':
+        srvObserver.addObserver(this, 'network:offline-status-changed', false);
+
+        if(srvPref.getBranch('network.').getBoolPref('online') &amp;&amp;
+           pref.getBoolPref('autoStart'))
+            this.start(pref.getIntPref('port'));
+        break;
+    case 'network:offline-status-changed':
+        switch(data) {
+        case 'online':
+            if(pref.getBoolPref('autoStart'))
+                this.start(pref.getIntPref('port'));
+            break;
+        case 'offline':
+            if(isActive())
+                this.stop();
+            break;
+        }
+        break;
+    }
+}
 
 // UTILITIES
 // ----------------------------------------------------------------------
@@ -172,3 +193,4 @@ function isActive() {
 function log(msg) {
     dump(msg + '\n');
 }
+</diff>
      <filename>chrome/content/server.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
-IDLC=/usr/lib/firefox/xpidl
-INC=/usr/share/idl/mozilla/
+IDLC=/usr/lib/xulrunner-1.9/xpidl
+INC=/usr/share/idl/xulrunner-1.9/stable/
 XPTS=MozRepl.xpt
 
 all: $(XPTS)</diff>
      <filename>components/Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,18 @@
 #include &quot;nsISupports.idl&quot;
+#include &quot;nsIObserver.idl&quot;
+
+interface nsIObserver;
 
 [scriptable, uuid(57f4284b-1f9b-4990-8525-9ed5cbb23e01)]
 interface nsIMozRepl: nsISupports
 {
     void start(in short port);
+
     void stop();
+
     boolean isActive();
+
     void reload();
-};  
+
+    void observe(in nsISupports aSubject, in string aTopic, in wstring aData);
+};</diff>
      <filename>components/MozRepl.idl</filename>
    </modified>
    <modified>
      <diff>@@ -13,10 +13,13 @@ const INTERFACE = Components.interfaces.nsIMozRepl;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
+const Cu = Components.utils;
 const loader = Cc['@mozilla.org/moz/jssubscript-loader;1']
     .getService(Ci.mozIJSSubScriptLoader);
 
-function Component() {}
+function Component() {
+    this.wrappedJSObject = this;
+}
 
 Component.prototype = {
     reload: function() {
@@ -25,7 +28,8 @@ Component.prototype = {
 
     QueryInterface: function(aIID) {
         if(!aIID.equals(INTERFACE) &amp;&amp;
-           !aIID.equals(Ci.nsISupports))
+           !aIID.equals(Ci.nsISupports) &amp;&amp;
+           !aIID.equals(Ci.nsIObserver))
             throw Cr.NS_ERROR_NO_INTERFACE;
         return this;
     }
@@ -37,7 +41,6 @@ var Factory = {
         if(aOuter != null)
             throw Cr.NS_ERROR_NO_AGGREGATION;
         var component = new Component();
-        component.init();
 
         return component.QueryInterface(aIID);
     }
@@ -51,14 +54,23 @@ var Module = {
             this._firstTime = false;
             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
         };
+
         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
         aCompMgr.registerFactoryLocation(
             CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
+
+        var catMan = Cc['@mozilla.org/categorymanager;1'].
+            getService(Ci.nsICategoryManager);
+        catMan.addCategoryEntry('app-startup', 'MozRepl', 'service,' + CONTRACT_ID, true, true);
     },
 
-    unregisterSelf: function(aCompMgr, aLocation, aType) {
+    unregisterSelf: function(aCompMgr, aLocation, aType) {pp
         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
+
+        var catMan = Cc['@mozilla.org/categorymanager;1'].
+            getService(Ci.nsICategoryManager);
+        catMan.deleteCategoryEntry('app-startup', 'service,' + CONTRACT_ID, true);
     },
 
     getClassObject: function(aCompMgr, aCID, aIID) {</diff>
      <filename>components/MozRepl.js</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>components/MozRepl.xpt</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b978d5844539ef4a8e9de11e18465eb6560e1959</id>
    </parent>
  </parents>
  <author>
    <name>Massimiliano Mirra</name>
    <email>bard@hyperstruct.net</email>
  </author>
  <url>http://github.com/bard/mozrepl/commit/85ae8461a4367e3e2af2f526c72f96a0471f90a0</url>
  <id>85ae8461a4367e3e2af2f526c72f96a0471f90a0</id>
  <committed-date>2008-09-25T11:53:10-07:00</committed-date>
  <authored-date>2008-09-23T14:09:35-07:00</authored-date>
  <message>REPL: Autostart no longer depends on UI.  When autostart is set, REPL also goes on- and off-line with the host app.</message>
  <tree>ad98748947e1cb31cbf5235ea29ff61df7b2a7b0</tree>
  <committer>
    <name>Massimiliano Mirra</name>
    <email>bard@hyperstruct.net</email>
  </committer>
</commit>
