From 2636b7cf51c2e97e76177ae5a5dd4ac666ae0bcb Mon Sep 17 00:00:00 2001 From: Agel Date: Thu, 19 Nov 2026 14:30:41 +0100 Subject: [PATCH] Add Update sidebar menu item and macOS standard About menu Add an "Update" entry to the sidebar to give users quick access to the application version without interrupting their reading session. Clicking it opens a themed modal popup (loaded conditionally via Loader) that displays AppInfo.version and keeps any currently open book loaded, providing a natural foundation for future update-checking functionality. On macOS, also install a parentless QMenuBar with a QAction::AboutRole item so Qt's Cocoa integration places "About Asteria" in the standard macOS Application menu without adding a QML in-window menu bar. The action invokes NSApp's standard About panel, leveraging the bundle name, icon, and version already configured in Info.plist. --- AGENTS.md | 2 + CMakeLists.txt | 13 ++++- src/backend/MacMenuBar.h | 11 ++++ src/backend/MacMenuBar.mm | 30 ++++++++++ src/main.cpp | 8 +++ src/qml/Main.qml | 19 ++++++ src/qml/components/SideBar.qml | 6 ++ src/qml/components/UpdatePopup.qml | 94 ++++++++++++++++++++++++++++++ 8 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/backend/MacMenuBar.h create mode 100644 src/backend/MacMenuBar.mm create mode 100644 src/qml/components/UpdatePopup.qml diff --git a/AGENTS.md b/AGENTS.md index 0833029..1bab2f0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -322,6 +322,7 @@ src/ FormatReader.h HistoryModel.h/cpp IFileDialogService.h + MacMenuBar.h/mm NativeFileDialogService.h/cpp PortalFileDialogService.h/cpp QmlRegistrations.h @@ -385,6 +386,7 @@ src/ SettingsPopup.qml SideBar.qml SideBarButton.qml + UpdatePopup.qml pages/ CustomThemePage.qml HistoryPage.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index fcd2913..c671077 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,11 +168,16 @@ if(WIN32) list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/asteria.rc") endif() if(APPLE) + enable_language(OBJCXX) set(APP_ICON_MACOS "${CMAKE_CURRENT_SOURCE_DIR}/src/assets/asteria-qt.icns") set_source_files_properties(${APP_ICON_MACOS} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" ) - list(APPEND SOURCES ${APP_ICON_MACOS}) + list(APPEND SOURCES + ${APP_ICON_MACOS} + src/backend/MacMenuBar.h + src/backend/MacMenuBar.mm + ) endif() # Executable @@ -229,6 +234,10 @@ target_link_libraries(asteria-qt PRIVATE ${UCHARDET_LIB} ) +if(APPLE) + target_link_libraries(asteria-qt PRIVATE "-framework AppKit") +endif() + if(UNIX AND NOT APPLE AND Qt6DBus_FOUND) target_link_libraries(asteria-qt PRIVATE Qt6::DBus) target_compile_definitions(asteria-qt PRIVATE HAS_QT_DBUS) @@ -259,6 +268,7 @@ set_source_files_properties(src/qml/components/LabeledSwitch.qml PROPERTIES QT_R set_source_files_properties(src/qml/pages/StarterPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/StarterPage.qml) set_source_files_properties(src/qml/pages/ReaderPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/ReaderPage.qml) set_source_files_properties(src/qml/components/SettingsPopup.qml PROPERTIES QT_RESOURCE_ALIAS components/SettingsPopup.qml) +set_source_files_properties(src/qml/components/UpdatePopup.qml PROPERTIES QT_RESOURCE_ALIAS components/UpdatePopup.qml) set_source_files_properties(src/qml/pages/HistoryPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/HistoryPage.qml) set_source_files_properties(src/qml/pages/CustomThemePage.qml PROPERTIES QT_RESOURCE_ALIAS pages/CustomThemePage.qml) @@ -283,6 +293,7 @@ qt_add_qml_module(asteria-qt src/qml/components/LabeledSlider.qml src/qml/components/LabeledSwitch.qml src/qml/components/SettingsPopup.qml + src/qml/components/UpdatePopup.qml src/qml/pages/StarterPage.qml src/qml/pages/ReaderPage.qml src/qml/pages/HistoryPage.qml diff --git a/src/backend/MacMenuBar.h b/src/backend/MacMenuBar.h new file mode 100644 index 0000000..ac247e0 --- /dev/null +++ b/src/backend/MacMenuBar.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace MacMenuBar { + +std::unique_ptr create(); +void showAboutPanel(); + +} // namespace MacMenuBar diff --git a/src/backend/MacMenuBar.mm b/src/backend/MacMenuBar.mm new file mode 100644 index 0000000..08cf834 --- /dev/null +++ b/src/backend/MacMenuBar.mm @@ -0,0 +1,30 @@ +#include "MacMenuBar.h" + +#import + +#include +#include +#include +#include + +namespace MacMenuBar { + +void showAboutPanel() +{ + [NSApp activateIgnoringOtherApps:YES]; + [NSApp orderFrontStandardAboutPanel:nil]; +} + +std::unique_ptr create() +{ + auto menuBar = std::make_unique(nullptr); + QMenu *appMenu = menuBar->addMenu(QApplication::applicationName()); + QAction *aboutAction = appMenu->addAction( + QApplication::translate("MacMenuBar", "About %1") + .arg(QApplication::applicationName())); + aboutAction->setMenuRole(QAction::AboutRole); + QObject::connect(aboutAction, &QAction::triggered, &showAboutPanel); + return menuBar; +} + +} // namespace MacMenuBar diff --git a/src/main.cpp b/src/main.cpp index c9a7f06..33b2e7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,10 @@ #include "backend/PortalFileDialogService.h" #endif +#ifdef Q_OS_MACOS +#include "backend/MacMenuBar.h" +#endif + void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString timestamp = QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss.zzz")); @@ -88,6 +92,10 @@ int main(int argc, char *argv[]) appIcon.addFile(QStringLiteral(":/Asteria/packaging/icons/64x64/asteria-qt.png"), QSize(64, 64)); QApplication::setWindowIcon(appIcon); +#ifdef Q_OS_MACOS + const auto macMenuBar = MacMenuBar::create(); +#endif + QQuickStyle::setStyle(QStringLiteral("Basic")); // --- Object graph (construction order = dependency order) --- diff --git a/src/qml/Main.qml b/src/qml/Main.qml index b68e353..bcfbcac 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -1,3 +1,4 @@ +pragma ComponentBehavior: Bound import QtQuick import QtQuick.Controls.Basic import Asteria @@ -11,6 +12,7 @@ ApplicationWindow { readonly property bool sidebarOpen: (!root.inReader || root.barsVisible) && UiState.sidebarOpen property string currentPage: "starter" property bool settingsOpen: false + property bool updateOpen: false // Set to true on the first book open at startup so we restore the last page. property bool _startupRestore: UiState.lastFilePath !== "" property bool _bookInitializing: false @@ -108,9 +110,14 @@ ApplicationWindow { onNavigateTo: function(page) { if (page === "settings") { root.currentPage = Book.hasBook ? "reader" : "starter" + root.updateOpen = false root.settingsOpen = true + } else if (page === "update") { + root.settingsOpen = false + root.updateOpen = true } else { root.settingsOpen = false + root.updateOpen = false if (root.currentPage === "reader" && ReadingModel.isTextMode && readerPage.scrollView) readerPage.scrollView.syncScrollPosition() if (Book.hasBook || Book.loading) @@ -186,6 +193,18 @@ ApplicationWindow { } } + Loader { + id: updatePopupLoader + anchors.fill: parent + z: 2000 + active: root.updateOpen + sourceComponent: Component { + UpdatePopup { + onCloseRequested: root.updateOpen = false + } + } + } + ErrorPopup { anchors.fill: parent z: 3000 diff --git a/src/qml/components/SideBar.qml b/src/qml/components/SideBar.qml index dca72a0..4003bc5 100644 --- a/src/qml/components/SideBar.qml +++ b/src/qml/components/SideBar.qml @@ -106,5 +106,11 @@ Rectangle { title: "Settings" onClicked: root.navigateTo("settings") } + + SideBarButton { + iconText: "\ue923" + title: "Update" + onClicked: root.navigateTo("update") + } } } diff --git a/src/qml/components/UpdatePopup.qml b/src/qml/components/UpdatePopup.qml new file mode 100644 index 0000000..63017a1 --- /dev/null +++ b/src/qml/components/UpdatePopup.qml @@ -0,0 +1,94 @@ +import QtQuick +import QtQuick.Controls.Basic +import Asteria + +FocusScope { + id: root + + signal closeRequested() + + focus: true + Accessible.role: Accessible.Dialog + Accessible.name: qsTr("Update") + + Keys.onEscapePressed: root.closeRequested() + + Rectangle { + anchors.fill: parent + color: ThemeManager.currentTheme.overlayBg + + MouseArea { + anchors.fill: parent + onClicked: root.closeRequested() + } + + Rectangle { + id: card + anchors.centerIn: parent + width: Math.min(root.width * 0.7, 360) + height: dialogColumn.implicitHeight + 48 + color: ThemeManager.currentTheme.surface + radius: 8 + + // Prevent clicks inside the card from dismissing the backdrop + MouseArea { + anchors.fill: parent + } + + Column { + id: dialogColumn + spacing: 16 + anchors { + top: parent.top + left: parent.left + right: parent.right + topMargin: 24 + leftMargin: 24 + rightMargin: 24 + } + + Text { + width: parent.width + text: qsTr("Update") + font.pixelSize: 16 + font.bold: true + color: ThemeManager.currentTheme.uiText + horizontalAlignment: Text.AlignHCenter + } + + Text { + width: parent.width + text: qsTr("Current version: %1").arg(AppInfo.version) + font.pixelSize: 14 + color: ThemeManager.currentTheme.readingText + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.Wrap + } + + Button { + id: closeButton + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("Ok") + onClicked: root.closeRequested() + + contentItem: Text { + text: closeButton.text + font.pixelSize: 14 + color: ThemeManager.currentTheme.readingText + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + background: Rectangle { + implicitWidth: 80 + implicitHeight: 36 + radius: 4 + color: closeButton.hovered + ? Qt.lighter(ThemeManager.currentTheme.primaryAccent, 1.15) + : ThemeManager.currentTheme.primaryAccent + } + } + } + } + } +}