How to use the electron-json-storage.setDataPath function in electron-json-storage

To help you get started, we’ve selected a few electron-json-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yafp / ttth / app / js / ttth / ttth.js View on Github external
function readLocalUserSetting (key, optional = false) {
    const storage = require('electron-json-storage')
    const remote = require('electron').remote
    const app = remote.app
    const path = require('path')

    writeLog('info', 'readLocalUserSetting ::: Trying to read value of key: ' + key)

    const defaultDataPath = storage.getDefaultDataPath() // get default storage path
    const userSettingsPath = path.join(app.getPath('userData'), 'ttthUserSettings') // change path for userSettings
    storage.setDataPath(userSettingsPath)

    // read the json file
    storage.get(key, function (error, data) {
        if (error) {
            writeLog('error', 'readLocalUserSetting ::: Got error while reading a json file with the name: _' + key + '_. Error: ' + error)
            throw error
        }

        var value = data.setting // store the read value in a variable

        writeLog('info', 'readLocalUserSetting ::: key: _' + key + '_ - got value: _' + value + '_')
        storage.setDataPath(defaultDataPath) // revert storage path

        // setting DefaultView
        if (key === 'settingDefaultView') {
            // no default view configured
github yafp / ttth / app / js / ttth / ttth.js View on Github external
function writeLocalUserSetting (key, value) {
    const storage = require('electron-json-storage')
    const remote = require('electron').remote
    const app = remote.app
    const path = require('path')

    const defaultDataPath = storage.getDefaultDataPath() // get default storage path
    const userSettingsPath = path.join(app.getPath('userData'), 'ttthUserSettings') // set new path for userUsettings
    storage.setDataPath(userSettingsPath)

    // write the user setting
    storage.set(key, { setting: value }, function (error) {
        if (error) {
            writeLog('error', 'writeLocalUserSetting ::: Got an error while trying to write a user setting with key: _' + key + '_ and value: _' + value + '_. Error: ' + error)
            throw error
        }
        writeLog('info', 'writeLocalUserSetting ::: key: _' + key + '_ - new value: _' + value + '_')
        storage.setDataPath(defaultDataPath) // revert to default path
    })
}
github yafp / ttth / app / js / ttth / ttth.js View on Github external
storage.get(key, function (error, data) {
        if (error) {
            writeLog('error', 'readLocalUserSetting ::: Got error while reading a json file with the name: _' + key + '_. Error: ' + error)
            throw error
        }

        var value = data.setting // store the read value in a variable

        writeLog('info', 'readLocalUserSetting ::: key: _' + key + '_ - got value: _' + value + '_')
        storage.setDataPath(defaultDataPath) // revert storage path

        // setting DefaultView
        if (key === 'settingDefaultView') {
            // no default view configured
            if (value === null) {
                writeLog('info', 'validateConfiguredDefaultView ::: No default configured - Stay on settings-view')
            } else {
                writeLog('info', 'validateConfiguredDefaultView ::: Found configured default view: ' + value)

                // check if the configured service is enabled or not
                var exists = false
                writeLog('info', 'validateConfiguredDefaultView ::: Check if configured default view is an enabled service or not')
                // Check if Dropdown contains the defined default view as enabled service
                $('#selectDefaultView option').each(function () {
                    if (this.value === value) {
                        exists = true
github yafp / ttth / app / js / ttth / ttth.js View on Github external
function loadConfiguredUserServices () {
    const storage = require('electron-json-storage')
    const remote = require('electron').remote
    const app = remote.app
    const path = require('path')

    $('#settingsServicesConfigured').empty() // empty the div

    // ensure we are reading from the correct location
    const defaultUserDataPath = app.getPath('userData')
    var customUserDataPath = path.join(defaultUserDataPath, 'storage')
    storage.setDataPath(customUserDataPath)

    // read all user service configuration files
    storage.getAll(function (error, data) {
        if (error) {
            // FIXME
            throw error
        }

        // show object which contains all config files
        // writeLog("error", (data);
        // writeLog("error", (typeof data);

        var serviceCount = 0

        writeLog('info', 'loadConfiguredUserServices ::: Found the following user configs: _' + data + '_.')
github soroushchehresa / unsplash-wallpapers / app / index.js View on Github external
// @flow

import React from 'react';
import { render } from 'react-dom';
import storage from 'electron-json-storage';
import os from 'os';
import updateHandler from 'app/utils/updateHandler';
import Root from './containers/Root';
import { configureStore, history } from './redux/store/configureStore';

updateHandler();
storage.setDataPath(os.tmpdir());
configureStore()
  .then((store) => {
    render(
      ,
      document.getElementById('root'),
    );
    if (module.hot) {
      module.hot.accept('./containers/Root', () => {
        // eslint-disable-next-line global-require
        const NextRoot = require('./containers/Root').default;
        render(
          ,
          document.getElementById('root'),
        );
      });
    }
github pumPCin / GiveawayJoiner / giveawayjoiner.js View on Github external
app.commandLine.appendSwitch('disk-cache-size', 100);
app.disableHardwareAcceleration();
if (process.platform === 'win32') {
_itr = __dirname + '/icons/icon.ico';
udata = (udata.slice(0, -4)).toLowerCase();
}
if (process.platform === 'darwin') {
app.dock.hide();
_bmd = 'false';
_bfr = 'true';
_itr = __dirname + '/icons/trayTemplate.png';
udata = (udata.slice(0, -34)).toLowerCase();
}
_icn = _itr;
app.setPath('userData', udata + 'data');
storage.setDataPath(udata + 'data');
if (fs.existsSync(storage.getDataPath() + '/user-agent.txt')) {
let content = fs.readFileSync(storage.getDataPath() + '/user-agent.txt');
if (content.length > 0) {
_ua = content.toString();
}
}
else {
fs.writeFile(storage.getDataPath() + '/user-agent.txt', _ua, (err) => { });
}
if (!fs.existsSync(storage.getDataPath() + '/blacklist.txt')) {
fs.writeFile(storage.getDataPath() + '/blacklist.txt', 'app/0,sub/0,', (err) => { });
}
ipcMain.on('save-user', function (event, data) {
user = data;
global.user = data;
});