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.
This commit is contained in:
Suyunmeng
2025-11-08 11:19:18 +08:00
parent e4ab2184eb
commit a3a6ef03a5
4 changed files with 19 additions and 7 deletions

View File

@@ -9,6 +9,8 @@ pub struct AppConfig {
pub open_links_in_browser: Option<bool>,
pub admin_password: Option<String>,
pub show_window_on_startup: Option<bool>,
pub log_filter_level: Option<String>,
pub log_filter_source: Option<String>,
}
impl AppConfig {
@@ -21,6 +23,8 @@ impl AppConfig {
open_links_in_browser: Some(false),
admin_password: None,
show_window_on_startup: Some(true),
log_filter_level: Some("all".to_string()),
log_filter_source: Some("openlist".to_string()),
}
}
}

View File

@@ -1,11 +1,11 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::{env, fs};
pub static APP_ID: &str = "io.github.openlistteam.openlist.desktop";
// Normalize path without Windows long path prefix (\\?\)
// The \\?\ prefix breaks compatibility with some applications like SQLite
fn normalize_path(path: &PathBuf) -> Result<PathBuf, String> {
fn normalize_path(path: &Path) -> Result<PathBuf, String> {
#[cfg(target_os = "windows")]
{
// On Windows, use canonicalize but strip the \\?\ prefix if present

View File

@@ -52,6 +52,8 @@ interface AppConfig {
open_links_in_browser?: boolean
admin_password?: string
show_window_on_startup?: boolean
log_filter_level?: string
log_filter_source?: string
}
interface MergedSettings {

View File

@@ -33,8 +33,8 @@ const logContainer = ref<HTMLElement>()
const searchInputRef = ref<HTMLInputElement>()
const autoScroll = ref(true)
const isPaused = ref(false)
const filterLevel = ref<string>('all')
const filterSource = ref<string>(localStorage.getItem('logFilterSource') || 'openlist')
const filterLevel = ref<string>(appStore.settings.app.log_filter_level || 'all')
const filterSource = ref<string>(appStore.settings.app.log_filter_source || 'openlist')
const searchQuery = ref('')
const selectedEntries = ref<Set<number>>(new Set())
const showFilters = ref(true)
@@ -55,8 +55,14 @@ const confirmDialogConfig = ref({
onCancel: () => {}
})
watch(filterLevel, async newValue => {
appStore.settings.app.log_filter_level = newValue
await appStore.saveSettings()
})
watch(filterSource, async newValue => {
localStorage.setItem('logFilterSource', newValue)
appStore.settings.app.log_filter_source = newValue
await appStore.saveSettings()
await appStore.loadLogs((newValue !== 'gin' ? newValue : 'openlist') as filterSourceType)
await scrollToBottom()
})