Skip to content

Commit

Permalink
Allow awaiting .openInEditor() (#272)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
kiavashp and sindresorhus committed Mar 8, 2024
1 parent d120209 commit c0bcdb7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ declare class ElectronStore<T extends Record<string, any> = Record<string, unkno

/**
Open the storage file in the user's editor.
Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.
*/
openInEditor(): void;
openInEditor(): Promise<void>;
}

export = ElectronStore;
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ class ElectronStore extends Conf {
initDataListener();
}

openInEditor() {
shell.openPath(this.path);
async openInEditor() {
const error = await shell.openPath(this.path);

if (error) {
throw new Error(error);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ store.reset('foo');
store.has('foo');
store.clear();

store.openInEditor();
await store.openInEditor();

store.size; // eslint-disable-line @typescript-eslint/no-unused-expressions
store.store; // eslint-disable-line @typescript-eslint/no-unused-expressions
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Get the path to the storage file.

Open the storage file in the user's editor.

Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.

### initRenderer()

Initializer to set up the required `ipc` communication channels for the module when a `Store` instance is not created in the main process and you are creating a `Store` instance in the Electron renderer process only.
Expand Down

0 comments on commit c0bcdb7

Please sign in to comment.