Remove Book and Close Book menu items and auto-close on navigation

Simplify sidebar navigation by removing the conditional Book and Close Book
items so users no longer need to manage a book left open in the background.

Because there is no longer a Book item to return to the reader, navigating
away from the reader to History or Custom Theme now flushes any pending
scroll position and closes the active or in-flight book. Opening the Settings
popup still keeps the book open behind the overlay, and clicking Files keeps
the current book open until a file is actually selected so cancelling the
file dialog preserves the current reading session.

This also fixes book-lifecycle edge cases exposed by closing on navigation:
- Cancel in-flight async loads in Book::close() and clear loading state so
  closing mid-load does not jump back to the reader or stall the spinner.
- Emit willCloseBook before resetting the reader so AppCoordinator snapshots
  final progress into HistoryModel and immediately clears UiState.lastFilePath.
- Mark Book as loading before clearing the outgoing reader when opening a new
  file to prevent HistoryPage from flashing between books, and fall back to
  History on load errors.
- Reset ScrollPageView and MangaPageView state when a book closes, and always
  navigate to the reader on restoreReady so CLI-opened files are not hidden
  behind a previously saved History page.
- Add coverage in BookTest and AppCoordinatorTest and document the behavior
  in AGENTS.md.
This commit is contained in:
Agel committed 2026-11-13 09:45:09 +01:00
1 parent 5940d86ed2
commit 5d96fbb0bb
12 files changed
+300 -46

No files matched your search

+5 -3
View File
@@ -27,7 +27,8 @@ AppCoordinator::AppCoordinator(Book &book,
, m_appState(appState)
, m_settings(settings)
{
connect(&m_book, &Book::willOpenNewBook, this, &AppCoordinator::onWillOpenNewBook);
connect(&m_book, &Book::willOpenNewBook, this, &AppCoordinator::snapshotOutgoingBook);
connect(&m_book, &Book::willCloseBook, this, &AppCoordinator::snapshotOutgoingBook);
connect(&m_readingModel, &ReadingModel::positionSaved, this, &AppCoordinator::onPositionSaved);
connect(&m_book, &Book::bookChanged, this, &AppCoordinator::onBookChanged);
@@ -35,8 +36,8 @@ AppCoordinator::AppCoordinator(Book &book,
this, &AppCoordinator::onAboutToQuit);
}
// Before a new book open: snapshot the outgoing book's progress into the library.
void AppCoordinator::onWillOpenNewBook()
// Before closing or opening a new book: snapshot the outgoing book's progress into the library.
void AppCoordinator::snapshotOutgoingBook()
{
if (m_book.hasBook())
m_historyModel.addOrUpdateBook(m_book.filePath(), m_readingModel.progress());
@@ -54,6 +55,7 @@ void AppCoordinator::onBookChanged()
{
if (!m_book.hasBook()) {
m_readingModel.setReader(nullptr);
m_uiState.setLastFilePath(QString());
return;
}
+1 -1
View File
@@ -26,7 +26,7 @@ public:
private slots:
void onBookChanged();
void onWillOpenNewBook();
void snapshotOutgoingBook();
void onPositionSaved();
void onAboutToQuit();
+23 -8
View File
@@ -66,16 +66,23 @@ void Book::openImpl(const QString &filePath)
if (m_reader)
emit willOpenNewBook();
close();
m_loading = true;
emit loadingChanged();
m_errorMessage.clear();
emit errorMessageChanged();
const int generation = ++m_openGeneration;
if (!m_loading) {
m_loading = true;
emit loadingChanged();
}
if (!m_errorMessage.isEmpty()) {
m_errorMessage.clear();
emit errorMessageChanged();
}
if (m_reader) {
m_reader.reset();
emit bookChanged();
}
m_openFuture = QtConcurrent::run([this, effectivePath, generation]() {
const auto reportError = [this, generation, effectivePath](const QString &err) {
QMetaObject::invokeMethod(this, [this, generation, effectivePath, err]() {
@@ -115,7 +122,15 @@ void Book::openImpl(const QString &filePath)
void Book::close()
{
++m_openGeneration;
if (m_loading) {
m_loading = false;
emit loadingChanged();
}
if (!m_reader) return;
emit willCloseBook();
m_reader.reset();
emit bookChanged();
}
+2
View File
@@ -49,6 +49,8 @@ public:
signals:
// Emitted just before replacing the current reader with a new one.
void willOpenNewBook();
// Emitted just before closing the current reader.
void willCloseBook();
void bookChanged();
void loadingChanged();
+13 -15
View File
@@ -57,17 +57,22 @@ ApplicationWindow {
Connections {
target: Book
function onLoadingChanged() {
if (Book.loading) root._bookInitializing = true
if (Book.loading)
root._bookInitializing = true
else if (!Book.hasBook)
root._bookInitializing = false
}
function onErrorMessageChanged() {
if (Book.errorMessage !== "") {
root._bookInitializing = false
root._startupRestore = false
UiState.barsVisible = true
if (!Book.hasBook && root.currentPage === "reader")
root.currentPage = "history"
}
}
function onBookChanged() {
if (!Book.hasBook) {
if (!Book.hasBook && !Book.loading) {
UiState.barsVisible = true
if (root.currentPage === "reader")
root.currentPage = "history"
@@ -106,15 +111,16 @@ ApplicationWindow {
root.settingsOpen = true
} else {
root.settingsOpen = false
if (root.currentPage === "reader" && ReadingModel.isTextMode && readerPage.scrollView)
readerPage.scrollView.syncScrollPosition()
if (Book.hasBook || Book.loading)
Book.close()
root.currentPage = page
}
}
onOpenFile: {
Book.browseAndOpen()
}
onCloseBook: {
Book.close()
}
}
Column {
@@ -201,16 +207,8 @@ ApplicationWindow {
function onRestoreReady(chunkIndex) {
if (!Book.hasBook) return
root._bookInitializing = false
if (root._startupRestore) {
root._startupRestore = false
const savedPage = UiState.lastPage
if (savedPage === "history")
root.currentPage = savedPage
else
root.currentPage = "reader"
} else {
root.currentPage = "reader"
}
root._startupRestore = false
root.currentPage = "reader"
}
}
+11 -1
View File
@@ -213,10 +213,20 @@ Rectangle {
}
}
function resetViewState() {
clickDebounce.stop()
root.contentReady = false
pageArea.pair = []
root.currentPair = 0
}
Connections {
target: Book
function onLoadingChanged() {
if (Book.loading) root.contentReady = false
if (Book.loading) root.resetViewState()
}
function onBookChanged() {
if (!Book.hasBook) root.resetViewState()
}
}
}
+13 -2
View File
@@ -241,12 +241,23 @@ Rectangle {
}
}
function resetViewState() {
restoreTimer.stop();
scrollAnimation.stop();
root.contentReady = false;
root.restoreReady = false;
}
Connections {
target: Book
function onLoadingChanged() {
if (Book.loading) {
root.contentReady = false;
root.restoreReady = false;
root.resetViewState();
}
}
function onBookChanged() {
if (!Book.hasBook) {
root.resetViewState();
}
}
}
-15
View File
@@ -9,7 +9,6 @@ Rectangle {
signal closeDrawer()
signal navigateTo(string page)
signal openFile()
signal closeBook()
width: root.sidebarOpen ? ThemeManager.sidebarWidth : 0
clip: true
@@ -53,13 +52,6 @@ Rectangle {
y: ThemeManager.headerHeight
width: ThemeManager.sidebarWidth
SideBarButton {
visible: Book.hasBook
iconText: "\ue86d"
title: "Book"
onClicked: root.navigateTo("reader")
}
SideBarButton {
iconText: "\ue02f"
title: "History"
@@ -72,13 +64,6 @@ Rectangle {
onClicked: root.openFile()
}
SideBarButton {
visible: Book.hasBook
iconText: "\ue5cd"
title: "Close Book"
onClicked: root.closeBook()
}
// Divider
Rectangle {
width: parent.width