Search code examples
xulxulrunner

How to run code during the "firstrun" of a Xulrunner Application


I am writing a custom xulrunner-based app and I wish to have some files deployed in the user profile the first time the application is run.

I placed the files in my application's defaults/profile directory but they did not get copied to user's profile during the first run of the application.

Should I write some additional code or this should happen automatically? The thing that gets copied for sure is the application default preferences.

Is there a "standard" way offered by Firefox or some of the many mozilla applications? Any link to some reading will be helpful. Any hint is valuable.

Thanks in advance.


Solution

  • Unfortunately the standard way of doing first run code is to use the pref system to determine if you have or haven't done something yet. There are a few gotchas though:

    • Make sure this code only runs once. If your firstrun code is in an overlay or main browser window, it can be run multiple times (once per window)

    • after you run the code and set the pref, make sure you flush the prefs, since prefs are written on close and will only be saved when you close.

      Components.classes['@mozilla.org/preferences-service;1'] .getService(Components.interfaces.nsIPrefService) .savePrefFile(null);