Coder Social home page Coder Social logo

electron-json-config's People

Contributors

bgrayburn avatar de-luca avatar dependabot-preview[bot] avatar dependabot[bot] avatar kelfish avatar megahertz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

electron-json-config's Issues

cannot find module ...config.json

after using with webpack/babel to build I'm getting the following error when running an electron app with this lib:

App threw an error when running [Error: Cannot find module '/Users/bgrayburn/Library/Application Support/NewSapienceModelEditor/config.json'.]

my understanding is this is coming from the require(file) line in the index.js of electron-json-config because such a config file module isn't loaded by webpack. I don't want to load the config file with webpack, but I do want to be able to use this lib with webpack.

My suggestion would be to use fs.readSync instead of require in the lib. How does this sound?

Module doesn't work with electron 17.2.0

Err message: Uncaught TypeError: Cannot read properties of undefined (reading 'getPath')
at Object. (/Users/aleksandrpeskov/WebstormProjects/divo-electron/node_modules/electron-json-config/lib/factory.js:9:53)
I fixed it with change const electron_1 = require("electron"); to const electron_1 = require("@electron/remote");
in node_modules in factory.js.
Thank you in advance!

cannot read property 'app' of undefined

in src/index line 19, the second half of the or conditional reads electron.remote.app && electron.remote.app.isReady()) this throws an error on the node js end of things when the app isn't ready because electron.remote is undefined. Solution is to change to electron.remote && electron.remote.app && electron.remote.app.isReady()). Shall I submit a pull request for this?

Setting key within object.

How would one go about setting a value within an object? Would we need to recreate the whole object and then just set that as a key? I have an object within my config called "network" that looks like this:

{
    'apikey' : '0000-1111-3333-4444',
    'network' : {
           'mac_address' : '00:11:22:33:44:55',
           'ip_address' : '192.168.1.50'
    },
    'username' : 'user123'
}

I cannot set it like this : config.set('network.ip_address', '192.168.1.55');

but I can do this :

var networktemp = config.get('network');
networktemp.ip_address = '192.168.1.50';
config.set('network' networktemp);

I guess I just answered my own question. I really appreciate this module! It definitely abstracts aways the sometimes convoluted work of dealing with json files using node's (fs) function.

Error trying to read config.json after clean install

Expected behavior:
After a clean install, the config file is created/loaded after the userData directory is created by electron

Actual behavior:
After a clean install, the module tries to create the config.json file before electron gets a chance to create the userData directory, throwing an error, crashing the app.
Subsequent app starts work fine since then the userData directory already exist (electron manages to create it after the first exception, maybe a race condition)

Workaround
Require electron-json-config on electron's ready callback

electron-json-config 1.5.0
electron 1.6.7
Windows 10

can there be a bulk version of set?

I have a setting of about 20 items,
when user commit the setting form, I have to set data item by item,
and this will result in writing the file 20 times, which is unnecessary.

so if there is another set function like setBulk which accept an object and iterate over it, set entries and then write result to file,
or give a option to original set, which can prevent writing file to disk, and expose sync function for writing file,
will somehow solve this problem

and delete may have the same behavior

Read Config File Initialization

Currently, the config file is loaded after receiving the electron 'ready' signal. If Electron was already loaded, you will never receive that signal, so the config file will not be read.

I couldnt figure out how to run or pass the integration tests you have, so I'll just paste my diff here. It is simple enough:

--- a/src/index.js
+++ b/src/index.js
@@ -7,14 +7,21 @@ const file = (electron.app || electron.remote.app).getPath('userData')+'/config.
 
 let config = {};
 
-
-(electron.app || electron.remote.app).on('ready', () => {
+let readConfig = () => {
   if(!u.exists(file)) {
     fs.writeFileSync(file, '{}');
   }
-
   config = JSON.parse(fs.readFileSync(file));
-});
+}; 
+
+if (electron.remote.app && electron.remote.app.isReady()) {
+  readConfig();
+}
+else {
+  (electron.app || electron.remote.app).on('ready', () => {
+    readConfig();
+  });
+}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.