/**
 * Module for getting settings in Main process.
 */
import electronSettings from 'electron-settings';

const settingsService = {
    get(itemKey) {
        const settingValue = electronSettings.getSync(itemKey);
        return (typeof settingValue === 'undefined' || settingValue === null) ? false : settingValue;
    },

    set(itemKey, settingValue) {
        electronSettings.setSync(itemKey, settingValue);
        if (settingsService.webContents) {
            settingsService.webContents.send('settings', 'changed', itemKey, settingValue);
        }
    },

    has(itemKey) {
        return electronSettings.hasSync(itemKey);
    },

    unset(itemKey) {
        electronSettings.unsetSync(itemKey);
    },

    webContents: null
};

export default settingsService;
