Skip to content

Commit

Permalink
[foilnotes] Use wakeup timer for auto-lock
Browse files Browse the repository at this point in the history
Normal timers take forever to trigger because the system gets suspended
when the screen turns off.
  • Loading branch information
monich committed Oct 6, 2024
1 parent 0657687 commit e6163da
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
6 changes: 4 additions & 2 deletions app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ openrepos {

TARGET = $${PREFIX}-$${NAME}
CONFIG += sailfishapp link_pkgconfig
PKGCONFIG += sailfishapp mlite5 glib-2.0 gobject-2.0 gio-unix-2.0
PKGCONFIG += sailfishapp mlite5 keepalive glib-2.0 gobject-2.0 gio-unix-2.0
QT += qml quick sql

isEmpty(VERSION) {
Expand Down Expand Up @@ -261,6 +261,7 @@ HEADERS += \
$${HARBOUR_LIB_INCLUDE}/HarbourSystemInfo.h \
$${HARBOUR_LIB_INCLUDE}/HarbourSystemState.h \
$${HARBOUR_LIB_INCLUDE}/HarbourTask.h \
$${HARBOUR_LIB_INCLUDE}/HarbourWakeupTimer.h \
$${HARBOUR_LIB_SRC}/HarbourMce.h

SOURCES += \
Expand All @@ -273,7 +274,8 @@ SOURCES += \
$${HARBOUR_LIB_SRC}/HarbourQrCodeImageProvider.cpp \
$${HARBOUR_LIB_SRC}/HarbourSystemInfo.cpp \
$${HARBOUR_LIB_SRC}/HarbourSystemState.cpp \
$${HARBOUR_LIB_SRC}/HarbourTask.cpp
$${HARBOUR_LIB_SRC}/HarbourTask.cpp \
$${HARBOUR_LIB_SRC}/HarbourWakeupTimer.cpp

HARBOUR_QML_COMPONENTS = \
$${HARBOUR_LIB_QML}/HarbourColorEditorDialog.qml \
Expand Down
2 changes: 1 addition & 1 deletion harbour-lib
6 changes: 4 additions & 2 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ ApplicationWindow {

function resetAutoLock() {
lockTimer.stop()
if (FoilNotesSettings.autoLock && HarbourSystemState.locked) {
if (FoilNotesModel.foilState === FoilNotesModel.FoilNotesReady &&
FoilNotesSettings.autoLock && HarbourSystemState.locked) {
lockTimer.start()
}
}

Timer {
HarbourWakeupTimer {
id: lockTimer

interval: FoilNotesSettings.autoLockTime
Expand All @@ -64,6 +65,7 @@ ApplicationWindow {
Connections {
target: FoilNotesModel
onEncryptionDone: FoilNotesPlaintextModel.onEncryptionDone(requestId, success)
onFoilStateChanged: resetAutoLock()
}

Binding {
Expand Down
1 change: 1 addition & 0 deletions rpm/harbour-foilnotes.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Source0: %{name}-%{version}.tar.gz
Requires: sailfishsilica-qt5
Requires: qt5-qtsvg-plugin-imageformat-svg
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(keepalive)
BuildRequires: pkgconfig(libcrypto)
BuildRequires: pkgconfig(sailfishapp)
BuildRequires: pkgconfig(Qt5Quick)
Expand Down
74 changes: 44 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
/*
* Copyright (C) 2018-2024 Slava Monich <[email protected]>
* Copyright (C) 2018-2022 Jolla Ltd.
* Copyright (C) 2018-2022 Slava Monich <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* any official policies, either expressed or implied.
*/

#include "FoilNotesDefs.h"
Expand All @@ -54,6 +60,7 @@
#include "HarbourOrganizeListModel.h"
#include "HarbourProcessState.h"
#include "HarbourSystemState.h"
#include "HarbourWakeupTimer.h"

#include <sailfishapp.h>
#include <gutil_log.h>
Expand All @@ -63,25 +70,32 @@

static void register_types(const char* uri, int v1 = 1, int v2 = 0)
{
qmlRegisterSingletonType<HarbourProcessState>(uri, v1, v2, "HarbourProcessState", HarbourProcessState::createSingleton);
qmlRegisterSingletonType<HarbourSystemState>(uri, v1, v2, "HarbourSystemState", HarbourSystemState::createSingleton);
qmlRegisterSingletonType<FoilNotesHints>(uri, v1, v2, "FoilNotesHints", FoilNotesHints::createSingleton);
qmlRegisterSingletonType<FoilNotesSettings>(uri, v1, v2, "FoilNotesSettings", FoilNotesSettings::createSingleton);
qmlRegisterSingletonType<FoilNotes>(uri, v1, v2, "FoilNotes", FoilNotes::createSingleton);
qmlRegisterSingletonType<FoilNotesModel>(uri, v1, v2, "FoilNotesModel", FoilNotesModel::createSingleton);
qmlRegisterSingletonType<FoilNotesNfcShareService>(uri, v1, v2, "FoilNotesNfcShareService", FoilNotesNfcShareService::createSingleton);
qmlRegisterSingletonType<FoilNotesPlaintextModel>(uri, v1, v2, "FoilNotesPlaintextModel", FoilNotesPlaintextModel::createSingleton);
qmlRegisterType<FoilNotesNfcShareClient>(uri, v1, v2, "FoilNotesNfcShareClient");
qmlRegisterType<FoilNotesSearchModel>(uri, v1, v2, "FoilNotesSearchModel");

qmlRegisterSingletonType<NfcAdapter>(uri, v1, v2, "NfcAdapter", NfcAdapter::createSingleton);
qmlRegisterSingletonType<NfcSystem>(uri, v1, v2, "NfcSystem", NfcSystem::createSingleton);
qmlRegisterType<NfcMode>(uri, v1, v2, "NfcMode");
qmlRegisterType<NfcPeer>(uri, v1, v2, "NfcPeer");

qmlRegisterType<HarbourColorEditorModel>(uri, v1, v2, "HarbourColorEditorModel");
qmlRegisterType<HarbourOrganizeListModel>(uri, v1, v2, "HarbourOrganizeListModel");
qmlRegisterType<HarbourQrCodeGenerator>(uri, v1, v2, "HarbourQrCodeGenerator");
#define REGISTER_TYPE(uri, v1, v2, Class) \
qmlRegisterType<Class>(uri, v1, v2, #Class)
#define REGISTER_SINGLETON_TYPE(uri, v1, v2, Class) \
qmlRegisterSingletonType<Class>(uri, v1, v2, #Class, \
Class::createSingleton)

REGISTER_SINGLETON_TYPE(uri, v1, v2, HarbourProcessState);
REGISTER_SINGLETON_TYPE(uri, v1, v2, HarbourSystemState);
REGISTER_TYPE(uri, v1, v2, HarbourColorEditorModel);
REGISTER_TYPE(uri, v1, v2, HarbourOrganizeListModel);
REGISTER_TYPE(uri, v1, v2, HarbourQrCodeGenerator);
REGISTER_TYPE(uri, v1, v2, HarbourWakeupTimer);

REGISTER_SINGLETON_TYPE(uri, v1, v2, NfcAdapter);
REGISTER_SINGLETON_TYPE(uri, v1, v2, NfcSystem);
REGISTER_TYPE(uri, v1, v2, NfcMode);
REGISTER_TYPE(uri, v1, v2, NfcPeer);

REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotesHints);
REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotesSettings);
REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotes);
REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotesModel);
REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotesNfcShareService);
REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilNotesPlaintextModel);
REGISTER_TYPE(uri, v1, v2, FoilNotesNfcShareClient);
REGISTER_TYPE(uri, v1, v2, FoilNotesSearchModel);
}

int main(int argc, char *argv[])
Expand Down

0 comments on commit e6163da

Please sign in to comment.