Skip to content

Commit

Permalink
fix: settings page working again
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Aug 24, 2018
1 parent baa4c77 commit 26eeff8
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions src/controls/main/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,65 @@ import {join} from 'path'
import {shell, ipcMain} from 'electron'
import { store } from '../../utils'

function openNodeConfig () {
return () => {
const path = store.get('ipfs').path
shell.openItem(join(path, 'config'))
const openNodeConfig = () => {
const path = store.get('ipfs').path
shell.openItem(join(path, 'config'))
}

const settingsToSend = {
direct: [
'autoLaunch',
'screenshotShortcut',
'downloadHashShortcut',
'lightTheme'
],
flags: {
dhtClient: '--routing=dhtclient'
}
}

function updateSettings () {
return (_, key, value) => {
store.set(key, value)
const sendSettings = ({ send }) => () => {
const options = {}

for (const opt of settingsToSend.direct) {
options[opt] = store.get(opt, false)
}

const flags = store.get('ipfs.flags')

for (const flag of Object.keys(settingsToSend.flags)) {
options[flag] = flags.includes(settingsToSend.flags[flag])
}

send('settings', options)
}

export default function (opts) {
const { send } = opts
const updateSettings = (opts) => (_, key, value) => {
if (settingsToSend.direct.includes(key)) {
store.set(key, value)
return sendSettings(opts)()
}

const flags = store.get('ipfs.flags')
const flag = settingsToSend.flags[key]
const index = flags.indexOf(flag)

const handler = () => {
send('settings', store.store)
if (value) {
if (index === -1) {
flags.push(flag)
}
} else {
if (index !== -1) {
flags.splice(index, 1)
}
}

ipcMain.on('request-settings', handler)
// TODO: settingsStore.on('change', handler) ?
store.set('ipfs.flags', flags)
sendSettings(opts)()
}

export default function (opts) {
ipcMain.on('request-settings', sendSettings(opts))
ipcMain.on('update-setting', updateSettings(opts))
ipcMain.on('open-node-settings', openNodeConfig(opts))
ipcMain.on('open-node-settings', openNodeConfig)
}

0 comments on commit 26eeff8

Please sign in to comment.