Release v0.2.19

This commit is contained in:
burnintuna 2026-08-21 23:24:30 +09:00
parent 8f0578c0d3
commit bae8699674
7 changed files with 371 additions and 69 deletions

View file

@ -21,7 +21,9 @@ use tar::Archive;
use crate::browser::{
BrowserEntry, EntryKind, SortDirection, SortField, classify_file, sort_entries,
};
use crate::config::{AppConfig, FavoriteEntry, LocationKind, LocationProfile, ViewerMode};
use crate::config::{
AppConfig, FavoriteEntry, LocationKind, LocationProfile, RecentFileEntry, ViewerMode,
};
use crate::database::Database;
use crate::source::{
display_remote_uri, ensure_mounted, enumerate_directory, enumerate_tree_entries,
@ -36,6 +38,7 @@ use crate::viewer::{
use crate::zip_cache::ZipCache;
const MOUSE_BACK_BUTTON: u32 = 8;
const RECENT_FILE_LIMIT: usize = 100;
const UPDATE_BUNDLE_URL: &str =
"https://burningtuna.cafe24.com/www/Downloads/Comicviewer/Comicviewer-latest-x86_64.tar.gz";
const UPDATE_CHECKSUM_URL: &str = "https://burningtuna.cafe24.com/www/Downloads/Comicviewer/Comicviewer-latest-x86_64.tar.gz.sha256";
@ -83,11 +86,14 @@ impl ComicWindow {
edit_location_button.set_sensitive(false);
let delete_location_button = gtk::Button::with_label("삭제");
delete_location_button.set_sensitive(false);
let clear_recent_button = gtk::Button::with_label("최근 기록 비우기");
clear_recent_button.set_visible(false);
locations.append(&gtk::Label::new(Some("위치")));
locations.append(&location_dropdown);
locations.append(&add_location_button);
locations.append(&edit_location_button);
locations.append(&delete_location_button);
locations.append(&clear_recent_button);
let navigation = gtk::Box::new(gtk::Orientation::Horizontal, 6);
let up_button = gtk::Button::builder()
@ -149,6 +155,7 @@ impl ComicWindow {
location_dropdown,
edit_location_button,
delete_location_button,
clear_recent_button: clear_recent_button.clone(),
path_entry,
search_entry,
sort_dropdown,
@ -159,7 +166,7 @@ impl ComicWindow {
state: RefCell::new(BrowserState {
profile_index: 0,
favorite_profile: None,
browsing_favorites: false,
mode: BrowserMode::Directory,
root_uri: root_uri.clone(),
current_uri: root_uri,
entries: Vec::new(),
@ -206,7 +213,7 @@ impl ComicWindow {
struct BrowserState {
profile_index: usize,
favorite_profile: Option<LocationProfile>,
browsing_favorites: bool,
mode: BrowserMode,
root_uri: String,
current_uri: String,
entries: Vec<BrowserEntry>,
@ -218,6 +225,13 @@ struct BrowserState {
typeahead_last_input: Option<Instant>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum BrowserMode {
Directory,
Favorites,
Recent,
}
struct BrowserController {
window: gtk::ApplicationWindow,
about_button: gtk::Button,
@ -225,6 +239,7 @@ struct BrowserController {
location_dropdown: gtk::DropDown,
edit_location_button: gtk::Button,
delete_location_button: gtk::Button,
clear_recent_button: gtk::Button,
path_entry: gtk::Entry,
search_entry: gtk::SearchEntry,
sort_dropdown: gtk::DropDown,
@ -298,8 +313,10 @@ impl BrowserController {
let Some(controller) = controller.upgrade() else {
return;
};
if is_favorites_selection(item.position(), controller.profiles().len()) {
controller.show_favorites();
match special_browser_mode(item.position(), controller.profiles().len()) {
Some(BrowserMode::Favorites) => controller.show_favorites(),
Some(BrowserMode::Recent) => controller.show_recent(),
_ => {}
}
});
label.add_controller(click);
@ -406,6 +423,9 @@ impl BrowserController {
let controller = Rc::clone(self);
self.clear_cache_button
.connect_clicked(move |_| controller.show_clear_cache_dialog());
let controller = Rc::clone(self);
self.clear_recent_button
.connect_clicked(move |_| controller.show_clear_recent_dialog());
}
fn profiles(&self) -> Vec<LocationProfile> {
@ -431,6 +451,7 @@ impl BrowserController {
.map(|profile| profile.name.clone())
.collect();
names.push("즐겨찾기".into());
names.push("최근 열어본 파일".into());
let names: Vec<_> = names.iter().map(String::as_str).collect();
self.location_dropdown
.set_model(Some(&gtk::StringList::new(&names)));
@ -439,9 +460,16 @@ impl BrowserController {
fn select_profile(self: &Rc<Self>) {
let profile_index = self.location_dropdown.selected() as usize;
let profiles = self.profiles();
if is_favorites_selection(self.location_dropdown.selected(), profiles.len()) {
self.show_favorites();
return;
match special_browser_mode(self.location_dropdown.selected(), profiles.len()) {
Some(BrowserMode::Favorites) => {
self.show_favorites();
return;
}
Some(BrowserMode::Recent) => {
self.show_recent();
return;
}
_ => {}
}
let editable = profile_index > 0 && profile_index < profiles.len();
self.edit_location_button.set_sensitive(editable);
@ -455,10 +483,11 @@ impl BrowserController {
let mut state = self.state.borrow_mut();
state.profile_index = profile_index;
state.favorite_profile = None;
state.browsing_favorites = false;
state.mode = BrowserMode::Directory;
state.root_uri = root_uri.clone();
state.current_uri = root_uri;
drop(state);
self.update_mode_controls(BrowserMode::Directory);
self.path_entry.set_editable(true);
self.search_entry.set_text("");
self.refresh();
@ -484,24 +513,58 @@ impl BrowserController {
state.generation = state.generation.wrapping_add(1);
state.typeahead_query.clear();
state.typeahead_last_input = None;
state.browsing_favorites = true;
state.mode = BrowserMode::Favorites;
state.favorite_profile = None;
state.entries = entries;
drop(state);
self.update_mode_controls(BrowserMode::Favorites);
self.search_entry.set_text("");
self.render();
}
fn show_recent(&self) {
self.cancel_listing();
self.edit_location_button.set_sensitive(false);
self.delete_location_button.set_sensitive(false);
self.path_entry.set_text("최근 열어본 파일");
self.path_entry.set_editable(false);
let entries = self
.config
.borrow()
.recent_files
.iter()
.map(recent_file_browser_entry)
.collect();
let mut state = self.state.borrow_mut();
state.generation = state.generation.wrapping_add(1);
state.typeahead_query.clear();
state.typeahead_last_input = None;
state.mode = BrowserMode::Recent;
state.favorite_profile = None;
state.entries = entries;
drop(state);
self.update_mode_controls(BrowserMode::Recent);
self.search_entry.set_text("");
self.render();
}
fn update_mode_controls(&self, mode: BrowserMode) {
let recent = mode == BrowserMode::Recent;
self.clear_recent_button.set_visible(recent);
self.sort_dropdown.set_sensitive(!recent);
self.direction_button.set_sensitive(!recent);
}
fn open_favorite(self: &Rc<Self>, favorite: FavoriteEntry) {
let Ok(root) = root_file(&favorite.profile) else {
self.status_label
.set_text("즐겨찾기의 저장된 위치가 올바르지 않습니다.");
.set_text("저장된 파일의 위치 정보가 올바르지 않습니다.");
return;
};
let favorite_file = gio::File::for_uri(&favorite.uri);
if !is_within_root(&favorite_file, &root) {
self.status_label
.set_text("즐겨찾기가 저장된 위치의 루트 밖을 가리킵니다.");
.set_text("저장된 파일이 위치의 루트 밖을 가리킵니다.");
return;
}
if favorite.is_directory {
@ -511,17 +574,18 @@ impl BrowserController {
self.delete_location_button.set_sensitive(false);
let mut state = self.state.borrow_mut();
state.favorite_profile = Some(favorite.profile.clone());
state.browsing_favorites = false;
state.mode = BrowserMode::Directory;
state.root_uri = root.uri().into();
state.current_uri = favorite.uri;
drop(state);
self.update_mode_controls(BrowserMode::Directory);
self.search_entry.set_text("");
self.refresh();
return;
}
self.cancel_listing();
self.status_label.set_text("즐겨찾기에 연결하는 중...");
self.status_label.set_text("저장된 파일에 연결하는 중...");
let operation = mount_operation(&favorite.profile, &self.window);
let controller = Rc::downgrade(self);
let task = glib::MainContext::default().spawn_local(async move {
@ -554,7 +618,7 @@ impl BrowserController {
if !kind.is_viewable() {
controller
.status_label
.set_text("이 즐겨찾기 파일 형식은 열 수 없습니다.");
.set_text("이 파일 형식은 열 수 없습니다.");
return;
}
let entry = folder_entries
@ -591,8 +655,7 @@ impl BrowserController {
}
fn open_entered_path(self: &Rc<Self>) {
let browsing_favorites = self.state.borrow().browsing_favorites;
if browsing_favorites {
if self.state.borrow().mode != BrowserMode::Directory {
return;
}
let profile = self.current_profile();
@ -609,8 +672,7 @@ impl BrowserController {
}
fn go_up(self: &Rc<Self>) {
let browsing_favorites = self.state.borrow().browsing_favorites;
if browsing_favorites {
if self.state.borrow().mode != BrowserMode::Directory {
return;
}
let state = self.state.borrow();
@ -624,10 +686,17 @@ impl BrowserController {
}
fn refresh(self: &Rc<Self>) {
let browsing_favorites = self.state.borrow().browsing_favorites;
if browsing_favorites {
self.show_favorites();
return;
let mode = self.state.borrow().mode;
match mode {
BrowserMode::Favorites => {
self.show_favorites();
return;
}
BrowserMode::Recent => {
self.show_recent();
return;
}
BrowserMode::Directory => {}
}
self.cancel_listing();
let (profile, uri, generation) = {
@ -658,7 +727,8 @@ impl BrowserController {
let Some(controller) = progress_controller.upgrade() else {
return;
};
if controller.state.borrow().generation == generation {
let state = controller.state.borrow();
if state.generation == generation && state.mode == BrowserMode::Directory {
controller.status_label.set_text(&format!(
"폴더를 불러오는 중... ({count}개의 파일/폴더를 읽음)"
));
@ -669,7 +739,7 @@ impl BrowserController {
return;
};
let state = controller.state.borrow();
let stale = state.generation != generation || state.browsing_favorites;
let stale = state.generation != generation || state.mode != BrowserMode::Directory;
drop(state);
if stale {
return;
@ -701,12 +771,14 @@ impl BrowserController {
.filter(|entry| browser_search_match(entry, query.as_str()))
.cloned()
.collect();
sort_entries(
&mut visible_entries,
state.sort_field,
state.sort_direction,
case_insensitive,
);
if state.mode != BrowserMode::Recent {
sort_entries(
&mut visible_entries,
state.sort_field,
state.sort_direction,
case_insensitive,
);
}
let count = visible_entries.len();
let names = visible_entries
.iter()
@ -828,19 +900,40 @@ impl BrowserController {
else {
return;
};
let browsing_favorites = self.state.borrow().browsing_favorites;
if browsing_favorites {
let favorite = self
.config
.borrow()
.favorites
.iter()
.find(|favorite| favorite.uri == entry.uri)
.cloned();
if let Some(favorite) = favorite {
self.open_favorite(favorite);
let mode = self.state.borrow().mode;
match mode {
BrowserMode::Favorites => {
let favorite = self
.config
.borrow()
.favorites
.iter()
.find(|favorite| favorite.uri == entry.uri)
.cloned();
if let Some(favorite) = favorite {
self.open_favorite(favorite);
}
return;
}
return;
BrowserMode::Recent => {
let recent = self
.config
.borrow()
.recent_files
.iter()
.find(|recent| recent.uri == entry.uri)
.cloned();
if let Some(recent) = recent {
self.open_favorite(FavoriteEntry {
name: recent.name,
uri: recent.uri,
is_directory: false,
profile: recent.profile,
});
}
return;
}
BrowserMode::Directory => {}
}
match entry.kind {
EntryKind::Directory => {
@ -985,9 +1078,9 @@ impl BrowserController {
state.sort_direction,
case_insensitive,
);
let browsing_favorites = state.browsing_favorites;
let mode = state.mode;
drop(state);
if !browsing_favorites && entries.iter().any(|entry| entry.uri == current_uri) {
if mode == BrowserMode::Directory && entries.iter().any(|entry| entry.uri == current_uri) {
Rc::new(entries)
} else {
Rc::clone(fallback)
@ -1001,6 +1094,8 @@ impl BrowserController {
profile: LocationProfile,
reuse_window: Option<gtk::ApplicationWindow>,
) {
let recent_entry = entry.clone();
let recent_profile = profile.clone();
self.status_label.set_text("ZIP 파일 다운로드 준비 중...");
let progress_label = reuse_window.as_ref().map_or_else(
|| self.status_label.clone(),
@ -1027,6 +1122,7 @@ impl BrowserController {
}
match result {
Ok(source) => {
controller.record_recent_file(&recent_entry, &recent_profile);
controller.status_label.set_text("다운로드 완료");
result_label.set_text("ZIP 파일을 여는 중...");
let Some(application) = controller.window.application() else {
@ -1068,6 +1164,8 @@ impl BrowserController {
profile: LocationProfile,
reuse_window: Option<gtk::ApplicationWindow>,
) {
let recent_entry = entry.clone();
let recent_profile = profile.clone();
let kind = entry.kind;
self.status_label
.set_text("미디어 파일 다운로드 준비 중...");
@ -1096,6 +1194,7 @@ impl BrowserController {
}
match result {
Ok(source) => {
controller.record_recent_file(&recent_entry, &recent_profile);
controller.status_label.set_text("다운로드 완료");
result_label.set_text("미디어 파일을 여는 중...");
let Some(application) = controller.window.application() else {
@ -1208,16 +1307,32 @@ impl BrowserController {
}
fn profile_for_entry(&self, entry: &BrowserEntry) -> LocationProfile {
if self.state.borrow().browsing_favorites
&& let Some(profile) = self
.config
.borrow()
.favorites
.iter()
.find(|favorite| favorite.uri == entry.uri)
.map(|favorite| favorite.profile.clone())
{
return profile;
match self.state.borrow().mode {
BrowserMode::Favorites => {
if let Some(profile) = self
.config
.borrow()
.favorites
.iter()
.find(|favorite| favorite.uri == entry.uri)
.map(|favorite| favorite.profile.clone())
{
return profile;
}
}
BrowserMode::Recent => {
if let Some(profile) = self
.config
.borrow()
.recent_files
.iter()
.find(|recent| recent.uri == entry.uri)
.map(|recent| recent.profile.clone())
{
return profile;
}
}
BrowserMode::Directory => {}
}
self.current_profile()
}
@ -1449,13 +1564,14 @@ impl BrowserController {
let uri: String = directory.uri().into();
let mut state = self.state.borrow_mut();
state.favorite_profile = Some(profile);
state.browsing_favorites = false;
state.mode = BrowserMode::Directory;
state.root_uri = uri.clone();
state.current_uri = uri.clone();
state.entries = entries;
state.typeahead_query.clear();
state.typeahead_last_input = None;
drop(state);
self.update_mode_controls(BrowserMode::Directory);
self.path_entry.set_text(&display_uri(&uri));
self.search_entry.set_text("");
self.render();
@ -1525,8 +1641,7 @@ impl BrowserController {
return was_active;
}
*self.config.borrow_mut() = updated;
let browsing_favorites = self.state.borrow().browsing_favorites;
if browsing_favorites {
if self.state.borrow().mode == BrowserMode::Favorites {
self.show_favorites();
}
self.status_label.set_text(if active {
@ -1537,6 +1652,28 @@ impl BrowserController {
active
}
fn record_recent_file(&self, entry: &BrowserEntry, profile: &LocationProfile) {
let mut updated = self.config.borrow().clone();
record_recent_file(&mut updated, entry, profile);
if let Err(error) = updated.save(&self.config_path) {
self.status_label
.set_text(&format!("최근 파일 기록을 저장할 수 없습니다: {error:#}"));
return;
}
*self.config.borrow_mut() = updated;
if self.state.borrow().mode == BrowserMode::Recent {
let entries = self
.config
.borrow()
.recent_files
.iter()
.map(recent_file_browser_entry)
.collect();
self.state.borrow_mut().entries = entries;
self.render();
}
}
fn choose_download_destination(
self: &Rc<Self>,
entry: BrowserEntry,
@ -1973,6 +2110,58 @@ impl BrowserController {
});
dialog.present();
}
fn show_clear_recent_dialog(self: &Rc<Self>) {
let dialog = gtk::Window::builder()
.title("최근 기록 비우기")
.transient_for(&self.window)
.modal(true)
.resizable(false)
.default_width(420)
.build();
let content = gtk::Box::new(gtk::Orientation::Vertical, 16);
content.set_margin_top(18);
content.set_margin_bottom(12);
content.set_margin_start(18);
content.set_margin_end(18);
let message = gtk::Label::new(Some(
"최근 열어본 파일 기록을 모두 삭제하시겠습니까?\n즐겨찾기와 ZIP 읽기 진행도는 유지됩니다.",
));
message.set_wrap(true);
message.set_xalign(0.0);
let actions = gtk::Box::new(gtk::Orientation::Horizontal, 6);
actions.set_halign(gtk::Align::End);
let cancel_button = gtk::Button::with_label("취소");
let clear_button = gtk::Button::with_label("모두 삭제");
clear_button.add_css_class("destructive-action");
actions.append(&cancel_button);
actions.append(&clear_button);
content.append(&message);
content.append(&actions);
dialog.set_child(Some(&content));
let dialog_to_close = dialog.clone();
cancel_button.connect_clicked(move |_| dialog_to_close.close());
let controller = Rc::clone(self);
let dialog_to_close = dialog.clone();
clear_button.connect_clicked(move |_| {
let mut updated = controller.config.borrow().clone();
updated.recent_files.clear();
if let Err(error) = updated.save(&controller.config_path) {
controller
.status_label
.set_text(&format!("최근 기록을 삭제할 수 없습니다: {error:#}"));
return;
}
*controller.config.borrow_mut() = updated;
controller.show_recent();
controller
.status_label
.set_text("최근 기록을 삭제했습니다.");
dialog_to_close.close();
});
dialog.present();
}
}
fn install_latest_update() -> Result<()> {
@ -2258,8 +2447,15 @@ fn browser_search_match(entry: &BrowserEntry, lowercase_query: &str) -> bool {
lowercase_query.is_empty() || entry.name.to_lowercase().contains(lowercase_query)
}
fn is_favorites_selection(selected: u32, profile_count: usize) -> bool {
selected != gtk::INVALID_LIST_POSITION && selected as usize == profile_count
fn special_browser_mode(selected: u32, profile_count: usize) -> Option<BrowserMode> {
if selected == gtk::INVALID_LIST_POSITION {
return None;
}
match selected as usize {
index if index == profile_count => Some(BrowserMode::Favorites),
index if index == profile_count + 1 => Some(BrowserMode::Recent),
_ => None,
}
}
fn sorted_navigable_entries(
@ -2313,6 +2509,32 @@ fn favorite_browser_entry(favorite: &FavoriteEntry) -> BrowserEntry {
}
}
fn recent_file_browser_entry(recent: &RecentFileEntry) -> BrowserEntry {
BrowserEntry {
uri: recent.uri.clone(),
name: recent.name.clone(),
list_name: None,
kind: classify_file(Path::new(&recent.name)),
size: None,
modified: None,
created: None,
etag: None,
}
}
fn record_recent_file(config: &mut AppConfig, entry: &BrowserEntry, profile: &LocationProfile) {
config.recent_files.retain(|recent| recent.uri != entry.uri);
config.recent_files.insert(
0,
RecentFileEntry {
name: entry.name.clone(),
uri: entry.uri.clone(),
profile: profile.clone(),
},
);
config.recent_files.truncate(RECENT_FILE_LIMIT);
}
fn show_viewer_loading(
window: &gtk::ApplicationWindow,
file_name: &str,
@ -2603,9 +2825,62 @@ mod tests {
assert_eq!(folder.kind, EntryKind::Directory);
assert_eq!(archive.kind, EntryKind::ZipArchive);
assert!(is_favorites_selection(3, 3));
assert!(!is_favorites_selection(2, 3));
assert!(!is_favorites_selection(gtk::INVALID_LIST_POSITION, 3));
assert_eq!(special_browser_mode(3, 3), Some(BrowserMode::Favorites));
assert_eq!(special_browser_mode(4, 3), Some(BrowserMode::Recent));
assert_eq!(special_browser_mode(2, 3), None);
assert_eq!(special_browser_mode(gtk::INVALID_LIST_POSITION, 3), None);
}
#[test]
fn recent_files_move_to_front_and_keep_only_100() {
let profile = LocationProfile {
name: "원격".into(),
kind: LocationKind::Sftp,
address: "sftp://example.invalid/comics".into(),
username: "reader".into(),
password: "password".into(),
domain: String::new(),
};
let mut config = AppConfig::default();
for index in 0..=RECENT_FILE_LIMIT {
let entry = media_entry(&format!("page{index}.jpg"));
record_recent_file(&mut config, &entry, &profile);
}
assert_eq!(config.recent_files.len(), RECENT_FILE_LIMIT);
assert_eq!(config.recent_files[0].name, "page100.jpg");
assert!(
!config
.recent_files
.iter()
.any(|recent| recent.name == "page0.jpg")
);
let entry = media_entry("page50.jpg");
record_recent_file(&mut config, &entry, &profile);
assert_eq!(config.recent_files.len(), RECENT_FILE_LIMIT);
assert_eq!(config.recent_files[0].name, "page50.jpg");
assert_eq!(config.recent_files[0].profile.password, "password");
}
#[test]
fn recent_files_support_all_viewer_file_types() {
let profile = home_profile();
let mut config = AppConfig::default();
for name in ["book.zip", "page.jpg", "clip.mp4"] {
let mut entry = media_entry(name);
entry.kind = classify_file(Path::new(name));
record_recent_file(&mut config, &entry, &profile);
}
let kinds = config
.recent_files
.iter()
.map(recent_file_browser_entry)
.map(|entry| entry.kind)
.collect::<Vec<_>>();
assert_eq!(
kinds,
[EntryKind::Video, EntryKind::Image, EntryKind::ZipArchive]
);
}
#[test]