新增quickcommand.showLoadingBar,支持显示加载条

This commit is contained in:
fofolee
2025-02-17 22:38:19 +08:00
parent d7508c36a7
commit 3eca3b448e
14 changed files with 339 additions and 84 deletions

View File

@@ -105,8 +105,27 @@ async function chat(apiConfig, content) {
throw new Error("不支持的模型类型");
}
const loadingBar = await quickcommand.showLoadingBar({
text: "AI思考中...",
onClose: () => {
// 取消请求
if (source) {
source.cancel("操作已取消");
}
},
});
// 创建取消令牌
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
// 发送请求
const response = await axios.post(url, requestData, config);
const response = await axios.post(url, requestData, {
...config,
cancelToken: source.token,
});
loadingBar.close();
// 解析不同模型的响应
let result;
@@ -129,6 +148,14 @@ async function chat(apiConfig, content) {
result,
};
} catch (error) {
// 如果是用户取消的请求,返回特定的错误信息
if (axios.isCancel(error)) {
return {
success: false,
error: "请求已取消",
cancelled: true,
};
}
return {
success: false,
error: error.response?.data?.error?.message || error.message,

View File

@@ -18,7 +18,6 @@ async function runFFmpeg(args, options = {}) {
return;
}
const {
title = "FFmpeg处理",
text = "处理中...",
position = "bottom-right",
onPause,
@@ -31,7 +30,6 @@ async function runFFmpeg(args, options = {}) {
// 显示进度条
const processBar = isShowProcessBar
? await quickcommand.showProcessBar({
title,
text,
value: 0,
position,

View File

@@ -1,13 +1,29 @@
const { runCsharpFeature } = require("../../csharp");
const child_process = require("child_process");
const stopMonitor = () => {
child_process.exec("taskkill /f /im monitor.exe");
};
// 监控剪贴板变化
const watchClipboard = async function () {
const args = ["-type", "clipboard", "-once"];
const result = await runCsharpFeature("monitor", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
const loadingBar = await quickcommand.showLoadingBar({
text: "等待剪贴板变化...",
onClose: () => {
stopMonitor();
},
});
try {
const result = await runCsharpFeature("monitor", args);
loadingBar.close();
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return JSON.parse(result);
} catch (error) {
return {};
}
return JSON.parse(result);
};
// 监控文件系统变化
@@ -28,11 +44,23 @@ const watchFileSystem = async function (watchPath, options = {}) {
args.push("-recursive", "false");
}
const result = await runCsharpFeature("monitor", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
const loadingBar = await quickcommand.showLoadingBar({
text: "等待文件变化...",
onClose: () => {
stopMonitor();
},
});
try {
const result = await runCsharpFeature("monitor", args);
loadingBar.close();
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return JSON.parse(result);
} catch (error) {
return {};
}
return JSON.parse(result);
};
module.exports = {