Setting Atom user config values when my package is installed


#1

Hey all,

I’m creating a new package and I want to know if there’s a way to set config values when somebody first installs the package (like setting default values upon install). Is there some kind of post-install hook I can tap into?

Thanks!


#2

I’m pretty sure what you’re looking for is the configDefaults property on the package:

https://github.com/atom/tree-view/blob/master/lib/tree.coffee#L4-7

The best part is that these aren’t just the defaults on initial install, there is support in Atom’s configuration system to show the default value if the user hasn’t added their own configuration and if they delete their own configuration it goes back to the default.


#3

@leedohm So if I want this to only run on first start (aka just installed) where do I need to put this in my package? Should it be in my main file? Also, how do I ensure the config key namespace is preserved? Something like this might work:

configDefaults:
    my_namespace:
        config_val_1: 'some_value'
        config_val_2: 'some_value2'

Something like that?


#4

It’s data … so technically it doesn’t “run”. These are just the defaults for your package. And yes, the way you have it is correct, to my understanding.


#5

If you want them to apply only on the first run, which is what I understand you were asking, I suppose you ought to overwrite them with new values whenever the user changes them?