Skip to content

Commit 092d1b0

Browse files
committed
feat (plugin): 支持 order 排序
1 parent aee9983 commit 092d1b0

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

src-tauri/src/plugins/manager.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ impl PluginManager {
2020
}
2121

2222
pub fn get_supported_languages(&self) -> Vec<serde_json::Value> {
23-
self.plugins
24-
.iter()
23+
let mut plugins: Vec<_> = self.plugins.iter().collect();
24+
plugins.sort_by_key(|(_, plugin)| plugin.get_order());
25+
26+
plugins
27+
.into_iter()
2528
.map(|(key, plugin)| {
2629
serde_json::json!({
2730
"name": plugin.get_language_name(),

src-tauri/src/plugins/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub struct LanguageInfo {
2727

2828
// 语言插件接口
2929
pub trait LanguagePlugin: Send + Sync {
30+
fn get_order(&self) -> i32 {
31+
0
32+
}
3033
fn get_language_name(&self) -> &'static str;
3134
fn get_file_extension(&self) -> &'static str;
3235
fn get_commands(&self) -> Vec<&'static str>;

src-tauri/src/plugins/python2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use super::{ExecutionResult, LanguagePlugin};
33
pub struct Python2Plugin;
44

55
impl LanguagePlugin for Python2Plugin {
6+
fn get_order(&self) -> i32 {
7+
1
8+
}
9+
610
fn get_language_name(&self) -> &'static str {
711
"Python 2"
812
}
@@ -30,7 +34,7 @@ impl LanguagePlugin for Python2Plugin {
3034
fn pre_execute_hook(&self, code: &str) -> Result<String, String> {
3135
// 添加一些 Python 特定的预处理
3236
let processed_code = format!(
33-
"# CodeForge Python Execution\n# Generated at: {}\n\n{}",
37+
"# CodeForge Python 2 Execution\n# Generated at: {}\n\n{}",
3438
chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
3539
code
3640
);

src-tauri/src/plugins/python3.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use super::{ExecutionResult, LanguagePlugin};
33
pub struct Python3Plugin;
44

55
impl LanguagePlugin for Python3Plugin {
6+
fn get_order(&self) -> i32 {
7+
2
8+
}
9+
610
fn get_language_name(&self) -> &'static str {
711
"Python 3"
812
}
@@ -30,7 +34,7 @@ impl LanguagePlugin for Python3Plugin {
3034
fn pre_execute_hook(&self, code: &str) -> Result<String, String> {
3135
// 添加一些 Python 特定的预处理
3236
let processed_code = format!(
33-
"# CodeForge Python Execution\n# Generated at: {}\n\n{}",
37+
"# CodeForge Python 3 Execution\n# Generated at: {}\n\n{}",
3438
chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
3539
code
3640
);

src/components/StatusBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<component :is="envInfo.installed ? CheckCircle : XCircle"
77
:class="envInfo.installed ? 'text-green-300' : 'text-white'"
88
class="w-4 h-4"/>
9-
<span>{{ envInfo.installed ? `${ envInfo.language }: ${ envInfo.version }` : `${ envInfo.language } 环境未安装` }}</span>
9+
<span>{{ envInfo.installed ? `${ envInfo.language }: ${ envInfo.version }` : `${ envInfo.language }: 环境未安装` }}</span>
1010
</div>
1111

1212
<div v-if="executionTime > 0" class="flex items-center space-x-2">

0 commit comments

Comments
 (0)