refactor: Optimize workflow update and command list process
- Introduce copiedDirectory flag to track directory creation - Restructure conditional logic for better flow control - Improve error handling and logging for directory operations
This commit is contained in:
parent
54b49389c5
commit
fd7c2edbbc
@ -216,31 +216,38 @@ export function registerInstallCommandsCommand(
|
|||||||
const currentVersion = UiUtilWrapper.extensionPath();
|
const currentVersion = UiUtilWrapper.extensionPath();
|
||||||
const previousVersion = devchatConfig.get("last_devchat_version", "");
|
const previousVersion = devchatConfig.get("last_devchat_version", "");
|
||||||
|
|
||||||
|
let copiedDirectory = false;
|
||||||
if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) {
|
if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) {
|
||||||
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
|
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
|
||||||
await copyDirectory(pluginDirPath, sysDirPath);
|
await copyDirectory(pluginDirPath, sysDirPath);
|
||||||
|
copiedDirectory = true;
|
||||||
}
|
}
|
||||||
devchatConfig.set("last_devchat_version", currentVersion);
|
devchatConfig.set("last_devchat_version", currentVersion);
|
||||||
|
|
||||||
// Check if ~/.chat/scripts directory exists
|
if (copiedDirectory) {
|
||||||
if (!fs.existsSync(sysMericoDirPath)) {
|
logger.channel()?.debug("Directory copied successfully.");
|
||||||
// Directory does not exist, wait for updateWorkflows to finish
|
|
||||||
logger.channel()?.debug("Update workflows...");
|
|
||||||
await dcClient.updateWorkflows();
|
|
||||||
await dcClient.updateCustomWorkflows();
|
|
||||||
sendCommandListByDevChatRun();
|
sendCommandListByDevChatRun();
|
||||||
} else {
|
} else {
|
||||||
// Directory exists, execute sendCommandListByDevChatRun immediately
|
// Check if ~/.chat/scripts directory exists
|
||||||
logger.channel()?.debug("Sending and updating workflows...");
|
if (!fs.existsSync(sysMericoDirPath)) {
|
||||||
await sendCommandListByDevChatRun();
|
// Directory does not exist, wait for updateWorkflows to finish
|
||||||
|
logger.channel()?.debug("Update workflows...");
|
||||||
|
await dcClient.updateWorkflows();
|
||||||
|
await dcClient.updateCustomWorkflows();
|
||||||
|
sendCommandListByDevChatRun();
|
||||||
|
} else {
|
||||||
|
// Directory exists, execute sendCommandListByDevChatRun immediately
|
||||||
|
logger.channel()?.debug("Sending and updating workflows...");
|
||||||
|
await sendCommandListByDevChatRun();
|
||||||
|
|
||||||
// Then asynchronously execute updateWorkflows
|
// Then asynchronously execute updateWorkflows
|
||||||
await dcClient.updateWorkflows();
|
await dcClient.updateWorkflows();
|
||||||
await dcClient.updateCustomWorkflows();
|
await dcClient.updateCustomWorkflows();
|
||||||
|
|
||||||
await sendCommandListByDevChatRun();
|
await sendCommandListByDevChatRun();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the panel is activated
|
// Ensure the panel is activated
|
||||||
await ensureChatPanel(context);
|
await ensureChatPanel(context);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user