From fd7c2edbbcd20288647e574e0fa731c58e7e13ca Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 2 Dec 2024 14:40:19 +0800 Subject: [PATCH] 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 --- src/contributes/commands.ts | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 4319715..2dc2085 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -216,31 +216,38 @@ export function registerInstallCommandsCommand( const currentVersion = UiUtilWrapper.extensionPath(); const previousVersion = devchatConfig.get("last_devchat_version", ""); + let copiedDirectory = false; if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) { logger.channel()?.debug("Creating directory: " + sysMericoDirPath); await copyDirectory(pluginDirPath, sysDirPath); + copiedDirectory = true; } devchatConfig.set("last_devchat_version", currentVersion); - // Check if ~/.chat/scripts directory exists - if (!fs.existsSync(sysMericoDirPath)) { - // Directory does not exist, wait for updateWorkflows to finish - logger.channel()?.debug("Update workflows..."); - await dcClient.updateWorkflows(); - await dcClient.updateCustomWorkflows(); + if (copiedDirectory) { + logger.channel()?.debug("Directory copied successfully."); sendCommandListByDevChatRun(); } else { - // Directory exists, execute sendCommandListByDevChatRun immediately - logger.channel()?.debug("Sending and updating workflows..."); - await sendCommandListByDevChatRun(); + // Check if ~/.chat/scripts directory exists + if (!fs.existsSync(sysMericoDirPath)) { + // 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 - await dcClient.updateWorkflows(); - await dcClient.updateCustomWorkflows(); - - await sendCommandListByDevChatRun(); + // Then asynchronously execute updateWorkflows + await dcClient.updateWorkflows(); + await dcClient.updateCustomWorkflows(); + + await sendCommandListByDevChatRun(); + } } - + // Ensure the panel is activated await ensureChatPanel(context); }