diff --git a/components/mobileshell/qml/components/AppLaunch.qml b/components/mobileshell/qml/components/AppLaunch.qml index 1cd5cc68..b3bc086b 100644 --- a/components/mobileshell/qml/components/AppLaunch.qml +++ b/components/mobileshell/qml/components/AppLaunch.qml @@ -2,20 +2,38 @@ // SPDX-License-Identifier: GPL-2.0-or-later import QtQuick -import org.kde.plasma.private.mobileshell as MobileShell -import org.kde.plasma.private.mobileshell.windowplugin as WindowPlugin + +// NOTE: This is a singleton in the mobileshell library, so we need to be careful to +// make this load as fast as possible (since it may be loaded in other processes ex. lockscreen). pragma Singleton QtObject { + id: root + /** * Activates an application by storage id if it is already running, or launch the application. */ function launchOrActivateApp(storageId) { - const launched = WindowPlugin.WindowUtil.activateWindowByStorageId(storageId); - if (!launched) { - MobileShell.ShellUtil.launchApp(storageId); - } + // We don't want to import WindowPlugin initially because it has side-effects and slows down initial load. + // -> only import it if we actually run the function + const component = Qt.createQmlObject(` + import QtQuick + import org.kde.plasma.private.mobileshell as MobileShell + import org.kde.plasma.private.mobileshell.windowplugin as WindowPlugin + + QtObject { + Component.onCompleted: { + const launched = WindowPlugin.WindowUtil.activateWindowByStorageId("${storageId}"); + + if (!launched) { + MobileShell.ShellUtil.launchApp("${storageId}"); + } + } + } + `, root, "runSnippet"); + + component.destroy(); } } diff --git a/components/mobileshell/qml/components/Constants.qml b/components/mobileshell/qml/components/Constants.qml index 3b74ec8f..a2b200c7 100644 --- a/components/mobileshell/qml/components/Constants.qml +++ b/components/mobileshell/qml/components/Constants.qml @@ -5,6 +5,9 @@ import QtQuick import org.kde.plasma.core as PlasmaCore +// NOTE: This is a singleton in the mobileshell library, so we need to be careful to +// make this load as fast as possible (since it may be loaded in other processes ex. lockscreen). + pragma Singleton QtObject { diff --git a/components/mobileshell/shellutil.cpp b/components/mobileshell/shellutil.cpp index 1aeb6ccb..efba4f37 100644 --- a/components/mobileshell/shellutil.cpp +++ b/components/mobileshell/shellutil.cpp @@ -26,16 +26,6 @@ ShellUtil::ShellUtil(QObject *parent) : QObject{parent} , m_localeConfig{KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig)} { - m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig); - - // watch for changes to locale config, to update 12/24 hour time - connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void { - if (group.name() == "Locale") { - // we have to reparse for new changes (from system settings) - m_localeConfig->reparseConfiguration(); - Q_EMIT isSystem24HourFormatChanged(); - } - }); } ShellUtil *ShellUtil::instance() @@ -71,6 +61,20 @@ void ShellUtil::executeCommand(const QString &command) bool ShellUtil::isSystem24HourFormat() { + // only load the config watcher if this function is actually used once + if (!m_localeConfigWatcher) { + m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig); + + // watch for changes to locale config, to update 12/24 hour time + connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void { + if (group.name() == "Locale") { + // we have to reparse for new changes (from system settings) + m_localeConfig->reparseConfiguration(); + Q_EMIT isSystem24HourFormatChanged(); + } + }); + } + KConfigGroup localeSettings = KConfigGroup(m_localeConfig, "Locale"); QString timeFormat = localeSettings.readEntry("TimeFormat", QStringLiteral(FORMAT24H));