<commit_before>'use strict'

const React = require('react')
const flux = {
  mailbox: require('../stores/mailbox'),
  google: require('../stores/google'),
  settings: require('../stores/settings')
}
const AppContent = require('./AppContent')
const path = window.nativeRequire('path')
const ipc = window.nativeRequire('electron').ipcRenderer
const remote = window.nativeRequire('remote')
const app = remote.require('app')
const Tray = remote.require('tray')
const Menu = remote.require('menu')
const mailboxDispatch = require('./Dispatch/mailboxDispatch')
const TimerMixin = require('react-timer-mixin')
const constants = require('shared/constants')

const injectTapEventPlugin = require('react-tap-event-plugin')
injectTapEventPlugin()

module.exports = React.createClass({
  displayName: 'App',
  mixins: [TimerMixin],

  /* **************************************************************************/
  // Lifecycle
  /* **************************************************************************/

  componentDidMount: function () {
    this.forceFocusTO = null

    flux.mailbox.S.listen(this.mailboxesChanged)
    flux.settings.S.listen(this.settingsChanged)
    flux.google.A.startPollSync()
    flux.google.A.syncAllProfiles()
    flux.google.A.syncAllUnreadCounts()

    mailboxDispatch.on('blurred', this.mailboxBlurred)

    ipc.on('switch-mailbox', this.ipcChangeActiveMailbox)
    ipc.on('auth-google-complete', this.ipcAuthMailboxSuccess)
    ipc.on('auth-google-error', this.ipcAuthMailboxFailure)
    ipc.on('mailbox-zoom-in', this.ipcZoomIn)
    ipc.on('mailbox-zoom-out', this.ipcZoomOut)
    ipc.on('mailbox-zoom-reset', this.ipcZoomReset)
  },

  componentWillUnmount: function () {
    flux.mailbox.S.unlisten(this.mailboxesChanged)
    flux.settings.S.unlisten(this.settingsChanged)
    flux.google.A.stopPollSync()

    ipc.off('switch-mailbox', this.ipcChangeActiveMailbox)
    ipc.off('auth-google-complete', this.ipcAuthMailboxSuccess)
    ipc.off('auth-google-error', this.ipcAuthMailboxFailure)
    ipc.off('mailbox-zoom-in', this.ipcZoomIn)
    ipc.off('mailbox-zoom-out', this.ipcZoomOut)
    ipc.off('mailbox-zoom-reset', this.ipcZoomReset)

    mailboxDispatch.off('blurred', this.mailboxBlurred)
  },

  /* **************************************************************************/
  // Data lifecycle
  /* **************************************************************************/

  getInitialState: function () {
    return { mailbox_ids: flux.mailbox.S.getState().ids() }
  },

  mailboxesChanged: function (store) {
    this.setState({ mailbox_ids: store.ids() })
    this.updateAppBadge(store)
    this.pushDataToMainThread(store)
  },

  settingsChanged: function (store) {
    this.updateAppBadge(undefined, store)
    this.pushDataToMainThread()
  },

  shouldComponentUpdate: function (nextProps, nextState) {
    // Nothing to ever update here. We're basically using this element as an event manager
    return false
  },

  /* **************************************************************************/
  // App
  /* **************************************************************************/

  /**
  * Updates the app badge
  * @param mailboxStore=mailbox store: the mailbox store to use
  * @param settingsStore=settings store: the settings store to use
  */
  updateAppBadge: function (mailboxStore = flux.mailbox.S.getState(), settingsStore = flux.settings.S.getState()) {
    const unread = mailboxStore.totalUnreadCount()
    if (process.platform === 'darwin') {
      if (settingsStore.showAppBadge()) {
        app.dock.setBadge(unread ? unread.toString() : '')
      } else {
        app.dock.setBadge('')
      }
    } else {
      if (!this.appTray) {
        const currentPath = decodeURIComponent(window.location.href.replace('file://', ''))
        const iconPath = path.join(path.dirname(currentPath), 'icons/app.png')
        this.appTray = new Tray(iconPath)
      }
<commit_msg>show tray icon according to setting<commit_after>'use strict'

const React = require('react')
const flux = {
  mailbox: require('../stores/mailbox'),
  google: require('../stores/google'),
  settings: require('../stores/settings')
}
const AppContent = require('./AppContent')
const path = window.nativeRequire('path')
const ipc = window.nativeRequire('electron').ipcRenderer
const remote = window.nativeRequire('remote')
const app = remote.require('app')
const Tray = remote.require('tray')
const Menu = remote.require('menu')
const mailboxDispatch = require('./Dispatch/mailboxDispatch')
const TimerMixin = require('react-timer-mixin')
const constants = require('shared/constants')

const injectTapEventPlugin = require('react-tap-event-plugin')
injectTapEventPlugin()

module.exports = React.createClass({
  displayName: 'App',
  mixins: [TimerMixin],

  /* **************************************************************************/
  // Lifecycle
  /* **************************************************************************/

  componentDidMount: function () {
    this.forceFocusTO = null

    flux.mailbox.S.listen(this.mailboxesChanged)
    flux.settings.S.listen(this.settingsChanged)
    flux.google.A.startPollSync()
    flux.google.A.syncAllProfiles()
    flux.google.A.syncAllUnreadCounts()

    mailboxDispatch.on('blurred', this.mailboxBlurred)

    ipc.on('switch-mailbox', this.ipcChangeActiveMailbox)
    ipc.on('auth-google-complete', this.ipcAuthMailboxSuccess)
    ipc.on('auth-google-error', this.ipcAuthMailboxFailure)
    ipc.on('mailbox-zoom-in', this.ipcZoomIn)
    ipc.on('mailbox-zoom-out', this.ipcZoomOut)
    ipc.on('mailbox-zoom-reset', this.ipcZoomReset)
  },

  componentWillUnmount: function () {
    flux.mailbox.S.unlisten(this.mailboxesChanged)
    flux.settings.S.unlisten(this.settingsChanged)
    flux.google.A.stopPollSync()

    ipc.off('switch-mailbox', this.ipcChangeActiveMailbox)
    ipc.off('auth-google-complete', this.ipcAuthMailboxSuccess)
    ipc.off('auth-google-error', this.ipcAuthMailboxFailure)
    ipc.off('mailbox-zoom-in', this.ipcZoomIn)
    ipc.off('mailbox-zoom-out', this.ipcZoomOut)
    ipc.off('mailbox-zoom-reset', this.ipcZoomReset)

    mailboxDispatch.off('blurred', this.mailboxBlurred)
  },

  /* **************************************************************************/
  // Data lifecycle
  /* **************************************************************************/

  getInitialState: function () {
    return { mailbox_ids: flux.mailbox.S.getState().ids() }
  },

  mailboxesChanged: function (store) {
    this.setState({ mailbox_ids: store.ids() })
    this.updateAppBadge(store)
    this.pushDataToMainThread(store)
  },

  settingsChanged: function (store) {
    this.updateAppBadge(undefined, store)
    this.pushDataToMainThread()
  },

  shouldComponentUpdate: function (nextProps, nextState) {
    // Nothing to ever update here. We're basically using this element as an event manager
    return false
  },

  /* **************************************************************************/
  // App
  /* **************************************************************************/

  /**
  * Updates the app badge
  * @param mailboxStore=mailbox store: the mailbox store to use
  * @param settingsStore=settings store: the settings store to use
  */
  updateAppBadge: function (mailboxStore = flux.mailbox.S.getState(), settingsStore = flux.settings.S.getState()) {
    const unread = mailboxStore.totalUnreadCount()
    if (process.platform === 'darwin') {
      if (settingsStore.showAppBadge()) {
        app.dock.setBadge(unread ? unread.toString() : '')
      } else {
        app.dock.setBadge('')
      }
    }

    if (settingsStore.showTrayIcon()) {
      if (!this.appTray) {
        const currentPath = decodeURIComponent(window.location.href.replace('file://', ''))
        const iconPath = path.join(path.dirname(currentPath), 'icons/app.png')
        this.appTray = new Tray(iconPath)
      }

{'fraction_non_alphanumeric': 0.23948097757621567, 'fraction_numerical': 0.0, 'mean_word_length': 4.441398217957505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4473600', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2328, 'n_words': 384}