feat(ui): persist log filter preferences in settings file

- Add log_filter_level and log_filter_source to AppConfig
- Remove localStorage usage, use persistent settings instead
- Filter preferences now survive app restarts
This commit is contained in:
Suyunmeng
2025-11-08 10:40:21 +08:00
parent 0be1dee772
commit c79bb5ef45
3 changed files with 13 additions and 5 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

@@ -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>(localStorage.getItem('logFilterLevel') || '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,12 +55,14 @@ const confirmDialogConfig = ref({
onCancel: () => {}
})
watch(filterLevel, newValue => {
localStorage.setItem('logFilterLevel', newValue)
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()
})