From da8ea3a8550adf46701e653de20ef443bc610556 Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Thu, 21 Apr 2022 16:34:24 +0300 Subject: [PATCH] [sailfish-utilities] Add a Restart Fingerprint button. Fixes JB#57941 Adds a button for restarting the fingerprint service. In practice, it restarts, waits 3 seconds and then restarts again. In some situations where the fingerprint cache gets messed up, which prevents fingerprints from being recognised, this sequence resolves the issue. --- plugin/utiltools.cpp | 5 +++++ plugin/utiltools.h | 3 +++ qml/ActionList.qml | 3 ++- qml/plugins/RestartFingerprint.qml | 19 +++++++++++++++++++ tools/CMakeLists.txt | 1 + tools/restart_fingerprint.sh | 18 ++++++++++++++++++ tools/sailfish_tools_system_action.cpp | 5 ++++- 7 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 qml/plugins/RestartFingerprint.qml create mode 100755 tools/restart_fingerprint.sh diff --git a/plugin/utiltools.cpp b/plugin/utiltools.cpp index 1a6857d..72ffda7 100644 --- a/plugin/utiltools.cpp +++ b/plugin/utiltools.cpp @@ -35,6 +35,11 @@ void UtilTools::restartLipstick(QJSValue successCallback, QJSValue errorCallback execute(SystemTool, QStringList("restart_lipstick"), successCallback, errorCallback); } +void UtilTools::restartFingerprint(QJSValue successCallback, QJSValue errorCallback) +{ + execute(SystemTool, QStringList("restart_fingerprint"), successCallback, errorCallback); +} + void UtilTools::handleProcessExit(int exitCode, QProcess::ExitStatus status) { QProcess *process = qobject_cast(sender()); diff --git a/plugin/utiltools.h b/plugin/utiltools.h index f2342a3..306c09f 100644 --- a/plugin/utiltools.h +++ b/plugin/utiltools.h @@ -24,6 +24,9 @@ class UtilTools: public QObject Q_INVOKABLE void restartLipstick(QJSValue successCallback = QJSValue::UndefinedValue, QJSValue errorCallback = QJSValue::UndefinedValue); + Q_INVOKABLE void restartFingerprint(QJSValue successCallback = QJSValue::UndefinedValue, + QJSValue errorCallback = QJSValue::UndefinedValue); + private slots: void handleProcessExit(int exitCode, QProcess::ExitStatus status); diff --git a/qml/ActionList.qml b/qml/ActionList.qml index bbf5b3b..d05f359 100644 --- a/qml/ActionList.qml +++ b/qml/ActionList.qml @@ -29,7 +29,8 @@ Column { plugins.append(info) } var names = [ "RestartNetwork", "RestartUI", - "CleanPackageCache", "CleanTracker" ] + "CleanPackageCache", "CleanTracker", + "RestartFingerprint"] for (var i = 0; i < names.length; ++i) justLoad(names[i]) } diff --git a/qml/plugins/RestartFingerprint.qml b/qml/plugins/RestartFingerprint.qml new file mode 100644 index 0000000..de1fa1a --- /dev/null +++ b/qml/plugins/RestartFingerprint.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import Sailfish.Utilities 1.0 + +ActionItem { + //% "Fingerprint" + title: qsTrId("sailfish-tools-he-fingerprint") + //% "Restart" + actionName: qsTrId("sailfish-tools-bt-fingerprint_restart") + deviceLockRequired: false + //% "Restart fingerprint service. In some circumstancces this can " + //% "resolve issues where valid fingerprints are no longer being " + //% "recognised." + description: qsTrId("sailfish-utilities-restart-fingerprint_desc") + + function action(on_reply, on_error) { + UtilTools.restartFingerprint(on_reply, on_error) + } +} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f94c39b..56b545a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -22,5 +22,6 @@ install(PROGRAMS restart_network.sh restart_lipstick.sh tracker_reindex.sh + restart_fingerprint.sh DESTINATION share/sailfish-utilities ) diff --git a/tools/restart_fingerprint.sh b/tools/restart_fingerprint.sh new file mode 100755 index 0000000..ef6c13c --- /dev/null +++ b/tools/restart_fingerprint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +warning() { + printf "%s: Warning: %s\n" "$(basename $0)" "${@}" 1>&2; +} + +service_do() { + if systemctl "$1" "$2"; then + return 0; + else + warning "Status $? on" "${@}" + return 1; + fi +} + +service_do restart sailfish-fpd +sleep 3 +service_do restart sailfish-fpd diff --git a/tools/sailfish_tools_system_action.cpp b/tools/sailfish_tools_system_action.cpp index 0592a26..915763e 100644 --- a/tools/sailfish_tools_system_action.cpp +++ b/tools/sailfish_tools_system_action.cpp @@ -66,11 +66,14 @@ std::map actions = { }}, { "tracker_reindex", [](action_ctx const *) { return execute_own_utility("tracker_reindex.sh"); + }}, + { "restart_fingerprint", [](action_ctx const *) { + return execute_own_utility("restart_fingerprint.sh"); }} }; std::set root_actions = { - "repair_rpm_db", "restart_network" + "repair_rpm_db", "restart_network", "restart_fingerprint" }; class BecomeRoot