Add splash screen for macOS

This commit is contained in:
Weixuan XIAO 2019-08-14 16:15:47 +02:00 committed by Nicolas Fella
parent 3bb1814faa
commit 3a700d9bcd

View file

@ -22,6 +22,7 @@
#include <QProcess> #include <QProcess>
#include <QThread> #include <QThread>
#include <QMessageBox> #include <QMessageBox>
#include <QSplashScreen>
#ifdef QSYSTRAY #ifdef QSYSTRAY
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
@ -58,10 +59,15 @@ int main(int argc, char** argv)
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QIcon kdeconnectIcon = QIcon::fromTheme(QStringLiteral("kdeconnect"));
QPixmap splashPixmap(kdeconnectIcon.pixmap(256, 256));
QSplashScreen splash(splashPixmap);
splash.show();
// Unset launchctl env, avoid block // Unset launchctl env, avoid block
DBusHelper::macosUnsetLaunchctlEnv(); DBusHelper::macosUnsetLaunchctlEnv();
// Start kdeconnectd // Start kdeconnectd
splash.showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
QProcess kdeconnectdProcess; QProcess kdeconnectdProcess;
if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"))) { if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"))) {
kdeconnectdProcess.startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd")); kdeconnectdProcess.startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"));
@ -77,6 +83,7 @@ int main(int argc, char** argv)
// Wait for dbus daemon env // Wait for dbus daemon env
QProcess getLaunchdDBusEnv; QProcess getLaunchdDBusEnv;
splash.showMessage(i18n("Waiting DBus") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
int retry = 0; int retry = 0;
do { do {
getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl"));
@ -103,10 +110,12 @@ int main(int argc, char** argv)
return -1; return -1;
} else { } else {
QThread::sleep(1); // Retry after 1s QThread::sleep(3); // Retry after 3s
retry++; retry++;
} }
} while(true); } while(true);
splash.showMessage(i18n("Loading modules") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
#endif #endif
KDBusService dbusService(KDBusService::Unique); KDBusService dbusService(KDBusService::Unique);
@ -217,5 +226,9 @@ int main(int argc, char** argv)
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
#ifdef Q_OS_MAC
splash.finish(nullptr);
#endif
return app.exec(); return app.exec();
} }