Skip to content

Commit

Permalink
feat: 支持命令行参数启动
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 19, 2023
1 parent f541a55 commit e2230d8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use selection::get_selection_text;
use shortcut::register_shortcut;
use tauri::api::notification::Notification;
use tauri::AppHandle;
use tauri::Manager;
use tauri::SystemTrayEvent;
use trayicon::*;
use window::*;

// 全局AppHandle
pub static APP: OnceCell<AppHandle> = OnceCell::new();
Expand All @@ -32,15 +32,18 @@ fn main() {
tauri::Builder::default()
// 单例运行
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
println!("{}, {argv:?}, {cwd}", app.package_info().name);
Notification::new(&app.config().tauri.bundle.identifier)
.title("程序已运行")
.body("程序已经在运行 请勿重复启动!")
.icon("pot")
.show()
.unwrap();
app.emit_all("single-instance", Payload { args: argv, cwd })
.unwrap();
if argv.contains(&"translate".to_string()) {
translate_window();
} else if argv.contains(&"persistent".to_string()) {
persistent_window();
} else {
Notification::new(&app.config().tauri.bundle.identifier)
.title("程序已经在运行 请勿重复启动!")
.body(cwd)
.icon("pot")
.show()
.unwrap();
}
}))
.setup(|app| {
// 初始化AppHandel
Expand Down

0 comments on commit e2230d8

Please sign in to comment.