import {merge, pick} from 'lodash'

const kStorageKey = 'wukong'

export function open(state = {}) {
  try {
    return merge({
      user: {
        preferences: {
          listenOnly: false,
          connection: 0,
          audioQuality: 2,
          theme: 0
        }
      }
    }, JSON.parse(localStorage.getItem(kStorageKey)), state)
  } catch (error) {
    return state
  }
}

export function save(state = {}) {
  try {
    localStorage.setItem(kStorageKey, JSON.stringify(pick(state, [
      'user.preferences',
      'song.playlist',
      'player.volume'
    ])))
  } catch (error) {
    localStorage.removeItem(kStorageKey)
  }
}

import {merge, pick} from 'lodash'

const kStorageKey = 'wukong'

export function open(state = {}) {
  try {
    return merge({
      user: {
        preferences: {
          listenOnly: false,
          connection: 0,
          audioQuality: 0,
          theme: 0
        }
      }
    }, JSON.parse(localStorage.getItem(kStorageKey)), state)
  } catch (error) {
    return state
  }
}

export function save(state = {}) {
  try {
    localStorage.setItem(kStorageKey, JSON.stringify(pick(state, [
      'user.preferences',
      'song.playlist',
      'player.volume'
    ])))
  } catch (error) {
    localStorage.removeItem(kStorageKey)
  }
}

Revert "Set audio quality default value"
Revert "Set audio quality default value"

This reverts commit e4adca4840dc444259d50c1395f6fe5e3c0dbacb.
