Skip to content

Commit

Permalink
feature: Make userData dir name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pazdera committed Oct 18, 2019
1 parent 884879f commit d5323c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Classic style titlebar (Windows 10)

`Shell`: Use this class to create a new app with a browser window serving content from a local directory

options:
- `root`, (required) Root of the local directory you want to serve in the browser window.
options:
- `root`, _(required)_ Root of the local directory you want to serve in the browser window.
- `scheme`, Scheme that will be used in the server protocol (Default: `shell`)
- `width`, Width of the main window (Default: `800`).
- `height`, Height of the main window (Default: `600`).
Expand All @@ -44,6 +44,7 @@ options:
- `devMode`, Enables developer mode (DevTool options) (Default: `false`).
- `menuTransform`, Function that will receive the shell menu and should return a modified version of it to add custom menu and menu items.
- `windowOptions`, Any option that will be passed down to electron's `BrowserWindow` constructor.
- `userDataDirName`, _(optional)_ Change the name of the directory where user data will be stored. The location is platform-specific. Defaults to the app `name` as specified in `package.json`.

Methods:

Expand Down
1 change: 1 addition & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const shell = new Shell({
name: 'My App',
root: CONTENT_ROOT,
scheme: CONTENT_SCHEME,
userDataDirName: 'my-demo-app',
// Can provide custom width and height
width: 1440,
height: 900,
Expand Down
7 changes: 7 additions & 0 deletions lib/shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class Shell extends EventEmitter {
const customTitlebar = !(this.options.titlebar && (!this.options.uwpTitlebar || !Shell.isWin()));
this.options.server = this.options.server || {};
app.setName(this.options.name);

if (this.options.userDataDirName) {
const appDataPath = app.getPath('appData');
const userDataPath = path.join(appDataPath, this.options.userDataDirName);
app.setPath('userData', userDataPath);
}

this.log = Logger.getLogger(this.options.log || {});
protocol.registerStandardSchemes([this.options.scheme], { secure: true });
if (customTitlebar) {
Expand Down

0 comments on commit d5323c1

Please sign in to comment.