Skip to content

Commit aa001eb

Browse files
authored
Merge pull request #39 from qianmoQ/dev-25.0.2
feat (core): 增加多个 UI 组件
2 parents 36156cb + 137bb41 commit aa001eb

12 files changed

Lines changed: 914 additions & 80 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
3838

3939
**系统要求:**
4040
- Node.js 18+
41-
- Rust 1.70+
41+
- Rust 1.8+
4242

4343
**构建步骤:**
4444

src-tauri/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct EditorConfig {
1515
pub indent_with_tab: Option<bool>, // 是否使用 tab 缩进
1616
pub tab_size: Option<u32>, // tab 缩进, 空格数,默认为 2
1717
pub theme: Option<String>, // 编辑器主题
18+
pub font_size: Option<u32>, // 编辑器字体大小
1819
}
1920

2021
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -39,6 +40,7 @@ impl Default for AppConfig {
3940
indent_with_tab: Some(true),
4041
tab_size: Some(2),
4142
theme: Some("githubLight".to_string()),
43+
font_size: Some(14),
4244
}),
4345
}
4446
}
@@ -94,6 +96,7 @@ impl ConfigManager {
9496
indent_with_tab: Some(true),
9597
tab_size: Some(2),
9698
theme: Some("githubLight".to_string()),
99+
font_size: Some(14),
97100
});
98101
println!("读取配置 -> 添加默认 editor 配置");
99102
}
@@ -197,6 +200,7 @@ impl ConfigManager {
197200
indent_with_tab: Some(true),
198201
tab_size: Some(2),
199202
theme: Some("githubLight".to_string()),
203+
font_size: Some(14),
200204
}),
201205
}
202206
}

src-tauri/src/setup/menus/app.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use log::info;
2+
#[allow(unused_imports)]
3+
use tauri::Manager;
24
use tauri::{
35
AppHandle, Emitter,
46
menu::{MenuItemBuilder, Submenu, SubmenuBuilder},
@@ -16,6 +18,18 @@ pub fn create_app_submenu(app: &AppHandle) -> tauri::Result<Submenu<tauri::Wry>>
1618
.accelerator("CmdOrCtrl+,")
1719
.build(app)?;
1820

21+
#[cfg(target_os = "macos")]
22+
let hide_item = MenuItemBuilder::new("隐藏 CodeForge")
23+
.id("hide")
24+
.accelerator("CmdOrCtrl+H")
25+
.build(app)?;
26+
27+
#[cfg(not(target_os = "macos"))]
28+
let hide_item = MenuItemBuilder::new("最小化 CodeForge")
29+
.id("hide")
30+
.accelerator("CmdOrCtrl+M")
31+
.build(app)?;
32+
1933
let restart_item = MenuItemBuilder::new("重启 CodeForge")
2034
.id("restart")
2135
.accelerator("CmdOrCtrl+R")
@@ -33,6 +47,8 @@ pub fn create_app_submenu(app: &AppHandle) -> tauri::Result<Submenu<tauri::Wry>>
3347
.separator()
3448
.item(&settings_item)
3549
.separator()
50+
.item(&hide_item)
51+
.separator()
3652
.item(&restart_item)
3753
.item(&quit_item)
3854
.build()?;
@@ -51,6 +67,28 @@ pub fn handle_app_menu_event(app: &AppHandle, event_id: &str) {
5167
"settings" => {
5268
let _event = app.emit("show-settings", ());
5369
}
70+
"hide" => {
71+
#[cfg(target_os = "macos")]
72+
{
73+
info!("隐藏应用 CodeForge");
74+
let _ = app.hide();
75+
}
76+
77+
#[cfg(not(target_os = "macos"))]
78+
{
79+
info!("最小化应用 CodeForge");
80+
// 获取主窗口并最小化
81+
if let Some(window) = app.get_webview_window("main") {
82+
let _ = window.minimize();
83+
} else {
84+
// 如果找不到 main 窗口,尝试获取第一个可用窗口
85+
let windows = app.webview_windows();
86+
if let Some((_, window)) = windows.iter().next() {
87+
let _ = window.minimize();
88+
}
89+
}
90+
}
91+
}
5492
"restart" => {
5593
info!("CodeForge 应用重启");
5694
app.restart();

src/components/AppHeader.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="flex items-center space-x-3">
44
<Select v-model="selectedLanguage"
55
class="w-48"
6+
searchable
67
:options="supportedLanguages as any"
78
:disabled="isRunning"
89
placeholder="选择语言"

src/components/CodeEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="flex bg-white h-full relative">
33
<Codemirror v-if="isReady"
4-
style="width: 100%; height: 100%"
4+
:style="{ width: '100%', height: '100%', fontSize: editorConfig?.font_size ? `${editorConfig.font_size}px` : undefined }"
55
:model-value="modelValue"
66
:extensions="extensions"
77
:indent-with-tab="editorConfig?.indent_with_tab"

src/components/setting/Editor.vue

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
是否使用 tab 缩进
66
</label>
77
<div class="flex gap-2">
8-
<input v-model="editorConfig.indent_with_tab"
9-
type="checkbox"
10-
class="px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
8+
<Switch v-model="editorConfig.indent_with_tab"/>
119
</div>
1210
</div>
1311

@@ -16,12 +14,16 @@
1614
缩进空格数
1715
</label>
1816
<div class="flex gap-2">
19-
<input v-model.number="editorConfig.tab_size"
20-
type="number"
21-
min="1"
22-
max="8"
23-
placeholder="缩进空格数,默认 2"
24-
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
17+
<Number v-model="editorConfig.tab_size" :min="1" :max="8" placeholder="缩进空格数"/>
18+
</div>
19+
</div>
20+
21+
<div>
22+
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
23+
字体大小
24+
</label>
25+
<div class="flex gap-2">
26+
<Number v-model="editorConfig.font_size" :min="1" :max="30" placeholder="字体大小"/>
2527
</div>
2628
</div>
2729

@@ -38,8 +40,10 @@
3840

3941
<script setup lang="ts">
4042
import { onMounted } from 'vue'
41-
import Select from '../../ui/Select.vue'
4243
import { useEditorConfig } from '../../composables/useEditorConfig'
44+
import Select from '../../ui/Select.vue'
45+
import Switch from '../../ui/Switch.vue'
46+
import Number from '../../ui/Number.vue'
4347
4448
const emit = defineEmits<{
4549
'settings-changed': [config: any]

src/components/setting/Language.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@
118118
超时时间(秒)
119119
</label>
120120
<div class="flex gap-2">
121-
<input v-model="pluginConfig.timeout"
122-
type="number"
123-
placeholder="超时时间(秒),默认 30 秒"
124-
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-transparent text-sm"/>
121+
<Number v-model="pluginConfig.timeout" class="w-1/5" placeholder="超时时间(秒),默认 30 秒"/>
125122
</div>
126123
</div>
127124
</template>
@@ -137,6 +134,7 @@ import { ContainerIcon, FileIcon, Folder, PickaxeIcon, Settings2 } from 'lucide-
137134
import { Codemirror } from 'vue-codemirror'
138135
import Button from '../../ui/Button.vue'
139136
import Tabs from '../../ui/Tabs.vue'
137+
import Number from '../../ui/Number.vue'
140138
import { usePluginConfig } from '../../composables/usePluginConfig'
141139
import type PluginConfig from '../../types/plugin'
142140
import { useCodeMirrorEditor } from '../../composables/useCodeMirrorEditor.ts'

src/composables/useCodeMirrorEditor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interface EditorConfig
6666
theme?: string
6767
indent_with_tab?: boolean
6868
tab_size?: number
69+
font_size?: number
6970
}
7071

7172
interface Props
@@ -221,7 +222,8 @@ export function useCodeMirrorEditor(props: Props)
221222
editorConfig.value = {
222223
theme: 'githubLight',
223224
indent_with_tab: true,
224-
tab_size: 2
225+
tab_size: 2,
226+
font_size: 14
225227
}
226228
await updateExtensions()
227229
}
@@ -234,7 +236,8 @@ export function useCodeMirrorEditor(props: Props)
234236
editorConfig.value = {
235237
theme: 'githubLight',
236238
indent_with_tab: true,
237-
tab_size: 2
239+
tab_size: 2,
240+
font_size: 14
238241
}
239242
await updateExtensions()
240243
}

src/composables/useEditorConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface EditorConfig
88
tab_size?: number
99
theme?: string
1010
indent_with_tab?: boolean
11+
font_size?: number
1112
}
1213

1314
interface ThemeOption
@@ -149,7 +150,8 @@ export function useEditorConfig(emit?: any)
149150
editorConfig.value = {
150151
indent_with_tab: true,
151152
tab_size: 2,
152-
theme: 'githubLight'
153+
theme: 'githubLight',
154+
font_size: 14
153155
}
154156
}
155157

0 commit comments

Comments
 (0)