diff --git a/README.md b/README.md index 5585b22..5f3b369 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,10 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发 ## 安装 **系统要求:** + - Node.js 18+ - Rust 1.8+ +- Tauri 2.x **构建步骤:** diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0f63556..993e9e4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -13,6 +13,7 @@ dependencies = [ "log", "regex", "reqwest 0.11.27", + "rfd", "serde", "serde_json", "tauri", @@ -91,6 +92,8 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6cbdf310d77fd3aaee6ea2093db7011dc2d35d2eb3481e5607f1f8d942ed99df" dependencies = [ + "async-fs", + "async-net", "enumflags2", "futures-channel", "futures-util", @@ -144,6 +147,17 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f7e37c0ed80b2a977691c47dae8625cfb21e205827106c64f7c588766b2e50" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + [[package]] name = "async-io" version = "2.5.0" @@ -173,6 +187,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-net" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + [[package]] name = "async-process" version = "2.4.0" @@ -2912,6 +2937,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "potential_utf" version = "0.1.2" @@ -3322,7 +3353,9 @@ dependencies = [ "objc2-app-kit", "objc2-core-foundation", "objc2-foundation 0.3.1", + "pollster", "raw-window-handle", + "urlencoding", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -4767,6 +4800,12 @@ dependencies = [ "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "urlpattern" version = "0.3.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index bf766e0..cab5fce 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -30,3 +30,4 @@ dirs = "6.0.0" regex = "1.11.1" reqwest = { version = "0.11", features = ["json", "stream"] } futures-util = "0.3" +rfd = "0.15" diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 5f2759d..e4b54db 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -16,8 +16,10 @@ pub struct EditorConfig { pub tab_size: Option, // tab 缩进, 空格数,默认为 2 pub theme: Option, // 编辑器主题 pub font_size: Option, // 编辑器字体大小 + pub font_family: Option, // 编辑器字体 pub show_line_numbers: Option, // 是否显示行号 pub show_function_help: Option, // 是否显示函数帮助 + pub space_dot_omission: Option, // 是否显示空格省略 } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -43,8 +45,10 @@ impl Default for AppConfig { tab_size: Some(2), theme: Some("githubLight".to_string()), font_size: Some(14), + font_family: Some("monospace".to_string()), show_line_numbers: Some(true), show_function_help: Some(false), + space_dot_omission: Some(false), }), } } @@ -101,8 +105,10 @@ impl ConfigManager { tab_size: Some(2), theme: Some("githubLight".to_string()), font_size: Some(14), + font_family: Some("monospace".to_string()), show_line_numbers: Some(true), show_function_help: Some(false), + space_dot_omission: Some(false), }); println!("读取配置 -> 添加默认 editor 配置"); } @@ -207,8 +213,10 @@ impl ConfigManager { tab_size: Some(2), theme: Some("githubLight".to_string()), font_size: Some(14), + font_family: Some("monospace".to_string()), show_line_numbers: Some(true), show_function_help: Some(false), + space_dot_omission: Some(false), }), } } diff --git a/src-tauri/src/font.rs b/src-tauri/src/font.rs new file mode 100644 index 0000000..0cc4b41 --- /dev/null +++ b/src-tauri/src/font.rs @@ -0,0 +1,30 @@ +use log::info; +use tauri::AppHandle; + +#[tauri::command] +pub async fn open_font_picker(_app_handle: AppHandle) -> Result, String> { + info!("编辑器设置 -> 打开字体选择器"); + + let file_handle = rfd::FileDialog::new() + .add_filter("字体文件", &["ttf", "otf", "woff", "woff2"]) + .set_title("选择字体文件") + .pick_file(); + + match file_handle { + Some(path) => { + let font_name = path + .file_stem() // 只取不带扩展名的文件名 + .ok_or_else(|| "无法获取字体名".to_string())? + .to_str() + .ok_or_else(|| "字体名包含无效字符".to_string())? + .to_string(); + + info!("编辑器设置 -> 用户选择了字体: {}", font_name); + Ok(Some(font_name)) + } + None => { + info!("编辑器设置 -> 用户取消了字体选择"); + Ok(None) + } + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ef8ada0..10bfbe5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -6,6 +6,7 @@ mod config; mod example; mod execution; +mod font; mod logger; mod plugin; mod plugins; @@ -24,6 +25,7 @@ use crate::utils::logger::{ }; use config::{get_app_config, get_config_path, init_config, update_app_config}; use example::load_example; +use font::open_font_picker; use log::info; use plugins::PluginManager; use update::{check_for_updates, start_update}; @@ -79,6 +81,7 @@ fn main() { check_for_updates, start_update, load_example, + open_font_picker ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/components/setting/Editor.vue b/src/components/setting/Editor.vue index fc59740..ea15370 100644 --- a/src/components/setting/Editor.vue +++ b/src/components/setting/Editor.vue @@ -12,10 +12,21 @@ + + + + @@ -27,12 +38,15 @@