feat(工具集) zip工具新增tip通知和自动补全zip后缀
This commit is contained in:
1 parent
9dc72c1ac0
commit
2405a1746d
5 files changed
+41
-1
No files matched your search
@@ -2,6 +2,7 @@
|
||||
name = "cutpic"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = ["gitea"]
|
||||
|
||||
[dependencies]
|
||||
image = "0.25"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "dexcel"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
publish = ["gitea"]
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "ptm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = ["gitea"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.6", features = ["derive"] }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "zip"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
publish = ["gitea"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
@@ -10,3 +11,4 @@ walkdir = "2.5"
|
||||
arboard = "3.4"
|
||||
clipboard-win = "5.4"
|
||||
winapi = { version = "0.3", features = ["winuser"] }
|
||||
notify-rust = "4"
|
||||
+36
-1
@@ -25,6 +25,10 @@ struct Args {
|
||||
/// 📋 复制 zip 文件路径到剪切板
|
||||
#[arg(short = 'v', long = "clipboard")]
|
||||
clipboard: bool,
|
||||
|
||||
/// 💬 弹出 Windows 通知提示打包完成
|
||||
#[arg(short = 't', long = "tip", value_name = "MESSAGE", num_args = 0..=1, default_missing_value = "")]
|
||||
tip: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -40,7 +44,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// 生成输出文件名
|
||||
let output_path = if let Some(name) = &args.name {
|
||||
name.clone()
|
||||
let name_str = name.to_string_lossy().to_string();
|
||||
if name_str.to_lowercase().ends_with(".zip") {
|
||||
name.clone()
|
||||
} else {
|
||||
PathBuf::from(format!("{}.zip", name_str))
|
||||
}
|
||||
} else {
|
||||
// 根据第一个源文件/文件夹生成默认名称
|
||||
let first_source = &args.sources[0];
|
||||
@@ -170,6 +179,32 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果需要弹出 Windows 通知
|
||||
if let Some(tip_message) = &args.tip {
|
||||
use notify_rust::Notification;
|
||||
|
||||
let title = "打包完成";
|
||||
let mut body = if tip_message.is_empty() {
|
||||
let file_name = output_path.file_name().unwrap_or_default().to_string_lossy().to_string();
|
||||
format!("{} 已经打包好了", file_name)
|
||||
} else {
|
||||
tip_message.clone()
|
||||
};
|
||||
|
||||
if args.clipboard {
|
||||
body.push_str("\n已经复制到剪贴板");
|
||||
}
|
||||
|
||||
match Notification::new()
|
||||
.summary(title)
|
||||
.body(&body)
|
||||
.show()
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => eprintln!("⚠️ 发送通知失败: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user