On Oct 13, 9:04*pm, Leni wrote:
> gNeandr wrote:
> > *[13.10.2009 23:49] * *ğLeniĞ wrote:
> >> Hi, I am wondering how to write code in an addon that runs just once
> >> on a brand-new installation of an addon, but not an upgrade of an addon.

>
> >> In other words, the code shouldn't run for users who already have the
> >> addon installed, just brand-new users. *So as written, this technique
> >> won't do the trick:
> >>http://firefoxdev.blogspot.com/2009/...come-page.html
> >> because the code runs once for all users, not just brand-new
> >> installations.

>
> >> I already have a kludgy workaround that I can use, so really I'm just
> >> asking if there is some sort of 'best-practice' way to do this.

>
> >> Leni.

> > Is the "kludgy workaround" just reading a specific prefs for your
> > extension? If it's already there it's not a brand-new installation.
> > 'best-practice' way *or not, very simple I think.

A simple way. Mine addon have preference "version number" that
defaults to "0.0.0". Then addon checking on session load stored
version number against current version number from install.rdf. And
then set it to the one that is inside of instal.rdf. So basically, all
you need is to check if the version number is "0.0.0" and then update
it.

And user could not possibly interfere with it (unless they manually
set version number preference back to "0.0.0", thus running your code
second time. Which is very unlikely)

Vitaly

> > Günter

>
> The kludgy workaround involves testing some other pref that users always
> change when they intially configure the addon. *If that other pref is
> set, then firstrun is set to false.
>
> This mostly works except for an (unlikely) use-case where it gives the
> wrong result: if a brand-new user happens to set that inital config pref
> then immediately restart, firstrun is set to false and the code in
> question is never executed. *That'll be infrequent enough to not be a
> big deal, but if there's a better solution for "run once on initial
> install" it would be better.
>
> Leni.