mirror of
https://github.com/OpenListTeam/OpenList-Desktop.git
synced 2025-11-25 03:14:56 +08:00
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:
@@ -9,6 +9,8 @@ pub struct AppConfig {
|
|||||||
pub open_links_in_browser: Option<bool>,
|
pub open_links_in_browser: Option<bool>,
|
||||||
pub admin_password: Option<String>,
|
pub admin_password: Option<String>,
|
||||||
pub show_window_on_startup: Option<bool>,
|
pub show_window_on_startup: Option<bool>,
|
||||||
|
pub log_filter_level: Option<String>,
|
||||||
|
pub log_filter_source: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppConfig {
|
impl AppConfig {
|
||||||
@@ -21,6 +23,8 @@ impl AppConfig {
|
|||||||
open_links_in_browser: Some(false),
|
open_links_in_browser: Some(false),
|
||||||
admin_password: None,
|
admin_password: None,
|
||||||
show_window_on_startup: Some(true),
|
show_window_on_startup: Some(true),
|
||||||
|
log_filter_level: Some("all".to_string()),
|
||||||
|
log_filter_source: Some("openlist".to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
pub static APP_ID: &str = "io.github.openlistteam.openlist.desktop";
|
pub static APP_ID: &str = "io.github.openlistteam.openlist.desktop";
|
||||||
|
|
||||||
// Normalize path without Windows long path prefix (\\?\)
|
// Normalize path without Windows long path prefix (\\?\)
|
||||||
// The \\?\ prefix breaks compatibility with some applications like SQLite
|
// 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")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
// On Windows, use canonicalize but strip the \\?\ prefix if present
|
// On Windows, use canonicalize but strip the \\?\ prefix if present
|
||||||
let canonical = path
|
let canonical = path
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.map_err(|e| format!("Failed to canonicalize path: {e}"))?;
|
.map_err(|e| format!("Failed to canonicalize path: {e}"))?;
|
||||||
|
|
||||||
let path_str = canonical.to_string_lossy();
|
let path_str = canonical.to_string_lossy();
|
||||||
if let Some(stripped) = path_str.strip_prefix(r"\\?\") {
|
if let Some(stripped) = path_str.strip_prefix(r"\\?\") {
|
||||||
Ok(PathBuf::from(stripped))
|
Ok(PathBuf::from(stripped))
|
||||||
@@ -20,7 +20,7 @@ fn normalize_path(path: &PathBuf) -> Result<PathBuf, String> {
|
|||||||
Ok(canonical)
|
Ok(canonical)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
path.canonicalize()
|
path.canonicalize()
|
||||||
|
|||||||
2
src/types/types.d.ts
vendored
2
src/types/types.d.ts
vendored
@@ -52,6 +52,8 @@ interface AppConfig {
|
|||||||
open_links_in_browser?: boolean
|
open_links_in_browser?: boolean
|
||||||
admin_password?: string
|
admin_password?: string
|
||||||
show_window_on_startup?: boolean
|
show_window_on_startup?: boolean
|
||||||
|
log_filter_level?: string
|
||||||
|
log_filter_source?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MergedSettings {
|
interface MergedSettings {
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ const logContainer = ref<HTMLElement>()
|
|||||||
const searchInputRef = ref<HTMLInputElement>()
|
const searchInputRef = ref<HTMLInputElement>()
|
||||||
const autoScroll = ref(true)
|
const autoScroll = ref(true)
|
||||||
const isPaused = ref(false)
|
const isPaused = ref(false)
|
||||||
const filterLevel = ref<string>('all')
|
const filterLevel = ref<string>(appStore.settings.app.log_filter_level || 'all')
|
||||||
const filterSource = ref<string>(localStorage.getItem('logFilterSource') || 'openlist')
|
const filterSource = ref<string>(appStore.settings.app.log_filter_source || 'openlist')
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const selectedEntries = ref<Set<number>>(new Set())
|
const selectedEntries = ref<Set<number>>(new Set())
|
||||||
const showFilters = ref(true)
|
const showFilters = ref(true)
|
||||||
@@ -55,8 +55,14 @@ const confirmDialogConfig = ref({
|
|||||||
onCancel: () => {}
|
onCancel: () => {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(filterLevel, async newValue => {
|
||||||
|
appStore.settings.app.log_filter_level = newValue
|
||||||
|
await appStore.saveSettings()
|
||||||
|
})
|
||||||
|
|
||||||
watch(filterSource, async newValue => {
|
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 appStore.loadLogs((newValue !== 'gin' ? newValue : 'openlist') as filterSourceType)
|
||||||
await scrollToBottom()
|
await scrollToBottom()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user