/* @flow */

import { CompositeDisposable, Disposable } from 'atom'

import Linter from './main'
import type { UI, Linter as LinterProvider } from './types'

// Internal variables
let instance

const idleCallbacks = new Set()

export default {
  activate() {
    this.subscriptions = new CompositeDisposable()

    instance = new Linter()
    this.subscriptions.add(instance)

    const linterDepsCallback = window.requestIdleCallback(function linterDepsInstall() {
      idleCallbacks.delete(linterDepsCallback)
      if (!atom.inSpecMode()) {
        // eslint-disable-next-line global-require
        require('atom-package-deps').install('linter', true)
      }
    })
    idleCallbacks.add(linterDepsCallback)
  },
  consumeLinter(linter: LinterProvider): Disposable {
    const linters = [].concat(linter)
    for (const entry of linters) {
      instance.addLinter(entry)
    }
    return new Disposable(() => {
      for (const entry of linters) {
        instance.deleteLinter(entry)
      }
    })
  },
  consumeUI(ui: UI): Disposable {
    const uis = [].concat(ui)
    for (const entry of uis) {
      instance.addUI(entry)
    }
    return new Disposable(() => {
      for (const entry of uis) {
        instance.deleteUI(entry)
      }
    })
  },
  provideIndie(): Object {
    return indie => instance.addIndie(indie)
  },
  deactivate() {
    idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID))
    idleCallbacks.clear()
    this.subscriptions.dispose()
  },
}

@@ -191,41 +191,8 @@
 ce%0A%0A
-const idleCallbacks = new Set()%0A%0A
 expo
@@ -345,223 +345,130 @@
     
-const linterDepsCallback = window.requestIdleCallback(function linterDepsInstall() %7B%0A      idleCallbacks.delete(linterDepsCallback)%0A      if (!atom.inSpecMode()) %7B%0A        // eslint-disable-next-line global-require%0A
+this.subscriptions.add(%0A      atom.packages.onDidActivateInitialPackages(function() %7B%0A        if (!atom.inSpecMode()) %7B%0A  
     
@@ -534,57 +534,26 @@
     
+  
 %7D%0A    
+ 
+ 
 %7D)
+,
 %0A    
-idleCallbacks.add(linterDepsCallback
 )%0A  
@@ -1195,113 +1195,8 @@
 ) %7B%0A
-    idleCallbacks.forEach(callbackID =%3E window.cancelIdleCallback(callbackID))%0A    idleCallbacks.clear()%0A
     

Install pacakge-deps on initial activate of packages