mac-helper 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/dialog.js CHANGED
@@ -8,12 +8,18 @@ exports.dialog = {
8
8
  chooseMultipleFromList,
9
9
  };
10
10
  async function prompt(label, defaultValue = '') {
11
- return ((await (0, run_1.run)((label) => {
12
- const app = Application.currentApplication();
13
- app.includeStandardAdditions = true;
14
- const response = app.displayDialog(label, { defaultAnswer: '' });
15
- return response.textReturned;
16
- }, label)) || defaultValue);
11
+ // if cancel dialog, will throw error
12
+ try {
13
+ return ((await (0, run_1.run)((label) => {
14
+ const app = Application.currentApplication();
15
+ app.includeStandardAdditions = true;
16
+ const response = app.displayDialog(label, { defaultAnswer: '' });
17
+ return response.textReturned;
18
+ }, label)) || defaultValue);
19
+ }
20
+ catch {
21
+ return defaultValue;
22
+ }
17
23
  }
18
24
  async function runOnCurrentApp(method, ...args) {
19
25
  return await (0, run_1.run)((method, ...args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mac-helper",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "useful helper for macOS",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/dialog.ts CHANGED
@@ -8,14 +8,19 @@ export const dialog = {
8
8
  }
9
9
 
10
10
  async function prompt(label: string, defaultValue = ''): Promise<string> {
11
- return (
12
- (await run((label) => {
13
- const app = Application.currentApplication()
14
- app.includeStandardAdditions = true
15
- const response = app.displayDialog(label, { defaultAnswer: '' })
16
- return response.textReturned
17
- }, label)) || defaultValue
18
- )
11
+ // if cancel dialog, will throw error
12
+ try {
13
+ return (
14
+ (await run((label) => {
15
+ const app = Application.currentApplication()
16
+ app.includeStandardAdditions = true
17
+ const response = app.displayDialog(label, { defaultAnswer: '' })
18
+ return response.textReturned
19
+ }, label)) || defaultValue
20
+ )
21
+ } catch {
22
+ return defaultValue
23
+ }
19
24
  }
20
25
 
21
26
  type AppMethod = 'chooseFromList'