@raycast/utils
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -9,6 +9,8 @@ "use strict"; | ||
const api_1 = require("@raycast/api"); | ||
const fs_1 = require("fs"); | ||
const react_1 = require("react"); | ||
const node_fs_1 = require("node:fs"); | ||
const promises_1 = require("node:fs/promises"); | ||
const node_os_1 = __importDefault(require("node:os")); | ||
const node_child_process_1 = __importDefault(require("node:child_process")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const react_1 = require("react"); | ||
const usePromise_1 = require("./usePromise"); | ||
@@ -69,14 +71,17 @@ const useLatest_1 = require("./useLatest"); | ||
else { | ||
(0, api_1.showToast)({ | ||
style: api_1.Toast.Style.Failure, | ||
title: "Cannot query the data", | ||
message: error.message, | ||
primaryAction: { | ||
title: "Copy Logs", | ||
onAction(toast) { | ||
toast.hide(); | ||
api_1.Clipboard.copy(error?.stack || error?.message || ""); | ||
console.error(error); | ||
if (api_1.environment.launchType !== api_1.LaunchType.Background) { | ||
(0, api_1.showToast)({ | ||
style: api_1.Toast.Style.Failure, | ||
title: "Cannot query the data", | ||
message: error.message, | ||
primaryAction: { | ||
title: "Copy Logs", | ||
onAction(toast) { | ||
toast.hide(); | ||
api_1.Clipboard.copy(error?.stack || error?.message || ""); | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -86,3 +91,3 @@ } | ||
const fn = (0, react_1.useMemo)(() => { | ||
if (!(0, fs_1.existsSync)(databasePath)) { | ||
if (!(0, node_fs_1.existsSync)(databasePath)) { | ||
throw new Error("The database does not exist"); | ||
@@ -95,3 +100,19 @@ } | ||
const spawnedPromise = (0, exec_utils_1.getSpawnedPromise)(spawned); | ||
const [{ error, exitCode, signal }, stdoutResult, stderrResult] = await (0, exec_utils_1.getSpawnedResult)(spawned, { encoding: "utf-8" }, spawnedPromise); | ||
let [{ error, exitCode, signal }, stdoutResult, stderrResult] = await (0, exec_utils_1.getSpawnedResult)(spawned, { encoding: "utf-8" }, spawnedPromise); | ||
if (stderrResult.match("(5)")) { | ||
// That means that the DB is busy because of another app is locking it | ||
// This happens when Chrome or Arc is opened: they lock the History db. | ||
// As an ugly workaround, we duplicate the file and read that instead | ||
// (with vfs unix - none to just not care about locks) | ||
const tempFolder = await (0, promises_1.mkdtemp)(node_path_1.default.join(node_os_1.default.tmpdir(), "useSQL-")); | ||
const newDbPath = node_path_1.default.join(tempFolder, "db"); | ||
await (0, promises_1.copyFile)(databasePath, newDbPath); | ||
const spawned = node_child_process_1.default.spawn("sqlite3", ["--json", "--readonly", "--vfs", "unix-none", databasePath, query], { | ||
signal: abortable.current?.signal, | ||
}); | ||
const spawnedPromise = (0, exec_utils_1.getSpawnedPromise)(spawned); | ||
[{ error, exitCode, signal }, stdoutResult, stderrResult] = await (0, exec_utils_1.getSpawnedResult)(spawned, { encoding: "utf-8" }, spawnedPromise); | ||
await (0, promises_1.rm)(newDbPath); | ||
await (0, promises_1.rmdir)(tempFolder); | ||
} | ||
if (error || exitCode !== 0 || signal !== null) { | ||
@@ -98,0 +119,0 @@ throw new Error(stderrResult); |
{ | ||
"name": "@raycast/utils", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
122254
2648
2