Skip to content

Commit

Permalink
Move some settings to shared settings (#293)
Browse files Browse the repository at this point in the history
* Move lockscreen settings to shared settings

* Add pin information to FAQs

* Move autoSleep and swipes to shared settings
  • Loading branch information
Eeems authored Feb 10, 2023
1 parent c52abd5 commit 7cfc243
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 136 deletions.
1 change: 0 additions & 1 deletion applications/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <QQuickItem>
#include <QObject>
#include <QMap>
#include <QSettings>
#include <QProcess>
#include <QStringList>
#include <QtDBus>
Expand Down
1 change: 0 additions & 1 deletion applications/launcher/oxide_stable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <QQmlApplicationEngine>
#include <QQuickItem>
#include <QSet>
#include <QSettings>
#include <QStandardPaths>
#include <QStringList>
#include <QtDBus>
Expand Down
63 changes: 37 additions & 26 deletions applications/lockscreen/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using namespace codes::eeems::oxide1;
using namespace Oxide::Sentry;

#define DECAY_SETTINGS_VERSION 1

enum State { Normal, PowerSaving };
enum BatteryState { BatteryUnknown, BatteryCharging, BatteryDischarging, BatteryNotPresent };
enum ChargerState { ChargerUnknown, ChargerConnected, ChargerNotConnected, ChargerNotPresent };
Expand All @@ -26,7 +24,7 @@ class Controller : public QObject {

public:
Controller(QObject* parent)
: QObject(parent), confirmPin(), settings(this) {
: QObject(parent), confirmPin() {
clockTimer = new QTimer(root);
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
Expand Down Expand Up @@ -88,10 +86,26 @@ class Controller : public QObject {
}
appsApi = new Apps(OXIDE_SERVICE, path.path(), bus, this);

settings.sync();
auto version = settings.value("version", 0).toInt();
if(version < DECAY_SETTINGS_VERSION){
migrate(&settings, version);
QSettings settings;
if(QFile::exists(settings.fileName())){
qDebug() << "Importing old settings";
settings.sync();
if(settings.contains("pin")){
qDebug() << "Importing old pin";
sharedSettings.set_pin(settings.value("pin").toString());
}
if(settings.contains("onLogin")){
qDebug() << "Importing old onLogin";
sharedSettings.set_onLogin(settings.value("onLogin").toString());
}
if(settings.contains("onFailedLogin")){
qDebug() << "Importing old onFailedLogin";
sharedSettings.set_onFailedLogin(settings.value("onFailedLogin").toString());
}
settings.clear();
settings.sync();
QFile::remove(settings.fileName());
sharedSettings.sync();
}

connect(&sharedSettings, &Oxide::SharedSettings::firstLaunchChanged, this, &Controller::firstLaunchChanged);
Expand Down Expand Up @@ -142,7 +156,7 @@ class Controller : public QObject {
return;
}
// There is no PIN configuration
if(!settings.contains("pin")){
if(!sharedSettings.has_pin()){
qDebug() << "No Pin";
QTimer::singleShot(100, [this]{
stateControllerUI->setProperty("state", xochitlPin().isEmpty() ? "pinPrompt" : "import");
Expand Down Expand Up @@ -180,7 +194,7 @@ class Controller : public QObject {
Application app(OXIDE_SERVICE, path.path(), QDBusConnection::systemBus());
app.launch();
}
bool hasPin(){ return settings.contains("pin") && storedPin().length(); }
bool hasPin(){ return sharedSettings.has_pin() && storedPin().length(); }
void previousApplication(){
if(!appsApi->previousApplication()){
launchStartupApp();
Expand Down Expand Up @@ -225,6 +239,7 @@ class Controller : public QObject {
return true;
}else if(state == "loaded"){
qDebug() << "PIN doesn't match!";
O_DEBUG(pin << "!=" << storedPin());
onFailedLogin();
return false;
}
Expand Down Expand Up @@ -289,10 +304,16 @@ class Controller : public QObject {
}
stateControllerUI->setProperty("state", state);
}
QString storedPin() { return settings.value("pin", "").toString(); }
QString storedPin() {
if(!sharedSettings.has_pin()){
O_DEBUG("Does not have pin and storedPin was called");
return "";
}
return sharedSettings.pin();
}
void setStoredPin(QString pin) {
settings.setValue("pin", pin);
settings.sync();
sharedSettings.set_pin(pin);
sharedSettings.sync();
}

void setRoot(QObject* root){ this->root = root; }
Expand Down Expand Up @@ -435,10 +456,10 @@ private slots:
// TODO handle charger
}
void onLogin(){
if(!settings.contains("onLogin")){
if(!sharedSettings.has_onLogin()){
return;
}
auto path = settings.value("onLogin").toString();
auto path = sharedSettings.onLogin();
if(!QFile::exists(path)){
O_WARNING("onLogin script does not exist" << path);
return;
Expand All @@ -450,10 +471,10 @@ private slots:
QProcess::execute(path, QStringList());
}
void onFailedLogin(){
if(!settings.contains("onFailedLogin")){
if(!sharedSettings.has_onFailedLogin()){
return;
}
auto path = settings.value("onFailedLogin").toString();
auto path = sharedSettings.onFailedLogin();
if(!QFile::exists(path)){
O_WARNING("onFailedLogin script does not exist" << path);
return;
Expand All @@ -467,7 +488,6 @@ private slots:

private:
QString confirmPin;
QSettings settings;
General* api;
System* systemApi;
codes::eeems::oxide1::Power* powerApi;
Expand Down Expand Up @@ -503,15 +523,6 @@ private slots:
return pinEntryUI;
}

static void migrate(QSettings* settings, int fromVersion){
if(fromVersion != 0){
throw "Unknown settings version";
}
// In the future migrate changes to settings between versions
settings->setValue("version", DECAY_SETTINGS_VERSION);
settings->sync();
}

static QString xochitlPin(){ return xochitlSettings.passcode(); }
static void removeXochitlPin(){
xochitlSettings.remove("Passcode");
Expand Down
41 changes: 20 additions & 21 deletions applications/system-service/systemapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void SystemAPI::PrepareForSleep(bool suspending){
Oxide::Sentry::sentry_span(t, "enable", "Enable various services", [this, device]{
buttonHandler->setEnabled(true);
emit deviceResuming();
if(m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected){
qDebug() << "Suspend timer re-enabled due to resume";
suspendTimer.start(m_autoSleep * 60 * 1000);
suspendTimer.start(autoSleep() * 60 * 1000);
}
if(device == Oxide::DeviceSettings::DeviceType::RM2){
system("modprobe brcmfmac");
Expand All @@ -98,20 +98,19 @@ void SystemAPI::PrepareForSleep(bool suspending){
});
}
}
void SystemAPI::setAutoSleep(int autoSleep){
if(autoSleep < 0 || autoSleep > 360){
void SystemAPI::setAutoSleep(int _autoSleep){
if(_autoSleep < 0 || _autoSleep > 360){
return;
}
qDebug() << "Auto Sleep" << autoSleep;
m_autoSleep = autoSleep;
if(m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
suspendTimer.setInterval(m_autoSleep * 60 * 1000);
}else if(!m_autoSleep){
qDebug() << "Auto Sleep" << _autoSleep;
sharedSettings.set_autoSleep(_autoSleep);
if(_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
suspendTimer.setInterval(_autoSleep * 60 * 1000);
}else if(!_autoSleep){
suspendTimer.stop();
}
settings.setValue("autoSleep", autoSleep);
settings.sync();
emit autoSleepChanged(autoSleep);
sharedSettings.sync();
emit autoSleepChanged(_autoSleep);
}
void SystemAPI::uninhibitAll(QString name){
if(powerOffInhibited()){
Expand All @@ -126,25 +125,25 @@ void SystemAPI::uninhibitAll(QString name){
emit sleepInhibitedChanged(false);
}
}
if(!sleepInhibited() && m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected && !suspendTimer.isActive()){
if(!sleepInhibited() && autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected && !suspendTimer.isActive()){
qDebug() << "Suspend timer re-enabled due to uninhibit" << name;
suspendTimer.start(m_autoSleep * 60 * 1000);
suspendTimer.start(autoSleep() * 60 * 1000);
}
}
void SystemAPI::startSuspendTimer(){
if(m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected && !suspendTimer.isActive()){
if(autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected && !suspendTimer.isActive()){
qDebug() << "Suspend timer re-enabled due to start Suspend timer";
suspendTimer.start(m_autoSleep * 60 * 1000);
suspendTimer.start(autoSleep() * 60 * 1000);
}
}
void SystemAPI::activity(){
auto active = suspendTimer.isActive();
suspendTimer.stop();
if(m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(!active){
qDebug() << "Suspend timer re-enabled due to activity";
}
suspendTimer.start(m_autoSleep * 60 * 1000);
suspendTimer.start(autoSleep() * 60 * 1000);
}else if(active){
qDebug() << "Suspend timer disabled";
}
Expand All @@ -155,10 +154,10 @@ void SystemAPI::uninhibitSleep(QDBusMessage message){
return;
}
sleepInhibitors.removeAll(message.service());
if(!sleepInhibited() && m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(!sleepInhibited() && autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(!suspendTimer.isActive()){
qDebug() << "Suspend timer re-enabled due to uninhibit sleep" << message.service();
suspendTimer.start(m_autoSleep * 60 * 1000);
suspendTimer.start(autoSleep() * 60 * 1000);
}
releaseSleepInhibitors(true);
}
Expand All @@ -167,7 +166,7 @@ void SystemAPI::uninhibitSleep(QDBusMessage message){
}
}
void SystemAPI::timeout(){
if(m_autoSleep && powerAPI->chargerState() != PowerAPI::ChargerConnected){
if(autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected){
qDebug() << "Automatic suspend due to inactivity...";
suspend();
}
Expand Down
Loading

0 comments on commit 7cfc243

Please sign in to comment.