<commit_before>import NylasStore from 'nylas-store';
import {remote} from 'electron';

import EdgehillAPI from '../edgehill-api';

const autoUpdater = remote.getGlobal('application').autoUpdateManager;

class UpdateChannelStore extends NylasStore {
  constructor() {
    super();
    this._current = {name: 'Loading...'};
    this._available = [{name: 'Loading...'}];

    if (NylasEnv.isMainWindow()) {
      this.refreshChannel();
    }
  }

  current() {
    return this._current;
  }

  currentIsUnstable() {
    return this._current && this._current.name.toLowerCase() === 'beta';
  }

  available() {
    return this._available;
  }

  refreshChannel() {
    EdgehillAPI.makeRequest({
      method: 'GET',
      path: `/update-channel`,
      qs: autoUpdater.parameters(),
      json: true,
    }).then(({current, available}) => {
      this._current = current;
      this._available = available;
      this.trigger();
    });
    return null;
  }

  setChannel(channelName) {
    EdgehillAPI.makeRequest({
      method: 'POST',
      path: `/update-channel`,
      qs: Object.assign({channel: channelName}, autoUpdater.parameters()),
      json: true,
    }).then(({current, available}) => {
      this._current = current;
      this._available = available;
      this.trigger();
    }).catch((err) => {
      NylasEnv.showErrorDialog(err.toString())
      this.trigger();
    });
    return null;
  }
}

export default new UpdateChannelStore();
<commit_msg>[feat] [autoupdater] Let N1 specify a preferred channel.<commit_after>import NylasStore from 'nylas-store';
import {remote} from 'electron';

import EdgehillAPI from '../edgehill-api';

const autoUpdater = remote.getGlobal('application').autoUpdateManager;
const preferredChannel = 'stable';

class UpdateChannelStore extends NylasStore {
  constructor() {
    super();
    this._current = {name: 'Loading...'};
    this._available = [{name: 'Loading...'}];

    if (NylasEnv.isMainWindow()) {
      this.refreshChannel();
    }
  }

  current() {
    return this._current;
  }

  currentIsUnstable() {
    return this._current && this._current.name.toLowerCase() === 'beta';
  }

  available() {
    return this._available;
  }

  refreshChannel() {
    EdgehillAPI.makeRequest({
      method: 'GET',
      path: `/update-channel`,
      qs: Object.assign({preferredChannel: preferredChannel}, autoUpdater.parameters()),
      json: true,
    }).then(({current, available}) => {
      this._current = current;
      this._available = available;
      this.trigger();
    });
    return null;
  }

  setChannel(channelName) {
    EdgehillAPI.makeRequest({
      method: 'POST',
      path: `/update-channel`,
      qs: Object.assign({channel: channelName,
                         preferredChannel: preferredChannel}, autoUpdater.parameters()),
      json: true,
    }).then(({current, available}) => {
      this._current = current;
      this._available = available;
      this.trigger();
    }).catch((err) => {
      NylasEnv.showErrorDialog(err.toString())
      this.trigger();
    });
    return null;
  }
}

export default new UpdateChannelStore();

{'fraction_non_alphanumeric': 0.15310698270339526, 'fraction_numerical': 0.00032030749519538755, 'mean_word_length': 2.998719590268886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2480481', 'n_tokens_mistral': 932, 'n_tokens_neox': 923, 'n_words': 190}