

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

const CI = Components.interfaces;
const CL = Components.classes;
const SERVICE_NAME = "YoonoStartObserver";
const SERVICE_CTRID = "{29ecb220-c802-11dc-95ff-0800200c9a66}";
const CONSOLESERVICE = CL["@mozilla.org/consoleservice;1"].getService(CI.nsIConsoleService);

function YObserver() {
  this.wrappedJSObject = this;
}

var topic = '';

// With FF4, 'app-startup' can no longer be used, 'profile-after-change' must be used instead
if (XPCOMUtils.generateNSGetFactory) {
  topic = "profile-after-change";
} else {
  topic = "app-startup";
}


YObserver.prototype = {
  classDescription: SERVICE_NAME,
  classID:          Components.ID(SERVICE_CTRID),
  contractID:       "@yoono.com/yoono-connect;1",
  QueryInterface: XPCOMUtils.generateQI([CI.nsIObserver,CI.nsISupports]),
  _xpcom_categories: [
    {
      category: topic,
      entry: SERVICE_NAME,
      service: true
    }
  ],

  observe: function(aSubject, aTopic, aData) {
    if (aTopic != topic) return;

    // Just notify main module of application startup
    Components.utils.import("resource://yoono/yoonoService.js");
    YOONO_CMPT.observe(aSubject, aTopic, aData);
  }
};

/**
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
*/
if (XPCOMUtils.generateNSGetFactory)
    var NSGetFactory = XPCOMUtils.generateNSGetFactory([YObserver]);
else
    var NSGetModule = XPCOMUtils.generateNSGetModule([YObserver]);
