mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
mobileshell: Dynamically load in heavy dependencies for singletons
This commit is contained in:
parent
2d1610aaa2
commit
6160280b0c
3 changed files with 41 additions and 16 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue