asdf98 commited on
Commit
f5c97e5
·
verified ·
1 Parent(s): 760eaf3

fix: prevent duplicate ADD captures by making on_navigation the only board action handler

Browse files
Files changed (1) hide show
  1. src-tauri/src/lib.rs +4 -30
src-tauri/src/lib.rs CHANGED
@@ -34,36 +34,10 @@ pub fn run() {
34
  let query = uri.split('?').nth(1).unwrap_or("");
35
  let params: std::collections::HashMap<String, String> = query.split('&').filter_map(|pair| { let (k, v) = pair.split_once('=')?; Some((percent_decode(k), percent_decode(v))) }).collect();
36
  match action.as_str() {
37
- "library" => {
38
- let url = params.get("url").cloned().unwrap_or_default();
39
- if !url.is_empty() {
40
- let source = params.get("source").cloned();
41
- let title = params.get("title").cloned();
42
- tauri::async_runtime::spawn(async move { let _ = crate::library::library_add_item(app, url, source, title).await; });
43
- }
44
- }
45
- "board" => {
46
- let url = params.get("url").cloned().unwrap_or_default();
47
- if !url.is_empty() {
48
- let source = params.get("source").cloned().unwrap_or_default();
49
- let title = params.get("title").cloned().unwrap_or_else(|| "Web Reference".to_string());
50
- let w = params.get("w").and_then(|s| s.parse::<u32>().ok()).unwrap_or(300);
51
- let h = params.get("h").and_then(|s| s.parse::<u32>().ok()).unwrap_or(200);
52
- tauri::async_runtime::spawn(async move {
53
- match crate::library::library_add_item(app.clone(), url.clone(), Some(source.clone()), Some(title.clone())).await {
54
- Ok(item) => {
55
- let _ = crate::board::board_add_image(app.clone(), Some(item.id.clone()), item.data_url.clone(), 120.0, 120.0, 300.0, 200.0);
56
- let _ = app.emit("board://image_added", serde_json::json!({"libraryId": item.id, "dataUrl": item.data_url, "url": item.url, "sourceUrl": item.source_url, "title": item.title, "width": item.width, "height": item.height, "colors": item.colors}));
57
- }
58
- Err(e) => {
59
- // Fallback: still add visible remote image to the canvas.
60
- // This mirrors snip/webclip behavior: user action must produce a board item.
61
- let _ = app.emit("board://image_added", serde_json::json!({"url": url, "dataUrl": url, "sourceUrl": source, "title": title, "width": w, "height": h, "colors": [], "downloadError": e}));
62
- }
63
- }
64
- });
65
- }
66
- }
67
  "vault" => {
68
  let va = params.get("action").cloned().unwrap_or_default();
69
  match va.as_str() {
 
34
  let query = uri.split('?').nth(1).unwrap_or("");
35
  let params: std::collections::HashMap<String, String> = query.split('&').filter_map(|pair| { let (k, v) = pair.split_once('=')?; Some((percent_decode(k), percent_decode(v))) }).collect();
36
  match action.as_str() {
37
+ // IMPORTANT: board/library ADD is intentionally NOT processed here.
38
+ // The hover overlay uses top-level navigation and browser::commands::on_navigation
39
+ // is the single canonical handler. Processing it here too caused duplicate images.
40
+ "board" | "library" => {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  "vault" => {
42
  let va = params.get("action").cloned().unwrap_or_default();
43
  match va.as_str() {