@raycast/utils
Advanced tools
Comparing version 1.9.1 to 1.10.0
import { Toast } from "@raycast/api"; | ||
export declare const handleErrorToastAction: (error: Error) => Toast.ActionOptions; | ||
export declare const handleErrorToastAction: (error: unknown) => Toast.ActionOptions; | ||
//# sourceMappingURL=handle-error-toast-action.d.ts.map |
@@ -48,2 +48,3 @@ "use strict"; | ||
const fallback = api_1.environment.isDevelopment || privateExtension; | ||
const stack = error instanceof Error ? error?.stack || error?.message || "" : String(error); | ||
return { | ||
@@ -54,3 +55,3 @@ title: fallback ? "Copy Logs" : "Report Error", | ||
if (fallback) { | ||
api_1.Clipboard.copy(error?.stack || error?.message || ""); | ||
api_1.Clipboard.copy(stack); | ||
} | ||
@@ -60,3 +61,3 @@ else { | ||
\`\`\` | ||
${error?.stack || error?.message || ""} | ||
${stack} | ||
\`\`\` | ||
@@ -63,0 +64,0 @@ `)}`); |
@@ -12,4 +12,5 @@ export * from "./usePromise"; | ||
export * from "./run-applescript"; | ||
export * from "./showFailureToast"; | ||
export type { AsyncState, MutatePromise } from "./types"; | ||
export type { Response } from "cross-fetch"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -28,1 +28,2 @@ "use strict"; | ||
__exportStar(require("./run-applescript"), exports); | ||
__exportStar(require("./showFailureToast"), exports); |
@@ -25,2 +25,27 @@ import { ParseExecOutputHandler } from "./exec-utils"; | ||
}; | ||
/** | ||
* Executes an AppleScript script. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { showHUD } from "@raycast/api"; | ||
* import { runAppleScript, showFailureToast } from "@raycast/utils"; | ||
* | ||
* export default async function () { | ||
* try { | ||
* const res = await runAppleScript( | ||
* ` | ||
* on run argv | ||
* return "hello, " & item 1 of argv & "." | ||
* end run | ||
* `, | ||
* ["world"] | ||
* ); | ||
* await showHUD(res); | ||
* } catch (error) { | ||
* showFailureToast(error, { title: "Could not run AppleScript" }); | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export declare function runAppleScript<T = string>(script: string, options?: AppleScriptOptions & { | ||
@@ -27,0 +52,0 @@ parseOutput?: ParseExecOutputHandler<T, string, AppleScriptOptions>; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const useLatest_1 = require("./useLatest"); | ||
const handle_error_toast_action_1 = require("./handle-error-toast-action"); | ||
const showFailureToast_1 = require("./showFailureToast"); | ||
function usePromise(fn, args, options) { | ||
@@ -49,6 +49,4 @@ const lastCallId = (0, react_1.useRef)(0); | ||
if (api_1.environment.launchType !== api_1.LaunchType.Background) { | ||
(0, api_1.showToast)({ | ||
style: api_1.Toast.Style.Failure, | ||
(0, showFailureToast_1.showFailureToast)(error, { | ||
title: "Failed to fetch latest data", | ||
message: error.message, | ||
primaryAction: { | ||
@@ -61,3 +59,2 @@ title: "Retry", | ||
}, | ||
secondaryAction: (0, handle_error_toast_action_1.handleErrorToastAction)(error), | ||
}); | ||
@@ -64,0 +61,0 @@ } |
@@ -19,3 +19,3 @@ "use strict"; | ||
const exec_utils_1 = require("./exec-utils"); | ||
const handle_error_toast_action_1 = require("./handle-error-toast-action"); | ||
const showFailureToast_1 = require("./showFailureToast"); | ||
/** | ||
@@ -73,9 +73,5 @@ * Executes a query on a local SQL database and returns the {@link AsyncState} corresponding to the query of the command. The last value will be kept between command runs. | ||
else { | ||
console.error(error); | ||
if (api_1.environment.launchType !== api_1.LaunchType.Background) { | ||
(0, api_1.showToast)({ | ||
style: api_1.Toast.Style.Failure, | ||
(0, showFailureToast_1.showFailureToast)(error, { | ||
title: "Cannot query the data", | ||
message: error.message, | ||
primaryAction: (0, handle_error_toast_action_1.handleErrorToastAction)(error), | ||
}); | ||
@@ -82,0 +78,0 @@ } |
{ | ||
"name": "@raycast/utils", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"description": "Set of utilities to streamline building Raycast extensions", | ||
@@ -5,0 +5,0 @@ "author": "Raycast Technologies Ltd.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
148717
86
3217
5