asdf98 commited on
Commit
eceaf26
·
verified ·
1 Parent(s): 6d1f25f

fix: remove Rust warnings in browser commands and record browser visits

Browse files
Files changed (1) hide show
  1. src-tauri/src/browser/commands.rs +5 -11
src-tauri/src/browser/commands.rs CHANGED
@@ -2,7 +2,7 @@ use std::collections::HashMap;
2
  use tauri::webview::{PageLoadEvent, WebviewBuilder};
3
  use tauri::{AppHandle, LogicalPosition, LogicalSize, Manager, Url, WebviewUrl};
4
 
5
- use super::layout::{bounds, hide_tab, resize_active, show_tab};
6
  use super::navigation::{navigation_blocked, resolve_url};
7
  use super::tab_manager::*;
8
  use crate::adblock::engine::AdBlockState;
@@ -51,18 +51,10 @@ pub async fn browser_set_visible(app: AppHandle, visible: bool, layout: Viewport
51
  Ok(())
52
  }
53
 
54
- /// Hard hide every child browser webview. Use this when the browser drawer closes.
55
- /// `browser_set_visible(false)` only hides the active tab; this function parks all tab webviews.
56
  #[tauri::command]
57
  pub fn browser_hide_all(app: AppHandle) -> Result<(), String> {
58
- let ids = {
59
- let state = app.state::<AppState>();
60
- let tabs = state.tabs.lock().map_err(|_| "lock")?;
61
- tabs.order.clone()
62
- };
63
- for id in ids {
64
- let _ = hide_tab(&app, &id);
65
- }
66
  Ok(())
67
  }
68
 
@@ -153,6 +145,8 @@ pub(crate) async fn create_tab_inner(app: &AppHandle, url: &str, _layout: &Viewp
153
  if !css.is_empty() { let escaped = css.replace('\\', "\\\\").replace('`', "\\`"); let _ = webview.eval(&format!("(function(){{const s=document.createElement('style');s.id='__muse_shield';s.textContent=`{escaped}`;document.head.appendChild(s)}})();")); }
154
  let scriptlet_js = adblock_state.get_injected_script(&url); if !scriptlet_js.is_empty() { let _ = webview.eval(&format!("try{{{scriptlet_js}}}catch(e){{}}")); }
155
  let _ = webview.eval("window.__muse_report_favicon && window.__muse_report_favicon()");
 
 
156
  }
157
  })
158
  .on_document_title_changed(move |_wv, title| { update_tab_field(&app_for_title, &id_for_title, |t| { if !title.trim().is_empty() { t.title = title.clone(); } }); })
 
2
  use tauri::webview::{PageLoadEvent, WebviewBuilder};
3
  use tauri::{AppHandle, LogicalPosition, LogicalSize, Manager, Url, WebviewUrl};
4
 
5
+ use super::layout::{hide_tab, resize_active, show_tab};
6
  use super::navigation::{navigation_blocked, resolve_url};
7
  use super::tab_manager::*;
8
  use crate::adblock::engine::AdBlockState;
 
51
  Ok(())
52
  }
53
 
 
 
54
  #[tauri::command]
55
  pub fn browser_hide_all(app: AppHandle) -> Result<(), String> {
56
+ let ids = { let state = app.state::<AppState>(); let tabs = state.tabs.lock().map_err(|_| "lock")?; tabs.order.clone() };
57
+ for id in ids { let _ = hide_tab(&app, &id); }
 
 
 
 
 
 
58
  Ok(())
59
  }
60
 
 
145
  if !css.is_empty() { let escaped = css.replace('\\', "\\\\").replace('`', "\\`"); let _ = webview.eval(&format!("(function(){{const s=document.createElement('style');s.id='__muse_shield';s.textContent=`{escaped}`;document.head.appendChild(s)}})();")); }
146
  let scriptlet_js = adblock_state.get_injected_script(&url); if !scriptlet_js.is_empty() { let _ = webview.eval(&format!("try{{{scriptlet_js}}}catch(e){{}}")); }
147
  let _ = webview.eval("window.__muse_report_favicon && window.__muse_report_favicon()");
148
+ let title = { let state = app_for_load.state::<AppState>(); state.tabs.lock().ok().and_then(|tabs| tabs.tabs.get(&id_for_load).map(|t| t.title.clone())).unwrap_or_default() };
149
+ let _ = crate::history::record_visit(&app_for_load, id_for_load.clone(), url.clone(), title);
150
  }
151
  })
152
  .on_document_title_changed(move |_wv, title| { update_tab_field(&app_for_title, &id_for_title, |t| { if !title.trim().is_empty() { t.title = title.clone(); } }); })