Undo state of toggled checkbox in settings


In my package config, I have a checkbox to toggle a custom tool-bar. Whenever the checkbox is clicked, onDidChange will display a dialog like the following.

atom.config.onDidChange "#{meta.name}.toolbar", ({isValue, wasValue}) => @toggleComponents(isValue, wasValue, 'toolbar')

toggleComponents: (isValue, wasValue, component) ->
    message: "Reload required"
    detailedMessage: 'Do you want to reload now?'
      "Reload window": ->
      "Cancel": ->
        # this does nothing
        atom.config.set("#{meta.name}.#{component}", wasValue)

The problem with this is, that the state of the checkbox always changes, which is unintended when the user clicks “Cancel”. Does the API offer any ways to avoid this or do I need to undo the selection myself?


Atom’s configuration system doesn’t have a way to support cancelable settings like that. There is a new configuration setting for a custom title bar on macOS that requires a restart to take effect. But if you cancel the restart, it doesn’t try to revert the setting change. You may have to go with a system like that one.


I just realized that resetting the option might be undesired: a user might want to change the setting without reloading the window immediately. But thanks for the link, this might be useful in the future.