<commit_before>localStorage = require './local-storage'
{CompositeDisposable} = require 'atom'
Terminal = require './terminal'
TerminalView = require './views/terminal'
StatusView = require './views/status'
{EventEmitter} = require 'events'
Updater = require './updater'
bus = require('./event-bus')()
Notifier = require './notifier'
atomHelper = require './atom-helper'
config = require './config'
auth = require './auth'
remote = require 'remote'
BrowserWindow = remote.require('browser-window')

module.exports =
  token: require('./token')

  activate: (state) ->
    console.log 'Activating Commit Live IDE'
    @checkForV1WindowsInstall()
    @registerWindowsProtocol()
    # @disableFormerPackage()

    @subscriptions = new CompositeDisposable
    @subscribeToLogin()

    atom.project.commitLiveIde = activateIde: =>
      console.log('tree connected => activating Commit Live')
      # @activateIDE(state)

    @waitForAuth = auth().then =>
      console.log('successfully authenticated')
      @activateIDE(state)
    .catch =>
      console.error('Failed to authenticate')

  activateIDE: (state) ->
    @isTerminalWindow = (localStorage.get('popoutTerminal') == 'true')
    if @isTerminalWindow
      window.resizeTo(750, 500)
      localStorage.delete('popoutTerminal')

    @activateTerminal()
    @activateStatusView(state)
    @activateEventHandlers()
    @activateSubscriptions()
    @activateNotifier()
    # @activateUpdater()
    @termView.sendClear()

  activateTerminal: ->
    @term = new Terminal
      host: config.host
      port: config.port
      path: config.path
      token: @token.get()

    @termView = new TerminalView(@term, null, @isTerminalWindow)
    @termView.toggle()


  activateStatusView: (state) ->
    @statusView = new StatusView state, @term, {@isTerminalWindow}

    bus.on 'terminal:popin', () =>
      @statusView.onTerminalPopIn()
      @termView.showAndFocus()

    @statusView.on 'terminal:popout', =>
      @termView.toggle()

  activateEventHandlers: ->
    atomHelper.trackFocusedWindow()

    # listen for learn:open event from other render processes (url handler)
    bus.on 'learn:open', (lab) =>
      console.log "inside bus.on " , lab.slug
      @termView.openLab(lab.slug)
      atom.getCurrentWindow().focus()<commit_msg>checking open in app and clear priority<commit_after>localStorage = require './local-storage'
{CompositeDisposable} = require 'atom'
Terminal = require './terminal'
TerminalView = require './views/terminal'
StatusView = require './views/status'
{EventEmitter} = require 'events'
Updater = require './updater'
bus = require('./event-bus')()
Notifier = require './notifier'
atomHelper = require './atom-helper'
config = require './config'
auth = require './auth'
remote = require 'remote'
BrowserWindow = remote.require('browser-window')

module.exports =
  token: require('./token')

  activate: (state) ->
    console.log 'Activating Commit Live IDE'
    @checkForV1WindowsInstall()
    @registerWindowsProtocol()
    # @disableFormerPackage()

    @subscriptions = new CompositeDisposable
    @subscribeToLogin()

    atom.project.commitLiveIde = activateIde: =>
      console.log('tree connected => activating Commit Live')
      # @activateIDE(state)

    @waitForAuth = auth().then =>
      console.log('successfully authenticated')
      @activateIDE(state)
    .catch =>
      console.error('Failed to authenticate')

  activateIDE: (state) ->
    @isTerminalWindow = (localStorage.get('popoutTerminal') == 'true')
    if @isTerminalWindow
      window.resizeTo(750, 500)
      localStorage.delete('popoutTerminal')

    @activateTerminal()
    @activateStatusView(state)
    @activateEventHandlers()
    @activateSubscriptions()
    @activateNotifier()
    # @activateUpdater()
    # @termView.sendClear()

  activateTerminal: ->
    @term = new Terminal
      host: config.host
      port: config.port
      path: config.path
      token: @token.get()

    @termView = new TerminalView(@term, null, @isTerminalWindow)
    @termView.toggle()


  activateStatusView: (state) ->
    @statusView = new StatusView state, @term, {@isTerminalWindow}

    bus.on 'terminal:popin', () =>
      @statusView.onTerminalPopIn()
      @termView.showAndFocus()

    @statusView.on 'terminal:popout', =>
      @termView.toggle()

  activateEventHandlers: ->
    atomHelper.trackFocusedWindow()

    # listen for learn:open event from other render processes (url handler)
    bus.on 'learn:open', (lab) =>
      console.log "inside bus.on " , lab.slug
      @termView.openLab(lab.slug)
      atom.getCurrentWindow().focus()
{'fraction_non_alphanumeric': 0.13543478260869565, 'fraction_numerical': 0.003043478260869565, 'mean_word_length': 3.6663286004056794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6681347', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1343, 'n_words': 295}