I've created an Electron app and build packages for Windows and MacOS using electron-packager. The app data is stored in a JSON file inside the resources folder and i'm using fs to perform file I/O tasks in the app.
What i would like to do is store the JSON file in a folder that could be accessed by both packages (Win and Mac). This way my client could use both versions of the app and the data source will be the same, thus, the data always updated.
Since i'm a Electron newbie, is there a way to "merge" both packages and share the same data file?
Thanks to #kevingelion and #revln9 from the Slack Electron discussion, i was able to solve my issue.
All i need to use is getAppPath() and from there go to the parent folder where the data file is located:
var app = require('electron').remote.app;
resourcePath = path.join(app.getAppPath(), '../../../db/'); //shared folder
Related
I create one software in electron. I need to add image upload functionality into it. Uploaded images will store in a local drive(D:// Drive) folder and also on preview time I need to access the same folder so I have not idea it is possible in electron and if yes then how can I do this?
And for an extra thing in the backend, I use nodejs if you have an idea about that thing is possible using node js then also tell me so I can integrate with node js also. just I need to store that images to a particular folder which is in my local drive and I also access that image from my local drive for preview things.
For selecting file to upload trigger event (ex. upload-start) through ipc from render process.
In main process in handler for this event use dialog module and .showOpenDialog() method which will return a path to the file.
Then in main process you can use fs module to work with file: read it, copy, move, rename and write.
And check How do I handle local file uploads in electron?
Right now I store my files right inside installed app directory and on macOS after deleting an application all saved files are gone too because they were right inside .app directory.
Where should I store files so they will not be deleted after deleting an application? Both on Windows and macOS.
For example, electron-store on macOS stores all data here: ~/Library/Application Support/App Name/ but I don't know where exactly it stores it on Windows.
More context:
I have an Electron app that stores images that user saves and show it inside the app. But the user shouldn't have an easy access to these images using any file provider because these images are the part of the database and I store paths and information about them. Hope it helps :)
Typically data is stored in the user’s “app data” folder where this directory is varies by operating system.
Mac OS: ~/Library/Application Support/{Your App Name (taken from the name property in package.json)}
Windows: C:\Users\\AppData\Local{Your App Name}
Linux: ~/.config/{Your App Name}
Electron provides app.getPath which returns the right directory, depending on your platform.
check this link for more info electron-store-data
I'm using node fs to create a directory and then watch it in my electron app. Users can then use that directory to upload documents. I use chokidar to watch the directory for documents. This all works locally; fs creates the directory inside my app folder. I can drag and drop files in, everything works.
This doesn't work, however, when I deploy the app to windows. I've searched the filesystem and cannot find where this folder was created.
What I'd like to do is create the folder on their Desktop. It would be even cooler if I could react to movements of the folder (e.g. the user moves it to Documents).
Is there a way to
Create the folder on their desktop (both osx and windows)
Listen for when the folder has been moved to another location.
Thanks!
Update
Found a way to find their desktop directory
const dir = Path.join(require('os').homedir(), 'Desktop/whatever');
Is there a way to do number 2?
Is there any specific folder where I can store my files so that the app can use it later after building? Like Meteor has a private folder, is there any folder for node webkit?
As far as I know there is no predefined path and it is not needed. You can access any file with relative path from current dir. Just do not forget to add it into final build.
We're building a node-webkit/NW.js application for OS X and want to create a updater for the application so that it will be kept up-to-date automatically.
Because we deploy the nodeJS, css and html in a App.nw package. It's quite easy to download a new package and just replace the old one and restart the application. After searching somewhat on Google we couldn't find any way of getting the location of the App.nw package on OS X.
We deploy a node-webkit redist on OS X but we use our own CEF client for Windows. On Windows it's quite simple, you just get the NW.exe path and work your way to the App.nw from there. Is there some way of doing that on OS X?
Also it might be good to state that we're working on an older version of node-webkit, version 0.8.6. This is because a lot of native modules don't work on 0.9+ of node-webkit because they need NodeJS 0.10.
While you are running your app your can do:
var path = window.location.pathname;
path = path.substr(0, path.lastIndexOf('/'));
That will give your the full path to the app.nw.
The answer is different depending upon whether you are working in a Terminal (command line) window or from Finder.
In OS X, the nw application is called nwjs. You can look around inside the application bundle by right clicking on the application and selecting the Show Package Contents menu item. Navigate to Contents -> Resources and you will see your App.nw file or directory there.
From the command line, go to the directory containing the nwjs app. It should have the name, nwjs.app. From that directory the file (or directory) that you want is nwjs.app/Contents/Resources/App.nw
When customizing your packaged application it is perfectly ok to rename nwjs.app to your_app_name.app. So the name of the app might be something different from nwjs.app.