Skip to content

Commit c0bcdb7

Browse files
Allow awaiting .openInEditor() (#272)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent d120209 commit c0bcdb7

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ declare class ElectronStore<T extends Record<string, any> = Record<string, unkno
5959

6060
/**
6161
Open the storage file in the user's editor.
62+
63+
Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.
6264
*/
63-
openInEditor(): void;
65+
openInEditor(): Promise<void>;
6466
}
6567

6668
export = ElectronStore;

index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ class ElectronStore extends Conf {
7373
initDataListener();
7474
}
7575

76-
openInEditor() {
77-
shell.openPath(this.path);
76+
async openInEditor() {
77+
const error = await shell.openPath(this.path);
78+
79+
if (error) {
80+
throw new Error(error);
81+
}
7882
}
7983
}
8084

index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ store.reset('foo');
1818
store.has('foo');
1919
store.clear();
2020

21-
store.openInEditor();
21+
await store.openInEditor();
2222

2323
store.size; // eslint-disable-line @typescript-eslint/no-unused-expressions
2424
store.store; // eslint-disable-line @typescript-eslint/no-unused-expressions

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ Get the path to the storage file.
379379

380380
Open the storage file in the user's editor.
381381

382+
Returns a promise that resolves when the editor has been opened, or rejects if it failed to open.
383+
382384
### initRenderer()
383385

384386
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.

0 commit comments

Comments
 (0)