feat(insightCommand): simplify file opening by using 'open' package

This commit is contained in:
DragonnZhang 2026-02-10 14:47:33 +08:00
parent 2a432b18f7
commit fcb22a3f79

View file

@ -13,44 +13,10 @@ import { join } from 'path';
import os from 'os';
import { StaticInsightGenerator } from '../../services/insight/generators/StaticInsightGenerator.js';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
import open from 'open';
const logger = createDebugLogger('DataProcessor');
// Open file in default browser
async function openFileInBrowser(filePath: string): Promise<void> {
const { exec } = await import('child_process');
const { promisify } = await import('util');
const execAsync = promisify(exec);
// Convert to file:// URL for cross-platform compatibility
const fileUrl = `file://${filePath.replace(/\\/g, '/')}`;
try {
switch (process.platform) {
case 'darwin': // macOS
await execAsync(`open "${fileUrl}"`);
break;
case 'win32': // Windows
await execAsync(`start "" "${fileUrl}"`);
break;
default: // Linux and others
await execAsync(`xdg-open "${fileUrl}"`);
}
} catch (_error) {
// If opening fails, try with local file path
switch (process.platform) {
case 'darwin': // macOS
await execAsync(`open "${filePath}"`);
break;
case 'win32': // Windows
await execAsync(`start "" "${filePath}"`);
break;
default: // Linux and others
await execAsync(`xdg-open "${filePath}"`);
}
}
}
export const insightCommand: SlashCommand = {
name: 'insight',
get description() {
@ -109,7 +75,7 @@ export const insightCommand: SlashCommand = {
// Open the file in the default browser
try {
await openFileInBrowser(outputPath);
await open(outputPath);
context.ui.addItem(
{