Skip to content

Commit 6c9f838

Browse files
committed
fix (language): 修复接口默认处理导致程序中断问题
1 parent cae1eee commit 6c9f838

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

src-tauri/src/plugins/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ pub trait LanguagePlugin: Send + Sync {
5656
fn get_language_key(&self) -> &'static str;
5757

5858
// 获取插件支持的文件扩展名
59-
fn get_file_extension(&self) -> String {
60-
self.get_config().unwrap().extension.clone()
61-
}
59+
fn get_file_extension(&self) -> String;
6260

6361
// 获取执行目录
6462
fn get_execute_home(&self) -> Option<PathBuf> {

src-tauri/src/plugins/python2.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ impl LanguagePlugin for Python2Plugin {
1616
"python2"
1717
}
1818

19+
fn get_file_extension(&self) -> String {
20+
self.get_config()
21+
.map(|config| config.extension.clone())
22+
.unwrap_or_else(|| "py".to_string())
23+
}
24+
1925
fn get_version_args(&self) -> Vec<&'static str> {
2026
vec!["--version"]
2127
}
@@ -39,6 +45,8 @@ impl LanguagePlugin for Python2Plugin {
3945
}
4046

4147
fn get_default_command(&self) -> String {
42-
self.get_config().unwrap().run_command.unwrap()
48+
self.get_config()
49+
.and_then(|config| config.run_command)
50+
.unwrap_or_else(|| "python2".to_string())
4351
}
4452
}

src-tauri/src/plugins/python3.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ impl LanguagePlugin for Python3Plugin {
1515
"python3"
1616
}
1717

18+
fn get_file_extension(&self) -> String {
19+
self.get_config()
20+
.map(|config| config.extension.clone())
21+
.unwrap_or_else(|| "py".to_string())
22+
}
23+
1824
fn get_version_args(&self) -> Vec<&'static str> {
1925
vec!["--version"]
2026
}
@@ -38,6 +44,8 @@ impl LanguagePlugin for Python3Plugin {
3844
}
3945

4046
fn get_default_command(&self) -> String {
41-
self.get_config().unwrap().run_command.unwrap()
47+
self.get_config()
48+
.and_then(|config| config.run_command)
49+
.unwrap_or_else(|| "python3".to_string())
4250
}
4351
}

src/App.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ const handleLanguageChange = async (newLanguage: string) => {
251251
252252
// 更新代码模板
253253
code.value = codeTemplates[newLanguage] || `# ${ getLanguageDisplayName(newLanguage) } Code
254-
# Write your code here...
255-
256-
print("Hello from ${ getLanguageDisplayName(newLanguage) }!")`
254+
# Write your code here...`
257255
258256
// 清空输出
259257
clearOutput()

0 commit comments

Comments
 (0)