First experiments with keeping me alive in the background

This commit is contained in:
Sebastian Wolf 2020-12-09 23:57:09 +01:00
parent f6d72d8ef1
commit af2a4b0be7
19 changed files with 174 additions and 12 deletions

View file

@ -62,6 +62,16 @@ Page {
} }
} }
TextSwitch {
checked: appSettings.stayInBackground
text: qsTr("Stay in background")
description: qsTr("Fernschreiber will stay active in the background after the app was closed")
automaticCheck: false
onClicked: {
appSettings.stayInBackground = !checked
}
}
ComboBox { ComboBox {
id: feedbackComboBox id: feedbackComboBox
label: qsTr("Notification feedback") label: qsTr("Notification feedback")

View file

@ -20,9 +20,13 @@
#define DEBUG_MODULE AppSettings #define DEBUG_MODULE AppSettings
#include "debuglog.h" #include "debuglog.h"
#include <QDBusInterface>
#include <QDBusReply>
namespace { namespace {
const QString KEY_SEND_BY_ENTER("sendByEnter"); const QString KEY_SEND_BY_ENTER("sendByEnter");
const QString KEY_USE_OPEN_WITH("useOpenWith"); const QString KEY_USE_OPEN_WITH("useOpenWith");
const QString KEY_STAY_IN_BACKGROUND("stayInBackground");
const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages"); const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages");
const QString KEY_ANIMATE_STICKERS("animateStickers"); const QString KEY_ANIMATE_STICKERS("animateStickers");
const QString KEY_NOTIFICATION_TURNS_DISPLAY_ON("notificationTurnsDisplayOn"); const QString KEY_NOTIFICATION_TURNS_DISPLAY_ON("notificationTurnsDisplayOn");
@ -62,6 +66,20 @@ void AppSettings::setUseOpenWith(bool useOpenWith)
} }
} }
bool AppSettings::getStayInBackground() const
{
return settings.value(KEY_STAY_IN_BACKGROUND, false).toBool();
}
void AppSettings::setStayInBackground(bool stayInBackground)
{
if (getStayInBackground() != stayInBackground) {
LOG(KEY_STAY_IN_BACKGROUND << stayInBackground);
settings.setValue(KEY_STAY_IN_BACKGROUND, stayInBackground);
emit stayInBackgroundChanged();
}
}
bool AppSettings::showStickersAsImages() const bool AppSettings::showStickersAsImages() const
{ {
return settings.value(KEY_SHOW_STICKERS_AS_IMAGES, true).toBool(); return settings.value(KEY_SHOW_STICKERS_AS_IMAGES, true).toBool();
@ -131,3 +149,20 @@ void AppSettings::setStorageOptimizer(bool enable)
emit storageOptimizerChanged(); emit storageOptimizerChanged();
} }
} }
bool AppSettings::isAppRunning()
{
LOG("Checking via D-Bus if app is already running...");
QDBusInterface dBusInterface("de.ygriega.fernschreiber", "/de/ygriega/fernschreiber", "", QDBusConnection::sessionBus());
if (dBusInterface.isValid()) {
QDBusReply<bool> reply = dBusInterface.call("showUI");
if (reply.isValid()) {
return reply.value();
}
LOG("D-Bus call to show UI failed. App doesn't seem to be running (properly)!" << reply.error().message());
return false;
} else {
LOG("Fernschreiber D-Bus session interface is not existing. App doesn't seem to be running!");
return false;
}
}

View file

@ -20,11 +20,13 @@
#include <QObject> #include <QObject>
#include <QSettings> #include <QSettings>
#include <QQuickView>
class AppSettings : public QObject { class AppSettings : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged) Q_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged)
Q_PROPERTY(bool useOpenWith READ getUseOpenWith WRITE setUseOpenWith NOTIFY useOpenWithChanged) Q_PROPERTY(bool useOpenWith READ getUseOpenWith WRITE setUseOpenWith NOTIFY useOpenWithChanged)
Q_PROPERTY(bool stayInBackground READ getStayInBackground WRITE setStayInBackground NOTIFY stayInBackgroundChanged)
Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged) Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged)
Q_PROPERTY(bool animateStickers READ animateStickers WRITE setAnimateStickers NOTIFY animateStickersChanged) Q_PROPERTY(bool animateStickers READ animateStickers WRITE setAnimateStickers NOTIFY animateStickersChanged)
Q_PROPERTY(bool notificationTurnsDisplayOn READ notificationTurnsDisplayOn WRITE setNotificationTurnsDisplayOn NOTIFY notificationTurnsDisplayOnChanged) Q_PROPERTY(bool notificationTurnsDisplayOn READ notificationTurnsDisplayOn WRITE setNotificationTurnsDisplayOn NOTIFY notificationTurnsDisplayOnChanged)
@ -48,6 +50,9 @@ public:
bool getUseOpenWith() const; bool getUseOpenWith() const;
void setUseOpenWith(bool useOpenWith); void setUseOpenWith(bool useOpenWith);
bool getStayInBackground() const;
void setStayInBackground(bool stayInBackground);
bool showStickersAsImages() const; bool showStickersAsImages() const;
void setShowStickersAsImages(bool showAsImages); void setShowStickersAsImages(bool showAsImages);
@ -63,9 +68,12 @@ public:
bool storageOptimizer() const; bool storageOptimizer() const;
void setStorageOptimizer(bool enable); void setStorageOptimizer(bool enable);
bool isAppRunning();
signals: signals:
void sendByEnterChanged(); void sendByEnterChanged();
void useOpenWithChanged(); void useOpenWithChanged();
void stayInBackgroundChanged();
void showStickersAsImagesChanged(); void showStickersAsImagesChanged();
void animateStickersChanged(); void animateStickersChanged();
void notificationTurnsDisplayOnChanged(); void notificationTurnsDisplayOnChanged();

View file

@ -26,6 +26,11 @@ DBusAdaptor::DBusAdaptor(QObject *parent): QDBusAbstractAdaptor(parent)
{ {
} }
void DBusAdaptor::setAppView(QQuickView *appView)
{
this->appView = appView;
}
void DBusAdaptor::openMessage(const QString &chatId, const QString &messageId) void DBusAdaptor::openMessage(const QString &chatId, const QString &messageId)
{ {
LOG("Open Message" << chatId << messageId); LOG("Open Message" << chatId << messageId);
@ -39,3 +44,10 @@ void DBusAdaptor::openUrl(const QStringList &arguments)
emit pleaseOpenUrl(arguments.first()); emit pleaseOpenUrl(arguments.first());
} }
} }
bool DBusAdaptor::showUI()
{
LOG("UI shall wake up!");
this->appView->showFullScreen();
return true;
}

View file

@ -21,6 +21,7 @@
#define DBUSADAPTOR_H #define DBUSADAPTOR_H
#include <QDBusAbstractAdaptor> #include <QDBusAbstractAdaptor>
#include <QQuickView>
class DBusAdaptor : public QDBusAbstractAdaptor class DBusAdaptor : public QDBusAbstractAdaptor
{ {
@ -31,6 +32,8 @@ class DBusAdaptor : public QDBusAbstractAdaptor
public: public:
DBusAdaptor(QObject *parent); DBusAdaptor(QObject *parent);
void setAppView(QQuickView* appView);
signals: signals:
void pleaseOpenMessage(const QString &chatId, const QString &messageId); void pleaseOpenMessage(const QString &chatId, const QString &messageId);
void pleaseOpenUrl(const QString &url); void pleaseOpenUrl(const QString &url);
@ -38,6 +41,10 @@ signals:
public slots: public slots:
void openMessage(const QString &chatId, const QString &messageId); void openMessage(const QString &chatId, const QString &messageId);
void openUrl(const QStringList &arguments); void openUrl(const QStringList &arguments);
bool showUI();
private:
QQuickView *appView;
}; };

View file

@ -39,6 +39,7 @@
#include "namedaction.h" #include "namedaction.h"
#include "notificationmanager.h" #include "notificationmanager.h"
#include "mceinterface.h" #include "mceinterface.h"
#include "dbusinterface.h"
#include "dbusadaptor.h" #include "dbusadaptor.h"
#include "processlauncher.h" #include "processlauncher.h"
#include "stickermanager.h" #include "stickermanager.h"
@ -75,6 +76,19 @@ int main(int argc, char *argv[])
context->setContextProperty("appSettings", appSettings); context->setContextProperty("appSettings", appSettings);
qmlRegisterUncreatableType<AppSettings>(uri, 1, 0, "AppSettings", QString()); qmlRegisterUncreatableType<AppSettings>(uri, 1, 0, "AppSettings", QString());
// if (appSettings->isAppRunning()) {
// return 0;
// }
if (appSettings->getStayInBackground()) {
app.data()->setQuitOnLastWindowClosed(false);
}
DBusInterface *dBusInterface = new DBusInterface(view.data());
DBusAdaptor *dBusAdaptor = dBusInterface->getDBusAdaptor();
dBusAdaptor->setAppView(view.data());
context->setContextProperty("dBusAdaptor", dBusAdaptor);
MceInterface *mceInterface = new MceInterface(view.data()); MceInterface *mceInterface = new MceInterface(view.data());
TDLibWrapper *tdLibWrapper = new TDLibWrapper(appSettings, mceInterface, view.data()); TDLibWrapper *tdLibWrapper = new TDLibWrapper(appSettings, mceInterface, view.data());
context->setContextProperty("tdLibWrapper", tdLibWrapper); context->setContextProperty("tdLibWrapper", tdLibWrapper);
@ -83,9 +97,6 @@ int main(int argc, char *argv[])
FernschreiberUtils *fernschreiberUtils = new FernschreiberUtils(view.data()); FernschreiberUtils *fernschreiberUtils = new FernschreiberUtils(view.data());
context->setContextProperty("fernschreiberUtils", fernschreiberUtils); context->setContextProperty("fernschreiberUtils", fernschreiberUtils);
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
context->setContextProperty("dBusAdaptor", dBusAdaptor);
ChatListModel chatListModel(tdLibWrapper); ChatListModel chatListModel(tdLibWrapper);
context->setContextProperty("chatListModel", &chatListModel); context->setContextProperty("chatListModel", &chatListModel);

View file

@ -63,7 +63,6 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
tdLibDatabaseDirectory.mkpath(tdLibDatabaseDirectoryPath); tdLibDatabaseDirectory.mkpath(tdLibDatabaseDirectoryPath);
} }
this->dbusInterface = new DBusInterface(this);
if (this->appSettings->getUseOpenWith()) { if (this->appSettings->getUseOpenWith()) {
this->initializeOpenWith(); this->initializeOpenWith();
} else { } else {
@ -1043,11 +1042,6 @@ void TDLibWrapper::registerJoinChat()
this->joinChatRequested = false; this->joinChatRequested = false;
} }
DBusAdaptor *TDLibWrapper::getDBusAdaptor()
{
return this->dbusInterface->getDBusAdaptor();
}
void TDLibWrapper::handleVersionDetected(const QString &version) void TDLibWrapper::handleVersionDetected(const QString &version)
{ {
this->version = version; this->version = version;

View file

@ -117,8 +117,6 @@ public:
Q_INVOKABLE bool getJoinChatRequested(); Q_INVOKABLE bool getJoinChatRequested();
Q_INVOKABLE void registerJoinChat(); Q_INVOKABLE void registerJoinChat();
DBusAdaptor *getDBusAdaptor();
// Direct TDLib functions // Direct TDLib functions
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject); Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber); Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
@ -278,7 +276,6 @@ private:
AppSettings *appSettings; AppSettings *appSettings;
MceInterface *mceInterface; MceInterface *mceInterface;
TDLibReceiver *tdLibReceiver; TDLibReceiver *tdLibReceiver;
DBusInterface *dbusInterface;
QString version; QString version;
TDLibWrapper::AuthorizationState authorizationState; TDLibWrapper::AuthorizationState authorizationState;
QVariantMap authorizationStateData; QVariantMap authorizationStateData;

View file

@ -1294,6 +1294,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Speicheroptimierer einschalten</translation> <translation>Speicheroptimierer einschalten</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1294,6 +1294,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Enable storage optimizer</translation> <translation>Enable storage optimizer</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1275,6 +1275,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Optimizador de almacenamiento</translation> <translation>Optimizador de almacenamiento</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1295,6 +1295,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Käytä tallennustilan optimointia</translation> <translation>Käytä tallennustilan optimointia</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1275,6 +1275,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1294,6 +1294,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Abilita ottimizzazione memoria</translation> <translation>Abilita ottimizzazione memoria</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1313,6 +1313,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Włącz optymalizację pamięci</translation> <translation>Włącz optymalizację pamięci</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1313,6 +1313,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Включить оптимизацию хранилища</translation> <translation>Включить оптимизацию хранилища</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1294,6 +1294,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation>Aktivera lagringsoptimering</translation> <translation>Aktivera lagringsoptimering</translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1275,6 +1275,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1294,6 +1294,14 @@
<source>Enable storage optimizer</source> <source>Enable storage optimizer</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Stay in background</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fernschreiber will stay active in the background after the app was closed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>