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.
This commit is contained in:
Agel committed 2026-11-19 14:30:41 +01:00
1 parent eca05bec8d
commit 2636b7cf51
8 files changed
+182 -1

No files matched your search

+2
View File
@@ -322,6 +322,7 @@ src/
FormatReader.h FormatReader.h
HistoryModel.h/cpp HistoryModel.h/cpp
IFileDialogService.h IFileDialogService.h
MacMenuBar.h/mm
NativeFileDialogService.h/cpp NativeFileDialogService.h/cpp
PortalFileDialogService.h/cpp PortalFileDialogService.h/cpp
QmlRegistrations.h QmlRegistrations.h
@@ -385,6 +386,7 @@ src/
SettingsPopup.qml SettingsPopup.qml
SideBar.qml SideBar.qml
SideBarButton.qml SideBarButton.qml
UpdatePopup.qml
pages/ pages/
CustomThemePage.qml CustomThemePage.qml
HistoryPage.qml HistoryPage.qml
+12 -1
View File
@@ -168,11 +168,16 @@ if(WIN32)
list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/asteria.rc") list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/asteria.rc")
endif() endif()
if(APPLE) if(APPLE)
enable_language(OBJCXX)
set(APP_ICON_MACOS "${CMAKE_CURRENT_SOURCE_DIR}/src/assets/asteria-qt.icns") set(APP_ICON_MACOS "${CMAKE_CURRENT_SOURCE_DIR}/src/assets/asteria-qt.icns")
set_source_files_properties(${APP_ICON_MACOS} PROPERTIES set_source_files_properties(${APP_ICON_MACOS} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources" 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() endif()
# Executable # Executable
@@ -229,6 +234,10 @@ target_link_libraries(asteria-qt PRIVATE
${UCHARDET_LIB} ${UCHARDET_LIB}
) )
if(APPLE)
target_link_libraries(asteria-qt PRIVATE "-framework AppKit")
endif()
if(UNIX AND NOT APPLE AND Qt6DBus_FOUND) if(UNIX AND NOT APPLE AND Qt6DBus_FOUND)
target_link_libraries(asteria-qt PRIVATE Qt6::DBus) target_link_libraries(asteria-qt PRIVATE Qt6::DBus)
target_compile_definitions(asteria-qt PRIVATE HAS_QT_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/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/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/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/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) 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/LabeledSlider.qml
src/qml/components/LabeledSwitch.qml src/qml/components/LabeledSwitch.qml
src/qml/components/SettingsPopup.qml src/qml/components/SettingsPopup.qml
src/qml/components/UpdatePopup.qml
src/qml/pages/StarterPage.qml src/qml/pages/StarterPage.qml
src/qml/pages/ReaderPage.qml src/qml/pages/ReaderPage.qml
src/qml/pages/HistoryPage.qml src/qml/pages/HistoryPage.qml
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <QMenuBar>
#include <memory>
namespace MacMenuBar {
std::unique_ptr<QMenuBar> create();
void showAboutPanel();
} // namespace MacMenuBar
+30
View File
@@ -0,0 +1,30 @@
#include "MacMenuBar.h"
#import <AppKit/AppKit.h>
#include <QAction>
#include <QApplication>
#include <QMenu>
#include <QMenuBar>
namespace MacMenuBar {
void showAboutPanel()
{
[NSApp activateIgnoringOtherApps:YES];
[NSApp orderFrontStandardAboutPanel:nil];
}
std::unique_ptr<QMenuBar> create()
{
auto menuBar = std::make_unique<QMenuBar>(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
+8
View File
@@ -34,6 +34,10 @@
#include "backend/PortalFileDialogService.h" #include "backend/PortalFileDialogService.h"
#endif #endif
#ifdef Q_OS_MACOS
#include "backend/MacMenuBar.h"
#endif
void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &msg) void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ {
QString timestamp = QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss.zzz")); 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)); appIcon.addFile(QStringLiteral(":/Asteria/packaging/icons/64x64/asteria-qt.png"), QSize(64, 64));
QApplication::setWindowIcon(appIcon); QApplication::setWindowIcon(appIcon);
#ifdef Q_OS_MACOS
const auto macMenuBar = MacMenuBar::create();
#endif
QQuickStyle::setStyle(QStringLiteral("Basic")); QQuickStyle::setStyle(QStringLiteral("Basic"));
// --- Object graph (construction order = dependency order) --- // --- Object graph (construction order = dependency order) ---
+19
View File
@@ -1,3 +1,4 @@
pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import Asteria import Asteria
@@ -11,6 +12,7 @@ ApplicationWindow {
readonly property bool sidebarOpen: (!root.inReader || root.barsVisible) && UiState.sidebarOpen readonly property bool sidebarOpen: (!root.inReader || root.barsVisible) && UiState.sidebarOpen
property string currentPage: "starter" property string currentPage: "starter"
property bool settingsOpen: false property bool settingsOpen: false
property bool updateOpen: false
// Set to true on the first book open at startup so we restore the last page. // Set to true on the first book open at startup so we restore the last page.
property bool _startupRestore: UiState.lastFilePath !== "" property bool _startupRestore: UiState.lastFilePath !== ""
property bool _bookInitializing: false property bool _bookInitializing: false
@@ -108,9 +110,14 @@ ApplicationWindow {
onNavigateTo: function(page) { onNavigateTo: function(page) {
if (page === "settings") { if (page === "settings") {
root.currentPage = Book.hasBook ? "reader" : "starter" root.currentPage = Book.hasBook ? "reader" : "starter"
root.updateOpen = false
root.settingsOpen = true root.settingsOpen = true
} else if (page === "update") {
root.settingsOpen = false
root.updateOpen = true
} else { } else {
root.settingsOpen = false root.settingsOpen = false
root.updateOpen = false
if (root.currentPage === "reader" && ReadingModel.isTextMode && readerPage.scrollView) if (root.currentPage === "reader" && ReadingModel.isTextMode && readerPage.scrollView)
readerPage.scrollView.syncScrollPosition() readerPage.scrollView.syncScrollPosition()
if (Book.hasBook || Book.loading) 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 { ErrorPopup {
anchors.fill: parent anchors.fill: parent
z: 3000 z: 3000
+6
View File
@@ -106,5 +106,11 @@ Rectangle {
title: "Settings" title: "Settings"
onClicked: root.navigateTo("settings") onClicked: root.navigateTo("settings")
} }
SideBarButton {
iconText: "\ue923"
title: "Update"
onClicked: root.navigateTo("update")
}
} }
} }
+94
View File
@@ -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
}
}
}
}
}
}