Reputation: 3878
I want to set the --user-data-dir of my electron app to a custom directory, in my case, I would like it to default to a folder in the public directory so any users running the app will share the same asset directory.
It doesn't seem like Electron's appendSwitch() function supports this (and didn't work when I tried), so i'm kind of lost on how to implement this switch.
Upvotes: 8
Views: 15462
Reputation:
In an application built with Electron, you usually get the default user data directory dynamically by using app.getPath(name) from the main process:
const { app } = require ('electron');
const userDataPath = app.getPath ('userData');
It is also possible to set the path to a custom directory by using app.setPath(name, path):
app.setPath ('userData', "path/to/new/directory");
Overrides the path to a special directory or file associated with name. If the path specifies a directory that does not exist, the directory will be created by this method. On failure an Error is thrown.
You can only override paths of a name defined in app.getPath.
By default, web pages' cookies and caches will be stored under the userData directory. If you want to change this location, you have to override the userData path before the ready event of the app module is emitted.
Upvotes: 19