Skip to content

Commit 8cfdd96

Browse files
committed
fix (core): 修复版本号获取规则
1 parent 91f6185 commit 8cfdd96

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

src-tauri/src/plugin.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
use crate::plugins::{LanguageInfo, PluginManager};
22
use log::{debug, error, info};
3+
use regex::Regex;
34
use std::process::Command;
45
use tauri::State;
56
use tokio::sync::Mutex;
67

78
pub type PluginManagerState = Mutex<PluginManager>;
89

9-
// 通用的环境信息获取函数
10+
fn extract_version(output: &str) -> String {
11+
let output = output.trim();
12+
13+
let version_patterns = vec![
14+
r"(?i)version\s+([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?)",
15+
r"(?i)version\s+([0-9]+\.[0-9]+(?:\.[0-9]+)?)",
16+
r"\bv?([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?)\b",
17+
r"\bv?([0-9]+\.[0-9]+(?:\.[0-9]+)?)\b",
18+
r#""([0-9]+\.[0-9]+\.[0-9]+)""#,
19+
];
20+
21+
for pattern in version_patterns {
22+
if let Ok(re) = Regex::new(pattern) {
23+
if let Some(cap) = re.captures(output) {
24+
if let Some(version) = cap.get(1) {
25+
return version.as_str().to_string();
26+
}
27+
}
28+
}
29+
}
30+
31+
if let Some(first_line) = output.lines().next() {
32+
if !first_line.is_empty() {
33+
return first_line.to_string();
34+
}
35+
}
36+
37+
output.to_string()
38+
}
39+
1040
#[tauri::command]
1141
pub async fn get_info(
1242
language: String,
@@ -44,20 +74,27 @@ pub async fn get_info(
4474
.arg(plugin.get_path_command())
4575
.output();
4676

47-
let mut version = String::from_utf8_lossy(&version_out.stdout)
77+
let mut raw_version = String::from_utf8_lossy(&version_out.stdout)
4878
.trim()
4979
.to_string();
5080

51-
if version.is_empty() {
81+
if raw_version.is_empty() {
5282
info!(
5383
"获取环境 -> 调用插件 [ {} ] 版本为空,通过 stderr 获取",
5484
language
5585
);
56-
version = String::from_utf8_lossy(&version_out.stderr)
86+
raw_version = String::from_utf8_lossy(&version_out.stderr)
5787
.trim()
5888
.to_string();
5989
}
6090

91+
let version = extract_version(&raw_version);
92+
let final_version = if version.is_empty() {
93+
raw_version
94+
} else {
95+
version
96+
};
97+
6198
let path = if let Ok(path_out) = path_result {
6299
if path_out.status.success() {
63100
String::from_utf8_lossy(&path_out.stdout).trim().to_string()
@@ -71,7 +108,7 @@ pub async fn get_info(
71108
info!("获取环境 -> 调用插件 [ {} ] 完成", language);
72109
return Ok(LanguageInfo {
73110
installed: true,
74-
version,
111+
version: final_version,
75112
path,
76113
language: plugin.get_language_name().to_string(),
77114
});
@@ -90,7 +127,6 @@ pub async fn get_info(
90127
})
91128
}
92129

93-
// 获取支持的语言列表
94130
#[tauri::command]
95131
pub async fn get_supported_languages(
96132
plugin_manager: State<'_, PluginManagerState>,

src/composables/useStatusBar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type Ref } from 'vue'
2-
import { CheckCircle, Loader2, XCircle } from 'lucide-vue-next'
3-
import { EnvInfo } from '../types/app.ts'
1+
import {type Ref} from 'vue'
2+
import {CheckCircle, Loader2, XCircle} from 'lucide-vue-next'
3+
import {EnvInfo} from '../types/app.ts'
44

55
export function useStatusBar(envInfo: Ref<EnvInfo>, isLoading: Ref<boolean>)
66
{
@@ -31,14 +31,14 @@ export function useStatusBar(envInfo: Ref<EnvInfo>, isLoading: Ref<boolean>)
3131
// 计算状态文本
3232
const getStatusText = () => {
3333
if (isLoading.value) {
34-
return `${ envInfo.value.language }: 检查环境中...`
34+
return `${envInfo.value.language}: 检查环境中...`
3535
}
3636

3737
if (envInfo.value.installed) {
38-
return `${ envInfo.value.language }: ${ envInfo.value.version }`
38+
return `${envInfo.value.language}: ${envInfo.value.version || '--'}`
3939
}
4040
else {
41-
return `${ envInfo.value.language }: 环境未安装`
41+
return `${envInfo.value.language}: 环境未安装`
4242
}
4343
}
4444

0 commit comments

Comments
 (0)