(function() {
  var error, keytar, tokenName;

  try {
    keytar = require('keytar');
  } catch (error1) {
    error = error1;
    if (process.platform === 'linux') {
      keytar = {
        findPassword: function() {},
        replacePassword: function() {}
      };
    } else {
      throw error;
    }
  }

  tokenName = 'Atom.io API Token';

  module.exports = {
    getToken: function(callback) {
      return keytar.findPassword(tokenName).then(function(token) {
        if (token) {
          callback(null, token);
          return;
        }
        if (token = process.env.ATOM_ACCESS_TOKEN) {
          callback(null, token);
          return;
        }
        return callback("No Atom.io API token in keychain\nRun `apm login` or set the `ATOM_ACCESS_TOKEN` environment variable.");
      });
    },
    saveToken: function(token) {
      return keytar.setPassword(tokenName, 'atom.io', token);
    }
  };

}).call(this);
