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:
8 files changed
+182
-1
No files matched your search
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMenuBar>
|
||||
#include <memory>
|
||||
|
||||
namespace MacMenuBar {
|
||||
|
||||
std::unique_ptr<QMenuBar> create();
|
||||
void showAboutPanel();
|
||||
|
||||
} // namespace MacMenuBar
|
||||
@@ -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
|
||||
@@ -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) ---
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -106,5 +106,11 @@ Rectangle {
|
||||
title: "Settings"
|
||||
onClicked: root.navigateTo("settings")
|
||||
}
|
||||
|
||||
SideBarButton {
|
||||
iconText: "\ue923"
|
||||
title: "Update"
|
||||
onClicked: root.navigateTo("update")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user