Skip to content

Commit 978f333

Browse files
authored
Merge pull request #5 from qianmoQ/dev-25.0.0
feat: 优化菜单工具
2 parents dd6265c + 894a0b7 commit 978f333

File tree

15 files changed

+195
-23
lines changed

15 files changed

+195
-23
lines changed

src-tauri/Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ tokio = "1.47.1"
2323
uuid = { version = "1.17.0", features = ["v4"] }
2424
tempfile = "3.0"
2525
chrono = { version = "0.4", features = ["serde"] }
26+
log = "0.4"
27+
fern = "0.7.1"

src-tauri/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
22
// 设置构建时间
3-
let build_time = chrono::Utc::now()
4-
.format("%Y-%m-%d %H:%M:%S UTC")
5-
.to_string();
3+
let utc_time = chrono::Utc::now();
4+
let beijing_time = utc_time + chrono::Duration::hours(8);
5+
let build_time = beijing_time.format("%Y年%m月%d日 %H:%M:%S").to_string();
66
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
77

88
// 重新构建触发条件

src-tauri/icons/128x128.png

-2.76 KB
Loading

src-tauri/icons/32x32.png

-40 Bytes
Loading

src-tauri/icons/icon.icns

-103 KB
Binary file not shown.

src-tauri/icons/icon.ico

-5.76 KB
Binary file not shown.

src-tauri/icons/icon.png

-47.5 KB
Loading

src-tauri/src/logger.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use chrono::Local;
2+
use log::LevelFilter;
3+
use std::fs;
4+
use tauri::{AppHandle, Manager};
5+
6+
pub fn setup_logger(app: &AppHandle) -> Result<(), fern::InitError> {
7+
// 获取应用数据目录
8+
let app_data_dir = app
9+
.path()
10+
.app_data_dir()
11+
.expect("Failed to get app data dir");
12+
13+
// 创建日志目录
14+
let log_dir = app_data_dir.join("logs");
15+
fs::create_dir_all(&log_dir).expect("Failed to create log directory");
16+
17+
// 生成当天的日志文件名
18+
let today = Local::now().format("%Y-%m-%d").to_string();
19+
let log_file = log_dir.join(format!("codeforge-{}.log", today));
20+
21+
// 配置日志
22+
fern::Dispatch::new()
23+
.format(|out, message, record| {
24+
out.finish(format_args!(
25+
"[{}] [{}] [{}:{}] {}",
26+
Local::now().format("%Y-%m-%d %H:%M:%S%.3f"),
27+
record.level(),
28+
record.file().unwrap_or("unknown"),
29+
record.line().unwrap_or(0),
30+
message
31+
))
32+
})
33+
.level(LevelFilter::Debug) // 设置日志级别
34+
.level_for("hyper", LevelFilter::Warn) // 减少第三方库的日志
35+
.level_for("reqwest", LevelFilter::Warn)
36+
.chain(std::io::stdout()) // 同时输出到控制台
37+
.chain(fern::log_file(&log_file)?) // 输出到文件
38+
.apply()?;
39+
40+
log::info!("日志系统初始化完成");
41+
log::info!("日志文件: {:?}", log_file);
42+
43+
Ok(())
44+
}

src-tauri/src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
windows_subsystem = "windows"
44
)]
55

6+
mod logger;
67
mod plugins;
78
mod setup;
89

910
use crate::setup::app::get_app_info;
10-
use chrono::Utc;
11+
use log::{debug, info};
1112
use plugins::{CodeExecutionRequest, ExecutionResult, LanguageInfo, PluginManager};
1213
use std::fs;
1314
use std::process::{Command, Stdio};
@@ -55,8 +56,10 @@ async fn execute_code(
5556
// 尝试不同的命令
5657
for cmd in plugin.get_commands() {
5758
let args = plugin.get_execute_args(file_path.to_str().unwrap());
58-
59-
println!("Trying command: {} with args: {:?}", cmd, args);
59+
debug!(
60+
"执行插件代码 -> 执行命令: {} 携带参数: {:?} 语言: {}",
61+
cmd, args, request.language
62+
);
6063

6164
let output = Command::new(cmd)
6265
.args(&args)
@@ -148,8 +151,7 @@ async fn get_info(
148151

149152
// 尝试不同的命令
150153
for cmd in plugin.get_commands() {
151-
println!("Trying command: {} for language: {}", cmd, language);
152-
154+
debug!("获取插件信息 -> 执行命令: {} 语言: {}", cmd, language);
153155
let version_output = Command::new(cmd).args(plugin.get_version_args()).output();
154156

155157
if let Ok(version_out) = version_output {
@@ -216,14 +218,18 @@ async fn clear_execution_history(history: State<'_, ExecutionHistory>) -> Result
216218
}
217219

218220
fn main() {
219-
let build_time = Utc::now().format("%Y-%m-%d %H:%M:%S UTC").to_string();
220-
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
221-
222221
tauri::Builder::default()
223222
.plugin(tauri_plugin_shell::init())
224223
.manage(ExecutionHistory::default())
225224
.manage(PluginManagerState::new(PluginManager::new()))
226225
.setup(|app| {
226+
// 初始化日志系统
227+
if let Err(e) = logger::setup_logger(app.handle()) {
228+
eprintln!("Failed to setup logger: {}", e);
229+
}
230+
info!("CodeForge 应用启动");
231+
info!("应用版本: {}", env!("CARGO_PKG_VERSION"));
232+
227233
let menu = setup::menu::create_menu(app.handle())?;
228234
app.set_menu(menu)?;
229235
setup::menu::setup_menu_handler(app.handle());

0 commit comments

Comments
 (0)