mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-03 06:00:49 +00:00
feat(insightCommand): simplify file opening by using 'open' package
This commit is contained in:
parent
2a432b18f7
commit
fcb22a3f79
1 changed files with 2 additions and 36 deletions
|
|
@ -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(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue