From d5323c1643556969a19afbedd00be44070feb91b Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Fri, 18 Oct 2019 17:20:24 +0100 Subject: [PATCH] feature: Make userData dir name configurable --- README.md | 5 +++-- app/main.js | 1 + lib/shell/index.js | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c281bd0..8aa1d13 100644 --- a/README.md +++ b/README.md @@ -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`). @@ -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: diff --git a/app/main.js b/app/main.js index c698f41..fe0fd10 100644 --- a/app/main.js +++ b/app/main.js @@ -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, diff --git a/lib/shell/index.js b/lib/shell/index.js index 6ec6a1c..cf63563 100644 --- a/lib/shell/index.js +++ b/lib/shell/index.js @@ -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) {