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:
bobo.yang 2024-12-02 14:40:19 +08:00
parent 54b49389c5
commit fd7c2edbbc

View File

@ -216,12 +216,18 @@ 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);
if (copiedDirectory) {
logger.channel()?.debug("Directory copied successfully.");
sendCommandListByDevChatRun();
} else {
// Check if ~/.chat/scripts directory exists // Check if ~/.chat/scripts directory exists
if (!fs.existsSync(sysMericoDirPath)) { if (!fs.existsSync(sysMericoDirPath)) {
// Directory does not exist, wait for updateWorkflows to finish // Directory does not exist, wait for updateWorkflows to finish
@ -240,6 +246,7 @@ export function registerInstallCommandsCommand(
await sendCommandListByDevChatRun(); await sendCommandListByDevChatRun();
} }
}
// Ensure the panel is activated // Ensure the panel is activated
await ensureChatPanel(context); await ensureChatPanel(context);