From ad6b5104179bbcbbebf54197e81c487666d106d1 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Thu, 17 Mar 2022 04:48:37 -0700 Subject: [PATCH] fix(macos): Represent autorun state in UI persistently Check file setting rather than reporting a global value that isn't persisted across client restart. --- src/platform/autorun_osx.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/platform/autorun_osx.cpp b/src/platform/autorun_osx.cpp index 743ed9f1a..545bd3016 100644 --- a/src/platform/autorun_osx.cpp +++ b/src/platform/autorun_osx.cpp @@ -25,29 +25,30 @@ #include namespace { -bool state; +QString getAutorunFile() +{ + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + + QDir::separator() + "Library" + QDir::separator() + "LaunchAgents" + + QDir::separator() + "chat.tox.qtox.autorun.plist"); +} } // namespace bool Platform::setAutorun(const Settings& settings, bool on) { std::ignore = settings; - QString qtoxPlist = - QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) - + QDir::separator() + "Library" + QDir::separator() + "LaunchAgents" - + QDir::separator() + "chat.tox.qtox.autorun.plist"); QString qtoxDir = QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() + "qtox"); - QSettings autoRun(qtoxPlist, QSettings::NativeFormat); + QSettings autoRun(getAutorunFile(), QSettings::NativeFormat); autoRun.setValue("Label", "chat.tox.qtox.autorun"); autoRun.setValue("Program", qtoxDir); - state = on; - autoRun.setValue("RunAtLoad", state); + autoRun.setValue("RunAtLoad", on); return true; } bool Platform::getAutorun(const Settings& settings) { std::ignore = settings; - return state; + QSettings autoRun(getAutorunFile(), QSettings::NativeFormat); + return autoRun.value("RunAtLoad", false).toBool(); }