From b3f7a9c158b4b0be62383bb687c8fe3d1c29b5ce Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Wed, 7 Oct 2026 21:43:41 +0800 Subject: [PATCH] fix: read auto-start state from app model in context menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. The context menu's "Add/Remove from startup" state was read through DesktopIntegration.isAutoStart() -> AppMgr::readProperty(), a synchronous D-Bus call on the GUI thread (25s default timeout). While ApplicationManager was restarting, every menu build could emit "Failed to read property AutoStart" and stall the GUI. 2. Add AppItemMenu.autoStart and pass model.autoStart from both menu creation sites: qml/Main.qml and the applet's launcheritem.qml showContextMenu, which applet views invoke via QML creation-context resolution. This is the existing autoStart model role refreshed through PropertiesChanged. 3. Remove the now-unused DesktopIntegration.isAutoStart() and AppMgr::autoStart(); the write path still uses setAutoStart() unchanged. Log: Avoid blocking D-Bus reads when building the launcher context menu. Influence: 1. Open an app context menu; verify "Add/Remove from startup" matches the emblem_autostart badge and toggles normally. 2. Restart ApplicationManager and open the context menu; verify no "Failed to read property AutoStart" warning and no GUI stall. 3. Reopen the context menu after toggling to verify the state refresh. fix: 右键菜单改从模型读取开机自启状态 1. 右键菜单的“开机自启”状态原先经 DesktopIntegration.isAutoStart() -> AppMgr::readProperty() 在 GUI 线程同步读 D-Bus(默认 25 秒超时), ApplicationManager 重启窗口内会打出 "Failed to read property AutoStart" 并可能阻塞 GUI。 2. AppItemMenu 新增 autoStart 属性,qml/Main.qml 与 applet 的 launcheritem.qml showContextMenu 两处创建点传入 model.autoStart;即 emblem_autostart 已在使用的 autoStart 模型角色,随 PropertiesChanged 刷新。 3. 删除不再使用的 DesktopIntegration.isAutoStart() 与 AppMgr::autoStart(); 写入路径 setAutoStart() 保持不变。 Log: 避免构建启动器右键菜单时同步读取 D-Bus。 Influence: 1. 打开应用右键菜单,确认“开机自启”状态与 emblem_autostart 角标一致, 切换正常。 2. 重启 ApplicationManager 后打开右键菜单,确认无 "Failed to read property AutoStart" 告警且 GUI 不卡顿。 3. 切换后重新打开右键菜单,确认状态刷新。 PMS: TASK-394335 --- desktopintegration.cpp | 5 ----- desktopintegration.h | 1 - qml/AppItemMenu.qml | 5 +++-- qml/Main.qml | 3 ++- shell-launcher-applet/package/launcheritem.qml | 3 ++- src/ddeintegration/appmgr.cpp | 6 ------ src/ddeintegration/appmgr.h | 1 - 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/desktopintegration.cpp b/desktopintegration.cpp index 6b17943f..6974ffed 100644 --- a/desktopintegration.cpp +++ b/desktopintegration.cpp @@ -183,11 +183,6 @@ void DesktopIntegration::removeFromDesktop(const QString &desktopId) AppMgr::removeFromDesktop(desktopId); } -bool DesktopIntegration::isAutoStart(const QString &desktopId) const -{ - return AppMgr::autoStart(desktopId); -} - // only affect the one in XDG_CONFIG_HOME, don't care about the system one (even if there is one). void DesktopIntegration::setAutoStart(const QString &desktopId, bool on) { diff --git a/desktopintegration.h b/desktopintegration.h index 33543a8a..2c9fda5b 100644 --- a/desktopintegration.h +++ b/desktopintegration.h @@ -67,7 +67,6 @@ class DesktopIntegration : public QObject Q_INVOKABLE bool isOnDesktop(const QString & desktopId) const; Q_INVOKABLE void sendToDesktop(const QString & desktopId); Q_INVOKABLE void removeFromDesktop(const QString & desktopId); - Q_INVOKABLE bool isAutoStart(const QString & desktopId) const; Q_INVOKABLE void setAutoStart(const QString & desktopId, bool on = true); Q_INVOKABLE bool shouldSkipConfirmUninstallDialog(const QString & desktopId) const; Q_INVOKABLE void uninstallApp(const QString & desktopId); diff --git a/qml/AppItemMenu.qml b/qml/AppItemMenu.qml index 1fa073bb..a5a01dcd 100644 --- a/qml/AppItemMenu.qml +++ b/qml/AppItemMenu.qml @@ -19,6 +19,7 @@ Loader { property bool hideFavoriteMenu property bool hideMoveToTopMenu property bool hideDisplayScalingMenu + property bool autoStart readonly property bool isFullscreen: LauncherController.currentFrame === "FullscreenFrame" readonly property bool isHorizontalDock: DesktopIntegration.dockPosition === Qt.UpArrow || DesktopIntegration.dockPosition === Qt.DownArrow readonly property int dockSpacing: (isHorizontalDock ? DesktopIntegration.dockGeometry.height : DesktopIntegration.dockGeometry.width) / Screen.devicePixelRatio @@ -118,9 +119,9 @@ Loader { MenuItem { objectName: "RemoveFromStartup" enabled: !root.desktopId.startsWith("internal/folders/") - text: DesktopIntegration.isAutoStart(root.desktopId) ? qsTr("Remove from startup") : qsTr("Add to startup") + text: root.autoStart ? qsTr("Remove from startup") : qsTr("Add to startup") onTriggered: { - DesktopIntegration.setAutoStart(root.desktopId, !DesktopIntegration.isAutoStart(root.desktopId)) + DesktopIntegration.setAutoStart(root.desktopId, !root.autoStart) } } MenuItem { diff --git a/qml/Main.qml b/qml/Main.qml index 097dd9be..b1a12a22 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -76,7 +76,8 @@ QtObject { isFavoriteItem: false, hideFavoriteMenu: true, hideDisplayScalingMenu: false, - hideMoveToTopMenu: true + hideMoveToTopMenu: true, + autoStart: model.autoStart }, additionalProps)); menu.closed.connect(menu.destroy) menu.popup(); diff --git a/shell-launcher-applet/package/launcheritem.qml b/shell-launcher-applet/package/launcheritem.qml index 185facdf..882c5886 100644 --- a/shell-launcher-applet/package/launcheritem.qml +++ b/shell-launcher-applet/package/launcheritem.qml @@ -109,7 +109,8 @@ AppletItem { isFavoriteItem: false, hideFavoriteMenu: true, hideDisplayScalingMenu: Math.abs(DesktopIntegration.scaleFactor - 1.0) < 0.0001, - hideMoveToTopMenu: true + hideMoveToTopMenu: true, + autoStart: model.autoStart }, additionalProps)); menu.closed.connect(menu.destroy) menu.popup(); diff --git a/src/ddeintegration/appmgr.cpp b/src/ddeintegration/appmgr.cpp index d076217b..01c896a6 100644 --- a/src/ddeintegration/appmgr.cpp +++ b/src/ddeintegration/appmgr.cpp @@ -124,12 +124,6 @@ bool AppMgr::launchApp(const QString &desktopId, const QString &activationToken) return true; } -bool AppMgr::autoStart(const QString &desktopId) -{ - const QVariant value = instance()->readProperty(desktopId, QStringLiteral("AutoStart")); - return value.isValid() && value.toBool(); -} - void AppMgr::setAutoStart(const QString &desktopId, bool enabled) { instance()->setProperty(desktopId, QStringLiteral("AutoStart"), enabled); diff --git a/src/ddeintegration/appmgr.h b/src/ddeintegration/appmgr.h index 8cd00373..890bc11f 100644 --- a/src/ddeintegration/appmgr.h +++ b/src/ddeintegration/appmgr.h @@ -19,7 +19,6 @@ class AppMgr final : public QObject static AppMgr *instance(); static bool launchApp(const QString &desktopId, const QString &activationToken = {}); - static bool autoStart(const QString &desktopId); static void setAutoStart(const QString &desktopId, bool enabled); static bool disableScale(const QString &desktopId); static void setDisableScale(const QString &desktopId, bool disabled);