Skip to content
Snippets Groups Projects
Commit 4d765cd8 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Reduce sync interval when display is off to 30 seconds

parent 6ba5c87e
No related branches found
No related tags found
No related merge requests found
Pipeline #69 passed
......@@ -23,7 +23,7 @@ let g:ale_linters = {
function! Formatonsave()
let l:formatdiff = 1
pyf /usr/lib/llvm/8/share/clang/clang-format.py
py3f /usr/lib/llvm/10/share/clang/clang-format.py
endfunction
autocmd BufWritePre *.h,*.cc,*.cpp call Formatonsave()
......
......@@ -19,6 +19,7 @@ ssl_dep = dependency('OpenSSL', static: true)
sailfish_dep = dependency('sailfishapp')
#networkstate_dep = dependency('statefs-qt5')
networkstate_dep = dependency('contextkit-statefs')
keepalive_dep = dependency('keepalive')
threads_dep = dependency('threads')
# generate dbus
......@@ -30,7 +31,7 @@ gen_xml = custom_target('gen-dbus-xml',
install: true,
install_dir: 'share/dbus-1/interfaces')
deps = [qt5_dep, zlib_dep, olm_dep, matrix_dep, json_dep, ssl_dep, sailfish_dep, threads_dep, boost_dep, networkstate_dep]
deps = [qt5_dep, zlib_dep, olm_dep, matrix_dep, json_dep, ssl_dep, sailfish_dep, threads_dep, boost_dep, networkstate_dep, keepalive_dep]
defines = ['-DBOOST_ASIO_DISABLE_EPOLL']
extra_flags = ['-Winvalid-pch']
......
......@@ -35,6 +35,7 @@ BuildRequires: pkgconfig(nemonotifications-qt5)
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(statefs-qt5)
BuildRequires: pkgconfig(contextkit-statefs)
BuildRequires: pkgconfig(keepalive)
BuildRequires: cmake
BuildRequires: ninja
BuildRequires: meson
......@@ -73,7 +74,7 @@ export CMAKE_PREFIX_PATH=%{bdir}/%{name}-cget/
#rm -rf %{bdir}/build
[ -d %{bdir}/build ] || (mkdir %{bdir}/build && meson --prefix=/usr -Dcpp_args='-Og -std=c++17' -Dcmake_prefix_path=%{bdir}/%{name}-cget/ %{bdir}/build)
[ -d %{bdir}/build ] || (mkdir %{bdir}/build && meson --prefix=/usr -Dcpp_args='-Og -std=c++17 -Wno-psabi' -Dcmake_prefix_path=%{bdir}/%{name}-cget/ %{bdir}/build)
#meson configure --prefix=/usr -Dcpp_args=-Og -Dcmake_prefix_path=%{bdir}/%{name}-cget/ %{bdir}/build
ninja -C %{bdir}/build
......
......@@ -29,6 +29,7 @@ PkgConfigBR:
- openssl
- statefs-qt5
- contextkit-statefs
- keepalive
# Build dependencies without a pkgconfig setup can be listed here
# PkgBR:
......@@ -51,6 +52,7 @@ Files:
- '%{_datadir}/%{name}'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/icons/hicolor/*/apps/%{name}.png'
- '%{_datadir}/dbus-1/interfaces/dev.neko.spoon.xml'
# For more information about yaml and what's supported in Sailfish OS
# build system, please see https://wiki.merproject.org/wiki/Spectacle
......@@ -5,6 +5,9 @@
#include <contextproperty.h>
#include <displayblanking.h>
#include <backgroundactivity.h>
#include <QtDebug>
#include "client.h"
......@@ -17,8 +20,33 @@ bool first_val = true;
Sync::Sync(RoomListModel &rooms, Login *login, QObject *parent)
: QThread(parent), rooms(rooms), stop(false), exit(false) {
static ContextProperty *prop = new ContextProperty("Internet.NetworkState");
activity = new BackgroundActivity(this);
display = new DisplayBlanking(this);
connect(activity, &BackgroundActivity::running, this, &Sync::sync, Qt::QueuedConnection);
connect(this, &Sync::nextSync, this, &Sync::sync, Qt::QueuedConnection);
// needs this, because we can wait only on this thread
connect(
this, &Sync::queueNextSync, this,
[this]() {
if (display->status() == DisplayBlanking::Status::On) {
qDebug("Display On");
emit nextSync();
} else {
qDebug("Display Off");
activity->wait(BackgroundActivity::ThirtySeconds);
}
},
Qt::QueuedConnection);
// change to quick sync loop as soon as display gets switched on
connect(display, &DisplayBlanking::statusChanged, this, [this]() {
if (display->status() == DisplayBlanking::Status::On && isRunning()) {
activity->stop();
emit queueNextSync();
}
});
connect(prop, &ContextProperty::valueChanged, [this]() {
if (first_val) {
first_val = false;
......@@ -106,7 +134,8 @@ void Sync::sync() {
if (err->error_code == boost::system::errc::network_unreachable) {
qDebug() << "Network changed, trying again";
emit nextSync();
emit nextSync();
}
return;
......@@ -195,6 +224,6 @@ void Sync::sync() {
emit roomUpdated(room);
}
emit nextSync();
emit queueNextSync();
});
}
......@@ -10,6 +10,9 @@
#include "login.h"
#include "models/roomlistmodel.h"
class BackgroundActivity;
class DisplayBlanking;
class Sync : public QThread {
Q_OBJECT
......@@ -34,6 +37,7 @@ class Sync : public QThread {
void newRoom(QSharedPointer<Room> room);
void roomUpdated(QSharedPointer<Room> room);
void nextSync();
void queueNextSync();
private:
RoomListModel &rooms;
......@@ -41,4 +45,6 @@ class Sync : public QThread {
QMutex mutex;
std::atomic<bool> stop, exit;
std::string since;
BackgroundActivity *activity;
DisplayBlanking *display;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment