Skip to content

Commit

Permalink
✨ Add support for electron-store's cwd option
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed May 27, 2021
1 parent 6933d57 commit d43f7f1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Here are all the options [vuex-electron-store](https://github.com/BetaHuhn/vuex-
| `reducer` | `function` | Will be called with the state and the paths as parameters to reduce the state to persist based on the given paths. Output will be persisted | Defaults to include the specified paths |
| `arrayMerger` | `function` | A function for merging arrays when rehydrating state. Will be passed as the [arrayMerge](https://github.com/TehShrike/deepmerge#arraymerge) argument to `deepmerge` | Defaults to combine the existing state with the persisted state |
| `encryptionKey` | `string/Buffer/TypedArray/DataView` | Will be used to encrypt the storage file. Only secure if you don't store the key in plain text ([more info](https://github.com/sindresorhus/electron-store#encryptionkey)) | n/a |
| `storageFileLocation` | `string` | Location where the storage file should be stored. If a relative path is provided, it will be relative to the default cwd. Don't specify this unless absolutely necessary ([more info](https://github.com/sindresorhus/electron-store#cwd)) | Defaults to optimal location based on system conventions |

See below for some [examples](#-examples).

Expand Down Expand Up @@ -244,7 +245,6 @@ export default new Vuex.Store({
## 📝 Todo

- [ ] Support [migrations](https://github.com/sindresorhus/electron-store#migrations)
- [ ] Support [changing the storage file location](https://github.com/sindresorhus/electron-store#cwd)
- [ ] Resetting the persisted state programmatically
- [ ] Create modified version for Vue 3

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PersistedState {
checkStorage: true
};
if (!opts.storage) {
defaultOptions.storage = new electron_store_1.default(Object.assign({ name: defaultOptions.fileName }, (opts.encryptionKey && { encryptionKey: opts.encryptionKey })));
defaultOptions.storage = new electron_store_1.default(Object.assign(Object.assign({ name: defaultOptions.fileName }, (opts.encryptionKey && { encryptionKey: opts.encryptionKey })), (opts.storageFileLocation && { cwd: opts.storageFileLocation })));
}
this.opts = Object.assign({}, defaultOptions, opts);
this.store = store;
Expand Down
2 changes: 2 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Options {
arrayMerger?: (target: any[], source: any[], options: any) => any;
overwrite?: boolean;
checkStorage?: boolean;
storageFileLocation?: string;
encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView;
storage?: Store;
}
Expand All @@ -22,6 +23,7 @@ export interface FinalOptions {
arrayMerger: (target: any[], source: any[], options: any) => any;
overwrite: boolean;
checkStorage: boolean;
storageFileLocation?: string;
encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView;
storage: Store;
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PersistedState {
if (!opts.storage) {
defaultOptions.storage = new Store({
name: defaultOptions.fileName,
...(opts.encryptionKey && { encryptionKey: opts.encryptionKey })
...(opts.encryptionKey && { encryptionKey: opts.encryptionKey }),
...(opts.storageFileLocation && { cwd: opts.storageFileLocation })
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Options {
arrayMerger?: (target: any[], source: any[], options: any) => any;
overwrite?: boolean;
checkStorage?: boolean;
storageFileLocation?: string;
encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView;
storage?: Store;
}
Expand All @@ -24,6 +25,7 @@ export interface FinalOptions {
arrayMerger: (target: any[], source: any[], options: any) => any;
overwrite: boolean;
checkStorage: boolean;
storageFileLocation?: string;
encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView;
storage: Store;
}

0 comments on commit d43f7f1

Please sign in to comment.