asdf98 commited on
Commit
2fc9965
·
verified ·
1 Parent(s): 2f4581f

fix: update history protocol filter to lumaref-action

Browse files
Files changed (1) hide show
  1. src-tauri/src/history.rs +38 -38
src-tauri/src/history.rs CHANGED
@@ -1,38 +1,38 @@
1
- use serde::{Deserialize, Serialize};
2
- use tauri::AppHandle;
3
- use uuid::Uuid;
4
-
5
- #[derive(Debug, Clone, Serialize, Deserialize)]
6
- pub struct HistoryEntry {
7
- pub id: String,
8
- pub tab_id: String,
9
- pub url: String,
10
- pub title: String,
11
- pub visited_at: i64,
12
- }
13
-
14
- const HISTORY_FILE: &str = "browser_history.json";
15
-
16
- pub fn record_visit(app: &AppHandle, tab_id: String, url: String, title: String) -> Result<(), String> {
17
- if url.is_empty() || url == "about:blank" || url.starts_with("muse-action://") { return Ok(()); }
18
- let mut entries: Vec<HistoryEntry> = crate::persistence::load_json(app, HISTORY_FILE).unwrap_or_default();
19
- let now = chrono::Utc::now().timestamp();
20
- if let Some(last) = entries.first() {
21
- if last.url == url && now - last.visited_at < 3 { return Ok(()); }
22
- }
23
- entries.insert(0, HistoryEntry { id: Uuid::new_v4().to_string(), tab_id, url, title, visited_at: now });
24
- entries.truncate(5000);
25
- crate::persistence::save_json(app, HISTORY_FILE, &entries)
26
- }
27
-
28
- #[tauri::command]
29
- pub fn history_list(app: AppHandle, limit: Option<usize>) -> Result<Vec<HistoryEntry>, String> {
30
- let mut entries: Vec<HistoryEntry> = crate::persistence::load_json(&app, HISTORY_FILE).unwrap_or_default();
31
- entries.truncate(limit.unwrap_or(250).min(5000));
32
- Ok(entries)
33
- }
34
-
35
- #[tauri::command]
36
- pub fn history_clear(app: AppHandle) -> Result<(), String> {
37
- crate::persistence::save_json(&app, HISTORY_FILE, &Vec::<HistoryEntry>::new())
38
- }
 
1
+ use serde::{Deserialize, Serialize};
2
+ use tauri::AppHandle;
3
+ use uuid::Uuid;
4
+
5
+ #[derive(Debug, Clone, Serialize, Deserialize)]
6
+ pub struct HistoryEntry {
7
+ pub id: String,
8
+ pub tab_id: String,
9
+ pub url: String,
10
+ pub title: String,
11
+ pub visited_at: i64,
12
+ }
13
+
14
+ const HISTORY_FILE: &str = "browser_history.json";
15
+
16
+ pub fn record_visit(app: &AppHandle, tab_id: String, url: String, title: String) -> Result<(), String> {
17
+ if url.is_empty() || url == "about:blank" || url.starts_with("lumaref-action://") { return Ok(()); }
18
+ let mut entries: Vec<HistoryEntry> = crate::persistence::load_json(app, HISTORY_FILE).unwrap_or_default();
19
+ let now = chrono::Utc::now().timestamp();
20
+ if let Some(last) = entries.first() {
21
+ if last.url == url && now - last.visited_at < 3 { return Ok(()); }
22
+ }
23
+ entries.insert(0, HistoryEntry { id: Uuid::new_v4().to_string(), tab_id, url, title, visited_at: now });
24
+ entries.truncate(5000);
25
+ crate::persistence::save_json(app, HISTORY_FILE, &entries)
26
+ }
27
+
28
+ #[tauri::command]
29
+ pub fn history_list(app: AppHandle, limit: Option<usize>) -> Result<Vec<HistoryEntry>, String> {
30
+ let mut entries: Vec<HistoryEntry> = crate::persistence::load_json(&app, HISTORY_FILE).unwrap_or_default();
31
+ entries.truncate(limit.unwrap_or(250).min(5000));
32
+ Ok(entries)
33
+ }
34
+
35
+ #[tauri::command]
36
+ pub fn history_clear(app: AppHandle) -> Result<(), String> {
37
+ crate::persistence::save_json(&app, HISTORY_FILE, &Vec::<HistoryEntry>::new())
38
+ }