use libkeepalive to wakeup daemon

Summary:
Main change is to use libkeepalive to wake up the system to ensure connections stay alive

Other minor changes are:
-Log daemon messages for debugging purposes
-Add way to forece refresh of device list
-Minor spec improvements

The keepalive changes certainly seem to help, not sure if it completely solves the problems
The logging changes are temporary, and I could use them locally, but they only affect sailfish users
Im not sure if the refresh method is correct, but seems to force the daemon to check for devices

Reviewers: #kde_connect, nicolasfella, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D15414
This commit is contained in:
Adam Pigg 2018-10-23 08:30:48 +01:00
parent a98533b8f4
commit ee52c8cd03
6 changed files with 67 additions and 10 deletions

View file

@ -330,7 +330,7 @@ void LanLinkProvider::sslErrors(const QList<QSslError>& errors)
//I'm the new device and this is the answer to my UDP identity packet (no data received yet). They are connecting to us through TCP, and they should send an identity.
void LanLinkProvider::newConnection()
{
//qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection";
qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection";
while (m_server->hasPendingConnections()) {
QSslSocket* socket = m_server->nextPendingConnection();
@ -353,7 +353,7 @@ void LanLinkProvider::dataReceived()
const QByteArray data = socket->readLine();
//qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
NetworkPacket* np = new NetworkPacket(QLatin1String(""));
bool success = NetworkPacket::unserialize(data, np);

View file

@ -5,13 +5,13 @@ install(FILES kdeconnect_plugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
add_subdirectory(ping)
add_subdirectory(battery)
add_subdirectory(sendnotifications)
add_subdirectory(clipboard)
if (NOT WIN32)
add_subdirectory(mpriscontrol)
endif()
if(NOT SAILFISHOS)
add_subdirectory(clipboard)
add_subdirectory(contacts)
add_subdirectory(share)
add_subdirectory(remotekeyboard)

View file

@ -3,6 +3,9 @@ find_package(Qt5 5.2 REQUIRED COMPONENTS DBus)
pkg_check_modules(NNQT5 REQUIRED nemonotifications-qt5)
include_directories(${NNQT5_INCLUDE_DIRS})
pkg_check_modules(KEEPALIVE REQUIRED keepalive)
include_directories(${KEEPALIVE_INCLUDE_DIRS})
set(kdeconnectsfos_SRCS
kdeconnect-sfos.cpp
)
@ -16,7 +19,7 @@ INSTALL( DIRECTORY qml DESTINATION ${SHARE_INSTALL_PREFIX}/kdeconnect-sfos/ )
#Daemon
add_executable(kdeconnectd sailfishdaemon.cpp)
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons ${NNQT5_LIBRARIES} KF5::I18n)
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons ${NNQT5_LIBRARIES} KF5::I18n ${KEEPALIVE_LIBRARIES})
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)

View file

@ -46,6 +46,15 @@ Page {
title: qsTr("Devices")
}
PullDownMenu {
MenuItem {
text: qsTr("Refresh")
onClicked: {
DaemonDbusInterface.forceOnNetworkChange();
}
}
}
// Place our content in a Column. The PageHeader is always placed at the top
// of the page, followed by our content.

View file

@ -9,13 +9,12 @@ Name: kdeconnect-sfos
# << macros
Summary: KDEConnect client for Sailfish
Version: 0.1
Version: 1.3.1
Release: 1
Group: Qt/Qt
License: LICENSE
URL: http://example.org/
Source0: %{name}-%{version}.tar.bz2
Source100: kdeconnect-sfos.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
Requires: qt5-qtquickcontrols-layouts
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
@ -32,9 +31,10 @@ BuildRequires: kdbusaddons-devel >= 5.31.0
BuildRequires: ki18n-devel >= 5.31.0
BuildRequires: kconfig-devel >= 5.31.0
BuildRequires: kiconthemes-devel >= 5.31.0
BuildRequires: pkgconfig(keepalive)
%description
Short description of my Sailfish OS Application
KDE Connect provides several features to integrate your phone and your computer
%prep

View file

@ -30,6 +30,9 @@
#include "kdeconnect-version.h"
#include <notification.h>
#include <backgroundactivity.h>
#include <QFile>
#include <QTextStream>
class SailfishDaemon : public Daemon
{
@ -38,8 +41,14 @@ class SailfishDaemon : public Daemon
public:
SailfishDaemon(QObject* parent = Q_NULLPTR)
: Daemon(parent)
, m_nam(Q_NULLPTR)
{}
, m_background(new BackgroundActivity())
{
connect(m_background, &BackgroundActivity::running,
[=]( ) { qDebug() << "Received wakeup";
m_background->wait(BackgroundActivity::ThirtySeconds);
} );
m_background->wait(BackgroundActivity::ThirtySeconds);
}
void askPairingConfirmation(Device* device) override
{
@ -93,11 +102,47 @@ public:
private:
QNetworkAccessManager* m_nam;
QNetworkAccessManager* m_nam = nullptr;
BackgroundActivity *m_background = nullptr;
};
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString txt;
QString typ;
switch (type) {
case QtDebugMsg:
typ = "Debug";
break;
case QtInfoMsg:
typ = "Info";
break;
case QtWarningMsg:
typ = "Warning";
break;
case QtCriticalMsg:
typ = "Critical";
break;
case QtFatalMsg:
break;
}
txt = QString("%1 %2: %3 (%4:%5, %6)").arg(QDateTime::currentDateTime().toString("yyyyMMdd:HHmmss")).arg(typ).arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
QFile outFile("/home/nemo/kdeconnectd.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char* argv[])
{
qInstallMessageHandler(myMessageOutput); // Install the handler
QCoreApplication app(argc, argv);
app.setApplicationName(QStringLiteral("kdeconnectd"));