import React, { Component, PropTypes } from 'react';
import Immutable from 'immutable';
import Router from 'react-router/BrowserRouter';
import connectToStores from 'alt-utils/lib/connectToStores';

import AppUIActions from 'actions/AppUIActions';
import AppUIStore from 'stores/AppUIStore';
import MetadataStore from 'stores/MetadataStore';

import secretin from 'utils/secretin';

import UserConnect from 'components/users/UserConnect';
import Layout from 'components/Layout';

class App extends Component {

  static propTypes = {
    savedUsername: PropTypes.string,
    loading: PropTypes.bool,
    connected: PropTypes.bool,
    errors: PropTypes.instanceOf(Immutable.Map),
  }

  static getStores() {
    return [
      AppUIStore,
      MetadataStore,
    ];
  }

  static getPropsFromStores() {
    const state = AppUIStore.getState();
    return {
      savedUsername: state.get('savedUsername'),
      loading: state.get('loading'),
      connected: state.get('connected'),
      errors: state.get('errors'),
      secrets: MetadataStore.getSecretsInFolder(),
    };
  }

  constructor(props) {
    super(props);
    this.disconnectingEvent = null;

    this.cameBack = this.cameBack.bind(this);
    this.left = this.left.bind(this);

    window.addEventListener('focus', this.cameBack);
    window.addEventListener('blur', this.left);
  }

  cameBack() {
    clearTimeout(this.disconnectingEvent);
  }

  left() {
    clearTimeout(this.disconnectingEvent);
    if (secretin.currentUser.options) {
      const delay = secretin.currentUser.options.timeToClose * 60 * 1000;
      if (delay > 0) {
        this.disconnectingEvent = setTimeout(AppUIActions.disconnectUser, delay);
      }
    }
  }


  render() {
    return (
      <Router basename={process.env.PUBLIC_URL}>
        <div className="App">
          {
            this.props.connected ? (
              <Layout />
            ) : (
              <UserConnect
                savedUsername={this.props.savedUsername}
                loading={this.props.loading}
                errors={this.props.errors}
              />
            )
          }
        </div>
      </Router>
    );
  }
}

export default connectToStores(App);

@@ -292,16 +292,64 @@
 %0Aimport 
+OptionsStore from 'stores/OptionsStore';%0Aimport 
 Metadata
@@ -384,48 +384,8 @@
 tore
-';%0A%0Aimport secretin from 'utils/secretin
 ';%0A%0A
@@ -628,24 +628,74 @@
 Types.bool,%0A
+    options: PropTypes.instanceOf(Immutable.Map),%0A
     errors: 
@@ -786,24 +786,44 @@
 AppUIStore,%0A
+      OptionsStore,%0A
       Metada
@@ -929,16 +929,58 @@
 eturn %7B%0A
+      options: OptionsStore.getOptions(),%0A
       sa
@@ -1287,70 +1287,84 @@
 his.
-cameBack = this.cameBack.bind(this);%0A    this.left = this.left
+onAppFocus = this.onAppFocus.bind(this);%0A    this.onAppBlur = this.onAppBlur
 .bin
@@ -1415,24 +1415,26 @@
 ', this.
-cameBack
+onAppFocus
 );%0A    w
@@ -1469,20 +1469,25 @@
 ', this.
-left
+onAppBlur
 );%0A  %7D%0A%0A
@@ -1492,16 +1492,18 @@
 %0A%0A  
-cameBack
+onAppFocus
 () %7B
@@ -1557,12 +1557,17 @@
 %0A%0A  
-left
+onAppBlur
 () %7B
@@ -1618,36 +1618,26 @@
     if (
-secretin.currentUser
+this.props
 .options
@@ -1664,28 +1664,18 @@
 y = 
-secretin.currentUser
+this.props
 .opt
@@ -1679,16 +1679,21 @@
 options.
+get('
 timeToCl
@@ -1695,16 +1695,18 @@
 eToClose
+')
  * 60 * 

Use OptionsStore instead of secretin