diff --git a/gui b/gui index 66c9115..c883677 160000 --- a/gui +++ b/gui @@ -1 +1 @@ -Subproject commit 66c9115f69ad90eea993cee16dcf93e280673201 +Subproject commit c8836777f0d09ce1328166abec5cebc480a2590a diff --git a/prebuild.js b/prebuild.js index 8dbff20..0c3fd26 100644 --- a/prebuild.js +++ b/prebuild.js @@ -1,26 +1,26 @@ -require('dotenv').config() +require('dotenv').config(); -const fs = require('fs') -const path = require('path') +const fs = require('fs'); +const path = require('path'); function copyIcon(src, dst) { if (!src) { - console.warn(`Icon path for ${dst} is not defined in your environment variables`) - return + console.warn(`Icon path for ${dst} is not defined in your environment variables`); + return; } - console.log(`Replacing icon ${dst} by ${src}`) + console.log(`Replacing icon ${dst} by ${src}`); if (!fs.existsSync(src)) { - console.warn(`Icon file ${src} does not exist.`) - return + console.warn(`Icon file ${src} does not exist.`); + return; } - const destPath = path.join(__dirname, 'assets', dst) + const destPath = path.join(__dirname, 'assets', dst); try { - fs.copyFileSync(src, destPath) - fs.chmodSync(destPath, 0o644) + fs.copyFileSync(src, destPath); + fs.chmodSync(destPath, 0o644); } catch(e) { - console.warn(`Failed to copy logo ${e}`) + console.warn(`Failed to copy logo ${e}`); } } @@ -31,7 +31,7 @@ function updatePackageJson() { ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat", ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat" } - console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`) + console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`); let packageJson = fs.readFileSync('package.json', 'utf8'); @@ -44,8 +44,8 @@ function updatePackageJson() { fs.writeFileSync('package.json', packageJson); } -copyIcon(process.env.EXTENSION_ICON, 'devchat.png') -copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg') -copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg') +copyIcon(process.env.EXTENSION_ICON, 'devchat.png'); +copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg'); +copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg'); -updatePackageJson() \ No newline at end of file +updatePackageJson(); \ No newline at end of file diff --git a/src/context/contextCodeSelected.ts b/src/context/contextCodeSelected.ts index 0f5d435..3d390ed 100644 --- a/src/context/contextCodeSelected.ts +++ b/src/context/contextCodeSelected.ts @@ -16,7 +16,9 @@ export async function handleCodeSelected(fileSelected: string, codeSelected: str // get relative path of workspace const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); - const relativePath = path.relative(workspaceDir!, fileSelected); + const relativePath = workspaceDir + ? path.relative(workspaceDir, fileSelected) + : fileSelected; // convert fileContent to markdown code block with languageId and file path const data = { diff --git a/src/context/contextFileSelected.ts b/src/context/contextFileSelected.ts index 94c1a8f..d7f09a8 100644 --- a/src/context/contextFileSelected.ts +++ b/src/context/contextFileSelected.ts @@ -19,7 +19,9 @@ export async function handleFileSelected(fileSelected: string) { // get relative path of workspace const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); - const relativePath = path.relative(workspaceDir!, fileSelected); + const relativePath = workspaceDir + ? path.relative(workspaceDir, fileSelected) + : fileSelected; // convert fileContent to markdown code block with languageId and file path const data = { 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); } diff --git a/workflowsCommands b/workflowsCommands index ed9898d..f4a4dbc 160000 --- a/workflowsCommands +++ b/workflowsCommands @@ -1 +1 @@ -Subproject commit ed9898d038e09732bbcaba0ef655efc1f89ef9a8 +Subproject commit f4a4dbc529e4fc80f67a0492674854c6fb8a29d3