Skip to content

Commit fd7c2ed

Browse files
committed
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
1 parent 54b4938 commit fd7c2ed

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/contributes/commands.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,31 +216,38 @@ export function registerInstallCommandsCommand(
216216
const currentVersion = UiUtilWrapper.extensionPath();
217217
const previousVersion = devchatConfig.get("last_devchat_version", "");
218218

219+
let copiedDirectory = false;
219220
if (!fs.existsSync(sysMericoDirPath) || (updatePublicWorkflow === false && currentVersion !== previousVersion)) {
220221
logger.channel()?.debug("Creating directory: " + sysMericoDirPath);
221222
await copyDirectory(pluginDirPath, sysDirPath);
223+
copiedDirectory = true;
222224
}
223225
devchatConfig.set("last_devchat_version", currentVersion);
224226

225-
// Check if ~/.chat/scripts directory exists
226-
if (!fs.existsSync(sysMericoDirPath)) {
227-
// Directory does not exist, wait for updateWorkflows to finish
228-
logger.channel()?.debug("Update workflows...");
229-
await dcClient.updateWorkflows();
230-
await dcClient.updateCustomWorkflows();
227+
if (copiedDirectory) {
228+
logger.channel()?.debug("Directory copied successfully.");
231229
sendCommandListByDevChatRun();
232230
} else {
233-
// Directory exists, execute sendCommandListByDevChatRun immediately
234-
logger.channel()?.debug("Sending and updating workflows...");
235-
await sendCommandListByDevChatRun();
236-
237-
// Then asynchronously execute updateWorkflows
238-
await dcClient.updateWorkflows();
239-
await dcClient.updateCustomWorkflows();
240-
241-
await sendCommandListByDevChatRun();
231+
// Check if ~/.chat/scripts directory exists
232+
if (!fs.existsSync(sysMericoDirPath)) {
233+
// Directory does not exist, wait for updateWorkflows to finish
234+
logger.channel()?.debug("Update workflows...");
235+
await dcClient.updateWorkflows();
236+
await dcClient.updateCustomWorkflows();
237+
sendCommandListByDevChatRun();
238+
} else {
239+
// Directory exists, execute sendCommandListByDevChatRun immediately
240+
logger.channel()?.debug("Sending and updating workflows...");
241+
await sendCommandListByDevChatRun();
242+
243+
// Then asynchronously execute updateWorkflows
244+
await dcClient.updateWorkflows();
245+
await dcClient.updateCustomWorkflows();
246+
247+
await sendCommandListByDevChatRun();
248+
}
242249
}
243-
250+
244251
// Ensure the panel is activated
245252
await ensureChatPanel(context);
246253
}

0 commit comments

Comments
 (0)