Custom package, how-to add settings to config.cson?


#1

Hello friends,

How can I add some "persistent" settings relative to my custom package in my config.cson ? I wants this settings set only once on the computer or manually modified by the user.

Now I’m able to add some config settings to config.cson with:

atom.config.set(‘custompackage.thingVolume’, ‘20’)

But settings are reset at each package start…

Thank you in advance for your answers :slight_smile:


#2

Do you mean normal package settings, or do you want something specific?

Normal package setings should already remember their values; they are added to the config.cson file. If the default value is static, you can declare them in your package.json to make them appear even when the package is deactivated, like this

{
  "configSchema": {
    "settingName": {
      "description": "foo",
      "type": "boolean",
      "default": true
    },
    "otherSetting": {
      ...
    },
    ...
  }
}

#3

Ok Aerij, thank you very much for your answer.

I think i mean normal package settings (just some path and boolean data), i’m clearly not a JavaScript or atom master ^^

I did want you said, but I think there is something wrong with my package.json :

{
  "name": "Happy-Engineer",
  "main": "./lib/happy-engineer",
  "version": "0.0.0",
  "description": "A short description of your package",
  "keywords": [
  ],
  "activationCommands": {
    "atom-workspace": "happy-engineer:fetch"
  },
  "repository": "https://github.com",
  "license": "MIT",
  "engines": {
    "atom": ">=1.0.0 <2.0.0"
  },
  "dependencies": {
  },
  "configSchema": {
    "settingName": {
      "description": "foo",
      "type": "boolean",
      "default": true
    }
  }
}

I added the configSchema but it cannot see any changes in my config.cson

Do i need to do others things or it should already works ?

Best regards


#4

The config schema is static; it won’t be changed by the config.cson.

In your program, you should be able to call atom.config.get("packageName. settingName") to get the current value, which is retained across sessions. If it is missing from the config.cson file, the default from the package.json schema will be used.

Are you saying this setting never appears in the config.cson, even when you change it (e.g., through the Settings GUI?)


#5

Ok i understand now the difference between config.cson and settings defined in package.json

Unfortunatly when i use the package.json of my previous post

the commande atom.config.get("packageName. settingName") return undefined.

Do you know why ?

In fact, none of my settings delcared in package.json are displayed in my package settings GUI… it’s nominal ?

Thank you for your answers :slight_smile: