Skip to content

Commit 7465a3d

Browse files
committed
feat (language): 增加 Java 图标
1 parent 0ad08ec commit 7465a3d

6 files changed

Lines changed: 51 additions & 73 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@babel/runtime": "^7.28.2",
1414
"@codemirror/lang-go": "^6.0.1",
15+
"@codemirror/lang-java": "^6.0.2",
1516
"@codemirror/lang-javascript": "^6.2.4",
1617
"@codemirror/lang-python": "^6.2.1",
1718
"@codemirror/state": "^6.5.2",

public/icons/java.svg

Lines changed: 7 additions & 0 deletions
Loading

src-tauri/src/plugins/java.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct JavaPlugin;
55

66
impl LanguagePlugin for JavaPlugin {
77
fn get_order(&self) -> i32 {
8-
2
8+
5
99
}
1010

1111
fn get_language_name(&self) -> &'static str {

src/App.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ const {
8282
lastExecutionTime,
8383
runCode,
8484
stopCode,
85-
clearOutput
85+
clearOutput,
86+
handleRealtimeOutput,
87+
handleExecutionComplete,
88+
handleExecutionStopped,
89+
handleExecutionTimeout,
90+
handleExecutionError
8691
} = useCodeExecution(toast)
8792
8893
const {
@@ -113,7 +118,12 @@ const { initializeEventListeners, cleanupEventListeners } = useEventManager({
113118
isSuccess,
114119
lastExecutionTime,
115120
currentLanguage,
116-
toast
121+
toast,
122+
handleRealtimeOutput,
123+
handleExecutionComplete,
124+
handleExecutionStopped,
125+
handleExecutionTimeout,
126+
handleExecutionError
117127
})
118128
119129
// 禁用右键菜单

src/composables/useCodeMirrorEditor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { nextTick, ref, watch } from 'vue'
22
import { python } from '@codemirror/lang-python'
33
import { javascript } from '@codemirror/lang-javascript'
44
import { go } from '@codemirror/lang-go'
5+
import { java } from '@codemirror/lang-java'
56
import {
67
abcdef,
78
abyss,
@@ -155,6 +156,8 @@ export function useCodeMirrorEditor(props: Props, _emit: Emit)
155156
return javascript()
156157
case 'go':
157158
return go()
159+
case 'java':
160+
return java()
158161
default:
159162
return null
160163
}

src/composables/useEventManager.ts

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Ref } from 'vue'
2-
import { ref } from 'vue'
32
import { listen, UnlistenFn } from '@tauri-apps/api/event'
43
import { CodeOutputEvent } from '../types/app.ts'
54

@@ -14,6 +13,11 @@ interface EventManagerOptions
1413
lastExecutionTime: Ref<number>
1514
currentLanguage: Ref<string>
1615
toast: any
16+
handleRealtimeOutput: (currentLanguage: string, data: any) => void
17+
handleExecutionComplete: (currentLanguage: string, data: any) => void
18+
handleExecutionStopped: (currentLanguage: string, data: any) => void
19+
handleExecutionTimeout: (currentLanguage: string, data: any) => void
20+
handleExecutionError: (currentLanguage: string, data: any) => void
1721
}
1822

1923
export function useEventManager(options: EventManagerOptions)
@@ -22,12 +26,12 @@ export function useEventManager(options: EventManagerOptions)
2226
showAbout,
2327
showSettings,
2428
showUpdate,
25-
output,
26-
isRunning,
27-
isSuccess,
28-
lastExecutionTime,
2929
currentLanguage,
30-
toast
30+
handleRealtimeOutput,
31+
handleExecutionComplete,
32+
handleExecutionStopped,
33+
handleExecutionTimeout,
34+
handleExecutionError
3135
} = options
3236

3337
// 事件监听器引用
@@ -41,40 +45,11 @@ export function useEventManager(options: EventManagerOptions)
4145
let unlistenExecutionTimeoutFn: UnlistenFn | null = null
4246
let unlistenExecutionErrorFn: UnlistenFn | null = null
4347

44-
// 实时输出相关
45-
const realTimeOutput = ref('')
46-
const realTimeStderr = ref('')
47-
4848
// 处理实时输出
49-
const handleRealtimeOutput = (event: any) => {
49+
const handleRealtimeOutputWrapper = (event: any) => {
5050
const data: CodeOutputEvent = event.payload
5151
console.log('实时输出:', data)
52-
53-
// 只处理当前语言的输出
54-
if (data.language !== currentLanguage.value) {
55-
return
56-
}
57-
58-
if (data.type === 'stdout') {
59-
realTimeOutput.value += data.content + '\n'
60-
}
61-
else if (data.type === 'stderr') {
62-
realTimeStderr.value += data.content + '\n'
63-
}
64-
65-
// 合并输出显示
66-
let combinedOutput = ''
67-
if (realTimeOutput.value) {
68-
combinedOutput += realTimeOutput.value
69-
}
70-
if (realTimeStderr.value) {
71-
if (combinedOutput) {
72-
combinedOutput += '\n'
73-
}
74-
combinedOutput += realTimeStderr.value
75-
}
76-
77-
output.value = combinedOutput
52+
handleRealtimeOutput(currentLanguage.value, data)
7853
}
7954

8055
// 处理执行状态事件
@@ -85,44 +60,26 @@ export function useEventManager(options: EventManagerOptions)
8560
}
8661
}
8762

88-
const handleExecutionComplete = (event: any) => {
63+
const handleExecutionCompleteWrapper = (event: any) => {
8964
const data = event.payload
90-
if (data.language === currentLanguage.value) {
91-
isRunning.value = false
92-
isSuccess.value = data.success
93-
if (data.execution_time) {
94-
lastExecutionTime.value = data.execution_time
95-
}
96-
console.log('代码执行完成')
97-
}
65+
console.log('代码执行完成')
66+
handleExecutionComplete(currentLanguage.value, data)
9867
}
9968

100-
const handleExecutionStopped = (event: any) => {
69+
const handleExecutionStoppedWrapper = (event: any) => {
10170
const data = event.payload
102-
if (data.language === currentLanguage.value) {
103-
isRunning.value = false
104-
output.value += '\n\n🛑 代码执行已被用户停止'
105-
toast.warning('代码执行已停止')
106-
console.log('代码执行已停止')
107-
}
71+
console.log('代码执行已停止')
72+
handleExecutionStopped(currentLanguage.value, data)
10873
}
10974

110-
const handleExecutionTimeout = (event: any) => {
75+
const handleExecutionTimeoutWrapper = (event: any) => {
11176
const data = event.payload
112-
if (data.language === currentLanguage.value) {
113-
isRunning.value = false
114-
output.value += '\n\n⚠️ 代码执行超时(30秒)'
115-
toast.error('代码执行超时')
116-
}
77+
handleExecutionTimeout(currentLanguage.value, data)
11778
}
11879

119-
const handleExecutionError = (event: any) => {
80+
const handleExecutionErrorWrapper = (event: any) => {
12081
const data = event.payload
121-
if (data.language === currentLanguage.value) {
122-
isRunning.value = false
123-
output.value += `\n\n❌ 执行错误: ${ data.error }`
124-
toast.error('代码执行出错')
125-
}
82+
handleExecutionError(currentLanguage.value, data)
12683
}
12784

12885
const initializeEventListeners = async () => {
@@ -140,14 +97,14 @@ export function useEventManager(options: EventManagerOptions)
14097
})
14198

14299
// 监听实时输出事件
143-
unlistenOutputFn = await listen('code-output', handleRealtimeOutput)
100+
unlistenOutputFn = await listen('code-output', handleRealtimeOutputWrapper)
144101

145102
// 监听执行状态事件
146103
unlistenExecutionStartFn = await listen('code-execution-start', handleExecutionStart)
147-
unlistenExecutionCompleteFn = await listen('code-execution-complete', handleExecutionComplete)
148-
unlistenExecutionStoppedFn = await listen('code-execution-stopped', handleExecutionStopped)
149-
unlistenExecutionTimeoutFn = await listen('code-execution-timeout', handleExecutionTimeout)
150-
unlistenExecutionErrorFn = await listen('code-execution-error', handleExecutionError)
104+
unlistenExecutionCompleteFn = await listen('code-execution-complete', handleExecutionCompleteWrapper)
105+
unlistenExecutionStoppedFn = await listen('code-execution-stopped', handleExecutionStoppedWrapper)
106+
unlistenExecutionTimeoutFn = await listen('code-execution-timeout', handleExecutionTimeoutWrapper)
107+
unlistenExecutionErrorFn = await listen('code-execution-error', handleExecutionErrorWrapper)
151108
}
152109

153110
const cleanupEventListeners = () => {

0 commit comments

Comments
 (0)