Navigation Menu

Skip to content

Commit

Permalink
use libkeepalive to wakeup daemon
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piggz committed Oct 23, 2018
1 parent a98533b commit ee52c8c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/backends/lan/lanlinkprovider.cpp
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion sfos/CMakeLists.txt
Expand Up @@ -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
)
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions sfos/qml/pages/FindDevices.qml
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions sfos/rpm/kdeconnect-sfos.spec
Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 48 additions & 3 deletions sfos/sailfishdaemon.cpp
Expand Up @@ -30,6 +30,9 @@
#include "kdeconnect-version.h"

#include <notification.h>
#include <backgroundactivity.h>
#include <QFile>
#include <QTextStream>

class SailfishDaemon : public Daemon
{
Expand All @@ -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
{
Expand Down Expand Up @@ -93,11 +102,47 @@ class SailfishDaemon : public Daemon


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"));
Expand Down

0 comments on commit ee52c8c

Please sign in to comment.