Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@babel/runtime": "^7.28.2",
"@codemirror/lang-go": "^6.0.1",
"@codemirror/lang-java": "^6.0.2",
"@codemirror/lang-javascript": "^6.2.4",
"@codemirror/lang-python": "^6.2.1",
"@codemirror/state": "^6.5.2",
Expand Down
7 changes: 7 additions & 0 deletions public/icons/java.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion src-tauri/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,32 @@ pub async fn get_info(
debug!("获取环境 -> 插件 [ {} ] 命令 {}", language, cmd);

let version_output = Command::new(&cmd).args(plugin.get_version_args()).output();
debug!(
"获取环境 -> 插件 [ {} ] 版本, 结果 {:?}",
plugin.get_language_key(),
version_output
);
if let Ok(version_out) = version_output {
if version_out.status.success() {
let path_result = Command::new(&cmd)
.arg("-c")
.arg(plugin.get_path_command())
.output();

let version = String::from_utf8_lossy(&version_out.stdout)
let mut version = String::from_utf8_lossy(&version_out.stdout)
.trim()
.to_string();

if version.is_empty() {
info!(
"获取环境 -> 调用插件 [ {} ] 版本为空,通过 stderr 获取",
language
);
version = String::from_utf8_lossy(&version_out.stderr)
.trim()
.to_string();
}

let path = if let Ok(path_out) = path_result {
if path_out.status.success() {
String::from_utf8_lossy(&path_out.stdout).trim().to_string()
Expand Down
54 changes: 54 additions & 0 deletions src-tauri/src/plugins/java.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use super::{LanguagePlugin, PluginConfig};
use std::vec;

pub struct JavaPlugin;

impl LanguagePlugin for JavaPlugin {
fn get_order(&self) -> i32 {
5
}

fn get_language_name(&self) -> &'static str {
"Java"
}

fn get_language_key(&self) -> &'static str {
"java"
}

fn get_file_extension(&self) -> String {
self.get_config()
.map(|config| config.extension.clone())
.unwrap_or_else(|| "java".to_string())
}

fn get_version_args(&self) -> Vec<&'static str> {
vec!["-version"]
}

fn get_path_command(&self) -> String {
"System.out.println(System.getProperty(\"java.home\"));".to_string()
}

fn get_default_config(&self) -> PluginConfig {
PluginConfig {
enabled: true,
language: String::from("java"),
before_compile: None,
extension: String::from("java"),
execute_home: None,
run_command: Some(String::from("java $filename")),
after_compile: Some(String::from("rm -f *.class")),
template: Some(String::from(
"public class Main {\n public static void main(String[] args) {\n System.out.println(\"Hello, World!\");\n }\n}",
)),
timeout: Some(30),
}
}

fn get_default_command(&self) -> String {
self.get_config()
.and_then(|config| config.run_command.clone())
.unwrap_or_else(|| "java".to_string())
}
}
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{
LanguagePlugin, PluginConfig, go::GoPlugin, nodejs::NodeJSPlugin, python2::Python2Plugin,
python3::Python3Plugin,
};
use crate::plugins::java::JavaPlugin;
use std::collections::HashMap;

pub struct PluginManager {
Expand All @@ -16,6 +17,7 @@ impl PluginManager {
plugins.insert("python3".to_string(), Box::new(Python3Plugin));
plugins.insert("nodejs".to_string(), Box::new(NodeJSPlugin));
plugins.insert("go".to_string(), Box::new(GoPlugin));
plugins.insert("java".to_string(), Box::new(JavaPlugin));

Self { plugins }
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::config::get_app_config_internal;
use log::{debug, info};
use serde::{Deserialize, Serialize};
use std::format;
use std::path::PathBuf;

// 通用结构定义
Expand Down Expand Up @@ -329,6 +330,7 @@ pub trait LanguagePlugin: Send + Sync {

// 重新导出子模块
pub mod go;
pub mod java;
pub mod manager;
pub mod nodejs;
pub mod python2;
Expand Down
14 changes: 12 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ const {
lastExecutionTime,
runCode,
stopCode,
clearOutput
clearOutput,
handleRealtimeOutput,
handleExecutionComplete,
handleExecutionStopped,
handleExecutionTimeout,
handleExecutionError
} = useCodeExecution(toast)

const {
Expand Down Expand Up @@ -113,7 +118,12 @@ const { initializeEventListeners, cleanupEventListeners } = useEventManager({
isSuccess,
lastExecutionTime,
currentLanguage,
toast
toast,
handleRealtimeOutput,
handleExecutionComplete,
handleExecutionStopped,
handleExecutionTimeout,
handleExecutionError
})

// 禁用右键菜单
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
extensions,
editorConfig,
initializeEditor
} = useCodeMirrorEditor(props, emit)
} = useCodeMirrorEditor(props)

const handleInput = (value: string) => {
emit('update:modelValue', value)
Expand Down
Loading
Loading