summaryrefslogtreecommitdiff
path: root/ui/app/app.js
blob: 9c6d54ee82ae027b432902498b3dfa10b14f82fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import bitmask from 'lib/bitmask'
import Account from 'models/account'
import Provider from 'models/provider'

require('css/bootstrap.less')
require('css/common.less')

class Application {
  constructor() {
  }

  //
  // main entry point for the application
  //
  initialize() {
    //window.addEventListener("error", this.showError.bind(this))
    //window.addEventListener("unhandledrejection", this.showError.bind(this))
    this.start()
  }

  //
  // (1) check to see if any accounts are authenticated.
  //     if any are, show main panel
  // (2) check to see if any accounts are 'vpn ready'.
  //     if any are, show main panel.
  // (3) otherwise, show login greeter
  //
  start() {
    Provider.list(false).then(
      domains => {
        Account.initializeList(domains)
        Account.active().then(
          accounts => {
            if (0 == accounts.length) {
              Account.vpnReady().then(accounts => {
                if (0 == accounts.length) {
                  this.show('greeter', {showLogin: true})
                } else {
                  this.show('main', {initialAccount: accounts[0]})
                }
              })
            } else {
              accounts.forEach(account => {
                Account.addActive(account)
              })
              this.show('main', {initialAccount: Account.list[0]})
            }
          },
          error => {this.showError(error)}
        )
      },
      error => {this.showError(error)}
    )
  }

  show(panel, properties) {
    this.switcher.show(panel, properties)
  }

  showError(e) {
    this.switcher.showError(e)
    return true
  }

  hideError() {
    this.switcher.hideError()
    return true
  }
}

var App = new Application
export default App