Skip to content

Commit a3d182c

Browse files
committed
feat: improve deep link handling in Tauri application
- Enhanced the deep link management by introducing a new `show_window` function to focus the main window and emit deep link events. - Simplified the deep link registration process in the Tauri setup, improving code clarity and maintainability. - Removed redundant logging and streamlined the handling of deep link URLs.
1 parent 25bac01 commit a3d182c

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src-tauri/src/lib.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,15 @@ use filesystem::{
3434
};
3535
use mcp::{add_mcp_server, delete_mcp_server, read_mcp_servers};
3636
use state::CodexState;
37-
use tauri::Manager;
37+
use tauri::{AppHandle, Emitter, Manager};
3838

3939
#[cfg_attr(mobile, tauri::mobile_entry_point)]
4040
pub fn run() {
4141
let mut builder = tauri::Builder::default();
4242
#[cfg(desktop)]
4343
{
4444
builder = builder.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
45-
println!("a new app instance was opened with {argv:?} and the deep link event was already triggered");
46-
47-
if let Some(deep_link_url) = argv.iter().find(|arg| arg.starts_with("codexia://")) {
48-
if let Err(err) = app.emit_all("deep-link-received", deep_link_url.clone()) {
49-
eprintln!("Failed to emit deep link event: {err}");
50-
}
51-
}
45+
show_window(app, argv);
5246
}));
5347
}
5448

@@ -121,10 +115,10 @@ pub fn run() {
121115
add_or_update_model_provider,
122116
ensure_default_providers,
123117
])
124-
.setup(|app| {
118+
.setup(|_app| {
125119
#[cfg(any(windows, target_os = "linux"))]
126120
{
127-
if let Err(err) = app.deep_link().register_all() {
121+
if let Err(err) = _app.deep_link().register_all() {
128122
eprintln!("Failed to register deep link schemes: {err}");
129123
}
130124
}
@@ -137,3 +131,22 @@ pub fn run() {
137131
.run(tauri::generate_context!())
138132
.expect("error while running tauri application");
139133
}
134+
135+
fn show_window(app: &AppHandle, args: Vec<String>) {
136+
let windows = app.webview_windows();
137+
let main_window = windows.values().next().expect("Sorry, no window found");
138+
139+
main_window
140+
.set_focus()
141+
.expect("Can't Bring Window to Focus");
142+
143+
dbg!(args.clone());
144+
if args.len() > 1 {
145+
let url = args[1].clone();
146+
147+
dbg!(url.clone());
148+
if url.starts_with("codexia://") {
149+
let _ = main_window.emit("deep-link-received", url);
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)