Skip to content

Commit a3a6ef0

Browse files
committed
feat(ui): persist log filter preferences in settings file
This commit improves the log viewer by persisting user filter preferences across page navigation and application restarts. Changes: - Add log_filter_level and log_filter_source fields to AppConfig - Store filter preferences in settings.json instead of localStorage - Ensure filter preferences survive app restarts and page switches - Fix clippy warning: use &Path instead of &PathBuf in normalize_path The filter level and source selections are now saved to the persistent settings file, providing a more reliable storage mechanism for Tauri applications.
1 parent e4ab218 commit a3a6ef0

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src-tauri/src/conf/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct AppConfig {
99
pub open_links_in_browser: Option<bool>,
1010
pub admin_password: Option<String>,
1111
pub show_window_on_startup: Option<bool>,
12+
pub log_filter_level: Option<String>,
13+
pub log_filter_source: Option<String>,
1214
}
1315

1416
impl AppConfig {
@@ -21,6 +23,8 @@ impl AppConfig {
2123
open_links_in_browser: Some(false),
2224
admin_password: None,
2325
show_window_on_startup: Some(true),
26+
log_filter_level: Some("all".to_string()),
27+
log_filter_source: Some("openlist".to_string()),
2428
}
2529
}
2630
}

src-tauri/src/utils/path.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
use std::path::PathBuf;
1+
use std::path::{Path, PathBuf};
22
use std::{env, fs};
33

44
pub static APP_ID: &str = "io.github.openlistteam.openlist.desktop";
55

66
// Normalize path without Windows long path prefix (\\?\)
77
// The \\?\ prefix breaks compatibility with some applications like SQLite
8-
fn normalize_path(path: &PathBuf) -> Result<PathBuf, String> {
8+
fn normalize_path(path: &Path) -> Result<PathBuf, String> {
99
#[cfg(target_os = "windows")]
1010
{
1111
// On Windows, use canonicalize but strip the \\?\ prefix if present
1212
let canonical = path
1313
.canonicalize()
1414
.map_err(|e| format!("Failed to canonicalize path: {e}"))?;
15-
15+
1616
let path_str = canonical.to_string_lossy();
1717
if let Some(stripped) = path_str.strip_prefix(r"\\?\") {
1818
Ok(PathBuf::from(stripped))
1919
} else {
2020
Ok(canonical)
2121
}
2222
}
23-
23+
2424
#[cfg(not(target_os = "windows"))]
2525
{
2626
path.canonicalize()

src/types/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ interface AppConfig {
5252
open_links_in_browser?: boolean
5353
admin_password?: string
5454
show_window_on_startup?: boolean
55+
log_filter_level?: string
56+
log_filter_source?: string
5557
}
5658

5759
interface MergedSettings {

src/views/LogView.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const logContainer = ref<HTMLElement>()
3333
const searchInputRef = ref<HTMLInputElement>()
3434
const autoScroll = ref(true)
3535
const isPaused = ref(false)
36-
const filterLevel = ref<string>('all')
37-
const filterSource = ref<string>(localStorage.getItem('logFilterSource') || 'openlist')
36+
const filterLevel = ref<string>(appStore.settings.app.log_filter_level || 'all')
37+
const filterSource = ref<string>(appStore.settings.app.log_filter_source || 'openlist')
3838
const searchQuery = ref('')
3939
const selectedEntries = ref<Set<number>>(new Set())
4040
const showFilters = ref(true)
@@ -55,8 +55,14 @@ const confirmDialogConfig = ref({
5555
onCancel: () => {}
5656
})
5757
58+
watch(filterLevel, async newValue => {
59+
appStore.settings.app.log_filter_level = newValue
60+
await appStore.saveSettings()
61+
})
62+
5863
watch(filterSource, async newValue => {
59-
localStorage.setItem('logFilterSource', newValue)
64+
appStore.settings.app.log_filter_source = newValue
65+
await appStore.saveSettings()
6066
await appStore.loadLogs((newValue !== 'gin' ? newValue : 'openlist') as filterSourceType)
6167
await scrollToBottom()
6268
})

0 commit comments

Comments
 (0)