2

I'm developing an Electron app that is running an instance React VR. The app enables a user to add and save content to a react-vr project by reading and writing the state from/to a JSON file. During development, this JSON file has been stored in the root directory. However, if a user is to download and use the app on their computer, the JSON file needs to be moved outside the app package contents folder.

I have tried using app.getpath('userdata') which returns /Users/'username'/Library/Application Support/'app_name', and I can move the JSON state file there successfully upon running the app. However, I don't know how to have react-vr access this file, especially since there is no access to the computer's file system. However, all I really need is the user's system username to include in the 'userdata' file path.

What's the best way to go about retrieving the username from within react-vr? Would there be a better way to persist user data instead of a using a JSON file to keep track of the state? Would it be worth considering using AsyncStorage in conjunction with a database? Many thanks.

  • Why would you have to include the username into the userData file path? That doesn't make sense, because the username is already in it. If userA uses your app, then the userData will be in `/Users/userA/Library/Application Support/yourApp/` and for userB under `/Users/userB/Library/Application Support/yourApp/`. You also **can** access the file via the fs module (you have the path, you have a filename), because that's the nice thing about Electron: you can basically use nodejs modules in a browser. – RoyalBingBong Jun 22 '17 at 07:09
  • @RoyalBingBong Yes, I can get the correct path using electron with app.getPath,, but that method doesn't work in React VR, and React VR wont recognize the file path. I know it defaults to the user's application support folder, but the username part of the path will be different for every user who downloads and uses the app. So I could hard code the other directories in the path, but it doesn't really matter though, React VR still can't read system file paths ... – Aaron Goldsmith Jun 22 '17 at 16:32
  • You could try using [localStorage](https://developer.mozilla.org/en/docs/Web/API/Window/localStorage) to save your data. – RoyalBingBong Jun 22 '17 at 17:47
  • @RoyalBingBong thanks I've looked into that, but I'm looking for a more permanent data storage solution. – Aaron Goldsmith Jun 22 '17 at 17:56

0 Answers0