<commit_before>/**
 * Copyright (C) 2012-2019 Mailvelope GmbH
 * Licensed under the GNU Affero General Public License version 3
 */

import React from 'react';
import {port, AppOptions} from '../app';
import * as l10n from '../../lib/l10n';
import Trans from '../../components/util/Trans';

l10n.register([
  'form_cancel',
  'form_save',
  'general_default_key_always',
  'general_default_key_auto_sign',
  'general_gnupg_check_availability',
  'general_gnupg_installed_question',
  'general_gnupg_not_available',
  'general_gnupg_prefer',
  'general_openpgp_current',
  'general_openpgp_prefer',
  'general_openpgp_preferences',
  'general_prefer_gnupg_note',
  'keygrid_default_key',
  'settings_general'
]);

export default class General extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      auto_add_primary: false,
      auto_sign_msg: false,
      prefer_gnupg: false,
      modified: false,
      nativeMessaging: true
    };
    this.handleCheck = this.handleCheck.bind(this);
    this.handleSave = this.handleSave.bind(this);
    this.handleCancel = this.handleCancel.bind(this);
  }

  componentDidMount() {
    this.loadPrefs();
    chrome.permissions.contains({permissions: ['nativeMessaging']}, nativeMessaging => this.setState({nativeMessaging}));
  }

  async loadPrefs() {
    const {general} = await port.send('get-prefs');
    this.setState({
      auto_add_primary: general.auto_add_primary,
      auto_sign_msg: general.auto_sign_msg,
      prefer_gnupg: general.prefer_gnupg,
      modified: false
    });
  }

  handleCheck({target}) {
    this.setState({[target.name]: target.checked, modified: true});
  }

  async handleSave() {
    const update = {
      general: {
        auto_add_primary: this.state.auto_add_primary,
        auto_sign_msg: this.state.auto_sign_msg,
        prefer_gnupg: this.state.prefer_gnupg
      }
    };
    await port.send('set-prefs', {prefs: update});
    this.setState({modified: false});
  }

  handleCancel() {
    this.loadPrefs();<commit_msg>Fix chrome.permissions not available in embedded settings (Firefox)<commit_after>/**
 * Copyright (C) 2012-2019 Mailvelope GmbH
 * Licensed under the GNU Affero General Public License version 3
 */

import React from 'react';
import {port, AppOptions} from '../app';
import * as l10n from '../../lib/l10n';
import Trans from '../../components/util/Trans';

l10n.register([
  'form_cancel',
  'form_save',
  'general_default_key_always',
  'general_default_key_auto_sign',
  'general_gnupg_check_availability',
  'general_gnupg_installed_question',
  'general_gnupg_not_available',
  'general_gnupg_prefer',
  'general_openpgp_current',
  'general_openpgp_prefer',
  'general_openpgp_preferences',
  'general_prefer_gnupg_note',
  'keygrid_default_key',
  'settings_general'
]);

export default class General extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      auto_add_primary: false,
      auto_sign_msg: false,
      prefer_gnupg: false,
      modified: false,
      nativeMessaging: true
    };
    this.handleCheck = this.handleCheck.bind(this);
    this.handleSave = this.handleSave.bind(this);
    this.handleCancel = this.handleCancel.bind(this);
  }

  componentDidMount() {
    this.loadPrefs();
    chrome.permissions && chrome.permissions.contains({permissions: ['nativeMessaging']}, nativeMessaging => this.setState({nativeMessaging}));
  }

  async loadPrefs() {
    const {general} = await port.send('get-prefs');
    this.setState({
      auto_add_primary: general.auto_add_primary,
      auto_sign_msg: general.auto_sign_msg,
      prefer_gnupg: general.prefer_gnupg,
      modified: false
    });
  }

  handleCheck({target}) {
    this.setState({[target.name]: target.checked, modified: true});
  }

  async handleSave() {
    const update = {
      general: {
        auto_add_primary: this.state.auto_add_primary,
        auto_sign_msg: this.state.auto_sign_msg,
        prefer_gnupg: this.state.prefer_gnupg
      }
    };
    await port.send('set-prefs', {prefs: update});
    this.setState({modified: false});
  }

  handleCancel() {
    this.loadPrefs();
{'fraction_non_alphanumeric': 0.12740384615384615, 'fraction_numerical': 0.007211538461538462, 'mean_word_length': 3.838372093023256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4010666', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1373, 'n_words': 245}