Merge pull request #2119 from nextcloud/sbeyer-fix-segv-on-exit

Fix SEGV (due to circular ownership) at exit
This commit is contained in:
Kevin Ottens 2020-06-24 18:05:37 +02:00 committed by GitHub
commit cbea0e7134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View file

@ -32,6 +32,7 @@
#include "cloudproviders/cloudprovidermanager.h"
#endif
#include <QQmlApplicationEngine>
#include <QDesktopServices>
#include <QDir>
#include <QMessageBox>
@ -66,7 +67,7 @@ ownCloudGui::ownCloudGui(Application *parent)
, _app(parent)
{
_tray = Systray::instance();
_tray->setParent(this);
_tray->setTrayEngine(new QQmlApplicationEngine(this));
// for the beginning, set the offline icon until the account was verified
_tray->setIcon(Theme::instance()->folderOfflineIcon(/*systray?*/ true));

View file

@ -49,12 +49,17 @@ Systray *Systray::instance()
return _instance;
}
Systray::Systray()
: _trayEngine(new QQmlApplicationEngine(this))
void Systray::setTrayEngine(QQmlApplicationEngine *trayEngine)
{
_trayEngine = trayEngine;
_trayEngine->addImportPath("qrc:/qml/theme");
_trayEngine->addImageProvider("avatars", new ImageProvider);
}
Systray::Systray()
: QSystemTrayIcon(nullptr)
{
qmlRegisterSingletonType<UserModel>("com.nextcloud.desktopclient", 1, 0, "UserModel",
[](QQmlEngine *, QJSEngine *) -> QObject * {
return UserModel::instance();
@ -82,18 +87,22 @@ Systray::Systray()
void Systray::create()
{
if (_trayEngine) {
if (!AccountManager::instance()->accounts().isEmpty()) {
_trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel());
}
_trayEngine->load(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"));
}
hideWindow();
emit activated(QSystemTrayIcon::ActivationReason::Unknown);
}
void Systray::slotNewUserSelected()
{
if (_trayEngine) {
// Change ActivityModel
_trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel());
}
// Rebuild App list
UserAppsModel::instance()->buildAppList();

View file

@ -49,6 +49,7 @@ public:
enum class TaskBarPosition { Bottom, Left, Top, Right };
Q_ENUM(TaskBarPosition);
void setTrayEngine(QQmlApplicationEngine *trayEngine);
void create();
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information);
void setToolTip(const QString &tip);
@ -89,7 +90,7 @@ private:
bool _isOpen = false;
bool _syncIsPaused = false;
QQmlApplicationEngine *_trayEngine;
QPointer<QQmlApplicationEngine> _trayEngine;
};
} // namespace OCC