let { app } = require('electron').remote
let Config = require('electron-config')





new class {
  constructor () {
    this.config = new Config

    this.handleLaunchAtLoginChange = this.handleLaunchAtLoginChange.bind(this)
    this.handleTextInput = this.handleTextInput.bind(this)

    this.initialize()
  }

  handleLaunchAtLoginChange (event) {
    let input = event.target
    let prefName = input.getAttribute('name')

    this.config.set(prefName, input.checked)

    app.setLoginItemSettings({
      openAtLogin: input.checked
    })
  }

  handleTextInput (event) {
    let input = event.target
    let prefName = input.getAttribute('name')

    this.config.set(prefName, input.value)
  }

  initialize () {
    this.setupTextInputs()
    this.setupLaunchAtLoginInput()
  }

  setTextInputValue (textInput) {
    let prefName = textInput.getAttribute('name')
    let pref = this.config.get(prefName)

    textInput.value = pref || ''
  }

  setupLaunchAtLoginInput () {
    let input = document.querySelector('#launchAtLogin')
    let currentValue = this.config.get('launchAtLogin')

    input.checked = app.getLoginItemSettings().openAtLogin

    input.addEventListener('change', this.handleLaunchAtLoginChange)
  }

  setupTextInputs () {
    let textInputs = document.querySelectorAll('[type=number], [type=password], [type=text], [type=url]')

    for (let i = 0, length = textInputs.length; i < length; i++) {
      let textInput = textInputs[i]

      this.setTextInputValue(textInput)

      textInput.addEventListener('input', this.handleTextInput)
    }
  }
}

@@ -230,28 +230,24 @@
  this.handle
-Text
 Input = this
@@ -249,28 +249,24 @@
  this.handle
-Text
 Input.bind(t
@@ -538,28 +538,24 @@
  %7D%0A%0A  handle
-Text
 Input (event
@@ -624,32 +624,307 @@
 ttribute('name')
+%0A    let value%0A%0A    switch (input.getAttribute('type')) %7B%0A      case 'checkbox':%0A        value = input.checked%0A        break%0A%0A      case 'email':%0A      case 'number':%0A      case 'password':%0A      case 'url':%0A      case 'text':%0A      default:%0A        value = input.value%0A    %7D
 %0A%0A    this.confi
@@ -939,22 +939,16 @@
 efName, 
-input.
 value)%0A 
@@ -987,119 +987,599 @@
 etup
-Text
 Inputs(
-)%0A    this.setupLaunchAtLoginInput()%0A  %7D%0A%0A  setTextInputValue (textInput) %7B%0A    let prefName = textI
+%5B%0A      'host',%0A      'password',%0A      'path',%0A      'port',%0A      'url',%0A      'username',%0A    %5D)%0A%0A    this.setupLaunchAtLoginInput()%0A  %7D%0A%0A  linkInputToConfig (input) %7B%0A    let eventType%0A%0A    this.setInputValue(input)%0A%0A    switch (input.getAttribute('type')) %7B%0A      case 'checkbox':%0A        eventType = 'change'%0A        break%0A%0A      case 'email':%0A      case 'number':%0A      case 'password':%0A      case 'url':%0A      case 'text':%0A      default:%0A        eventType = 'input'%0A    %7D%0A%0A    input.addEventListener(eventType, this.handleInput)%0A  %7D%0A%0A  setInputValue (input) %7B%0A    let pref = i
 nput
@@ -1608,20 +1608,21 @@
     let 
-pref
+value
  = this.
@@ -1640,24 +1640,246 @@
 pref
-Name)%0A%0A    textI
+)%0A%0A    switch (input.getAttribute('type')) %7B%0A      case 'checkbox':%0A        input.checked = value%0A        break%0A%0A      case 'email':%0A      case 'number':%0A      case 'password':%0A      case 'url':%0A      case 'text':%0A      default:%0A        i
 nput
@@ -1891,19 +1891,26 @@
 e = 
-pref
+value
  %7C%7C ''%0A
+    %7D%0A
   %7D%0A
@@ -2200,20 +2200,16 @@
 etup
-Text
 Inputs (
 ) %7B%0A
@@ -2204,24 +2204,30 @@
 Inputs (
+inputs
 ) %7B%0A    
 let text
@@ -2222,314 +2222,123 @@
     
-let textInputs = document.querySelectorAll('%5Btype=number%5D, %5Btype=password%5D, %5Btype=text%5D, %5Btype=url%5D')%0A%0A    for (let i = 0, length = textInputs.length; i %3C length; i++) %7B%0A      let textInput = textInputs%5Bi%5D%0A%0A      this.setTextInputValue(textInput)%0A%0A      textInput.addEventListener('input', this.handleTextI
+inputs.forEach(inputID =%3E %7B%0A      let input = document.querySelector(%60#$%7BinputID%7D%60)%0A%0A      this.linkInputToConfig(i
 nput
@@ -2340,19 +2340,20 @@
 input)%0A    %7D
+)
 %0A  %7D%0A%7D%0A

Refactor preferences JS again