Reuse viewer windows and organize favorites

This commit is contained in:
burnintuna 2026-07-22 02:37:56 +09:00
parent ef2a0a7915
commit bb73c1abea
3 changed files with 587 additions and 163 deletions

View file

@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
pub struct AppConfig {
pub cache_quota_gb: u64,
pub fast_image_loading: bool,
pub viewer_mode: ViewerMode,
pub locations: Vec<LocationProfile>,
pub favorites: Vec<FavoriteEntry>,
}
@ -19,6 +20,7 @@ impl Default for AppConfig {
Self {
cache_quota_gb: 10,
fast_image_loading: true,
viewer_mode: ViewerMode::FitWidth,
locations: Vec::new(),
favorites: Vec::new(),
}
@ -55,6 +57,39 @@ pub enum LocationKind {
Sftp,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ViewerMode {
ActualSize,
#[default]
FitWidth,
FitHeight,
TwoPage,
Continuous,
}
impl ViewerMode {
pub fn dropdown_index(self) -> u32 {
match self {
Self::ActualSize => 0,
Self::FitWidth => 1,
Self::FitHeight => 2,
Self::TwoPage => 3,
Self::Continuous => 4,
}
}
pub fn from_dropdown_index(index: u32) -> Self {
match index {
0 => Self::ActualSize,
2 => Self::FitHeight,
3 => Self::TwoPage,
4 => Self::Continuous,
_ => Self::FitWidth,
}
}
}
impl AppConfig {
pub fn load_or_create(path: &Path) -> Result<Self> {
if path.exists() {
@ -139,6 +174,7 @@ mod tests {
let config = AppConfig {
cache_quota_gb: 0,
fast_image_loading: true,
viewer_mode: ViewerMode::FitWidth,
locations: vec![LocationProfile {
name: "테스트".into(),
kind: LocationKind::Sftp,
@ -173,6 +209,21 @@ mod tests {
fn fast_image_loading_is_enabled_for_existing_configs() {
let decoded: AppConfig = toml::from_str("cache_quota_gb = 10\n").unwrap();
assert!(decoded.fast_image_loading);
assert_eq!(decoded.viewer_mode, ViewerMode::FitWidth);
assert!(decoded.favorites.is_empty());
}
#[test]
fn viewer_modes_round_trip_through_dropdown_indices() {
for mode in [
ViewerMode::ActualSize,
ViewerMode::FitWidth,
ViewerMode::FitHeight,
ViewerMode::TwoPage,
ViewerMode::Continuous,
] {
assert_eq!(ViewerMode::from_dropdown_index(mode.dropdown_index()), mode);
}
assert_eq!(ViewerMode::from_dropdown_index(99), ViewerMode::FitWidth);
}
}