Use QSettings in AppConfig
Some more changes Changes Fix review items Rename init-settings to restore-native-settings Restore application name (thanks @churik !) Remove org name/domain setting for desktop Change organization name to include domain Re-use default values in :desktop/desktop Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
This commit is contained in:
parent
e122ebdb84
commit
e40e495e11
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
const QStringList loggingCategories =
|
||||
{"UIManager",
|
||||
|
@ -14,25 +15,50 @@ const QStringList loggingCategories =
|
|||
"RCTStatus",
|
||||
"jsserver",
|
||||
"status"};
|
||||
|
||||
const QString SETTINGS_GROUP_NAME = "im/status";
|
||||
const QString AppConfig::LOGGING_ENABLED = "logging_enabled";
|
||||
|
||||
Q_LOGGING_CATEGORY(APPCONFIG, "AppConfig")
|
||||
|
||||
AppConfig AppConfig::appConfig;
|
||||
|
||||
AppConfig::AppConfig() {
|
||||
AppConfig::AppConfig()
|
||||
: settings("Status.im", "StatusDesktop") {
|
||||
settings.beginGroup(SETTINGS_GROUP_NAME);
|
||||
|
||||
// Set default values
|
||||
if (settings.value(LOGGING_ENABLED).isNull()) {
|
||||
settings.setValue(LOGGING_ENABLED, false);
|
||||
}
|
||||
|
||||
QStringList keys = settings.allKeys();
|
||||
for (int i = 0; i < keys.size(); ++i) {
|
||||
processFx(keys[i], settings.value(keys[i]));
|
||||
}
|
||||
}
|
||||
|
||||
AppConfig& AppConfig::inst() {
|
||||
return appConfig;
|
||||
}
|
||||
|
||||
bool AppConfig::getLoggingEnabled() const {
|
||||
return loggingEnabled;
|
||||
QVariant AppConfig::getValue(const QString& name) const {
|
||||
return settings.value(name);
|
||||
}
|
||||
|
||||
void AppConfig::setLoggingEnabled(bool enabled) {
|
||||
//qCDebug(APPCONFIG) << "### appconfig setLoggingEnabled " << enabled;
|
||||
QLoggingCategory::setFilterRules(getLoggingFilterRules(enabled));
|
||||
this->loggingEnabled = enabled;
|
||||
void AppConfig::setValue(const QString& name, const QVariant& value) {
|
||||
processFx(name, value);
|
||||
settings.setValue(name, value);
|
||||
}
|
||||
|
||||
// This fn is for processing side-effects of a particular value
|
||||
void AppConfig::processFx(const QString& name, const QVariant& value) const {
|
||||
//qCDebug(APPCONFIG) << "### processFx group" << settings.group() << " " << name << ": " << value;
|
||||
if (name == LOGGING_ENABLED) {
|
||||
bool enabled = value.toBool();
|
||||
//qCDebug(APPCONFIG) << "### processFx" << name << ": " << value << ": " << enabled;
|
||||
QLoggingCategory::setFilterRules(getLoggingFilterRules(enabled));
|
||||
}
|
||||
}
|
||||
|
||||
QString AppConfig::getLoggingFilterRules(bool enabled) const {
|
||||
|
@ -47,3 +73,4 @@ QString AppConfig::getLoggingFilterRules(bool enabled) const {
|
|||
return filterRules;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define APPCONFIG_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QSettings>
|
||||
|
||||
// This class is intended to store app configuration
|
||||
// modifiable from JS side
|
||||
|
@ -12,15 +14,18 @@ public:
|
|||
|
||||
static AppConfig& inst();
|
||||
|
||||
bool getLoggingEnabled() const;
|
||||
void setLoggingEnabled(bool enable);
|
||||
QVariant getValue(const QString& name) const;
|
||||
void setValue(const QString& name, const QVariant& value);
|
||||
|
||||
const static QString LOGGING_ENABLED;
|
||||
private:
|
||||
AppConfig();
|
||||
|
||||
bool loggingEnabled = false;
|
||||
static AppConfig appConfig;
|
||||
QSettings settings;
|
||||
|
||||
QString getLoggingFilterRules(bool enabled) const;
|
||||
void processFx(const QString& name, const QVariant& value) const;
|
||||
};
|
||||
#endif // APPCONFIG_H
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/**
|
||||
* Copyright (C) 2016, Canonical Ltd.
|
||||
* All rights reserved.
|
||||
|
@ -240,6 +239,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
QCoreApplication::setApplicationName("Status");
|
||||
|
||||
// Init AppConfig
|
||||
AppConfig::inst().getValue(AppConfig::LOGGING_ENABLED);
|
||||
|
||||
QString appPath = QCoreApplication::applicationDirPath();
|
||||
QString dataStoragePath = getDataStoragePath();
|
||||
#ifdef BUILD_FOR_BUNDLE
|
||||
|
@ -263,7 +265,6 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
//qCDebug(STATUS) << "###STATUS_NO_LOGGING";
|
||||
AppConfig::inst().setLoggingEnabled(false);
|
||||
|
||||
|
||||
#ifdef BUILD_FOR_BUNDLE
|
||||
|
@ -558,3 +559,4 @@ void saveMessage(QtMsgType type, const QMessageLogContext &context,
|
|||
}
|
||||
|
||||
#include "main.moc"
|
||||
|
||||
|
|
|
@ -33,12 +33,14 @@ QList<ModuleMethod *> DesktopConfig::methodsToExport() {
|
|||
|
||||
QVariantMap DesktopConfig::constantsToExport() { return QVariantMap(); }
|
||||
|
||||
void DesktopConfig::getLoggingEnabled(double callback) {
|
||||
bridge->invokePromiseCallback(callback, QVariantList{AppConfig::inst().getLoggingEnabled()});
|
||||
void DesktopConfig::getValue(const QString& name, double callback) {
|
||||
//qCDebug(DESKTOPCONFIG) << "### getValue" << name;
|
||||
bridge->invokePromiseCallback(callback, QVariantList{AppConfig::inst().getValue(name)});
|
||||
}
|
||||
|
||||
void DesktopConfig::setLoggingEnabled(bool enable) {
|
||||
//qCDebug(DESKTOPCONFIG) << "### setLoggingEnabled " << enable;
|
||||
AppConfig::inst().setLoggingEnabled(enable);
|
||||
void DesktopConfig::setValue(const QString& name, const QVariant& value) {
|
||||
//qCDebug(DESKTOPCONFIG) << "### setValue" << name << ": " << value;
|
||||
AppConfig::inst().setValue(name, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define DESKTOPCONFIG_H
|
||||
|
||||
#include "moduleinterface.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(CONFIG)
|
||||
|
@ -22,8 +22,8 @@ public:
|
|||
QList<ModuleMethod*> methodsToExport() override;
|
||||
QVariantMap constantsToExport() override;
|
||||
|
||||
Q_INVOKABLE void getLoggingEnabled(double callback);
|
||||
Q_INVOKABLE void setLoggingEnabled(bool enable);
|
||||
Q_INVOKABLE void getValue(const QString& name, double callback);
|
||||
Q_INVOKABLE void setValue(const QString& name, const QVariant& value);
|
||||
|
||||
private:
|
||||
Bridge* bridge = nullptr;
|
||||
|
|
|
@ -4,15 +4,12 @@ const NativeModules = require('react-native').NativeModules;
|
|||
|
||||
class DesktopConfig {
|
||||
|
||||
static getLoggingEnabled(callbackFn) {
|
||||
NativeModules.DesktopConfigManager.getLoggingEnabled(
|
||||
(enabled) => {
|
||||
callbackFn(enabled);
|
||||
});
|
||||
static getValue(name, callbackFn) {
|
||||
NativeModules.DesktopConfigManager.getValue(name, callbackFn);
|
||||
}
|
||||
|
||||
static setLoggingEnabled(enabled) {
|
||||
NativeModules.DesktopConfigManager.setLoggingEnabled(enabled);
|
||||
static setValue(name, value) {
|
||||
NativeModules.DesktopConfigManager.setValue(name, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,10 +102,6 @@
|
|||
#(re-frame/dispatch
|
||||
[:web3/fetch-node-version-callback %])]}
|
||||
(protocol/initialize-protocol address)
|
||||
#(when platform/desktop?
|
||||
(let [logging-enabled (get-in db [:account/account :settings :logging-enabled])]
|
||||
(log/debug "### user-login-callback .setLoggingEnabled" logging-enabled)
|
||||
(.setLoggingEnabled rn-dependencies/desktop-config logging-enabled)))
|
||||
#(when-not platform/desktop?
|
||||
(initialize-wallet %)))
|
||||
(account-and-db-password-do-not-match cofx error)))))
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
[status-im.accounts.login.core :as accounts.login]
|
||||
[status-im.accounts.update.core :as accounts.update]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.react-native.js-dependencies :as rn-dependencies]
|
||||
[status-im.data-store.core :as data-store]
|
||||
[status-im.data-store.realm.core :as realm]
|
||||
[status-im.extensions.registry :as extensions.registry]
|
||||
|
@ -42,6 +43,11 @@
|
|||
(log/warn "Could not decrypt database" error)
|
||||
(re-frame/dispatch [:init.callback/init-store-error encryption-key])))))
|
||||
|
||||
(defn restore-native-settings! []
|
||||
(when platform/desktop?
|
||||
(.getValue rn-dependencies/desktop-config "logging_enabled"
|
||||
#(re-frame/dispatch [:set-in [:desktop/desktop :logging-enabled] %1]))))
|
||||
|
||||
;; TODO (yenda) move keychain functions to dedicated namespace
|
||||
(defn reset-keychain! []
|
||||
(.. (keychain/reset)
|
||||
|
@ -67,6 +73,7 @@
|
|||
(fx/defn start-app [cofx]
|
||||
(fx/merge cofx
|
||||
{:init/get-device-UUID nil
|
||||
:init/restore-native-settings nil
|
||||
:ui/listen-to-window-dimensions-change nil
|
||||
:notifications/handle-initial-push-notification nil
|
||||
:network/listen-to-network-status nil
|
||||
|
@ -78,13 +85,14 @@
|
|||
(fx/defn initialize-app-db
|
||||
"Initialize db to initial state"
|
||||
[{{:keys [status-module-initialized? view-id hardwallet
|
||||
initial-props
|
||||
initial-props desktop/desktop
|
||||
network-status network peers-count peers-summary device-UUID]
|
||||
:node/keys [status]
|
||||
:or {network (get app-db :network)}} :db}]
|
||||
{:db (assoc app-db
|
||||
:contacts/contacts {}
|
||||
:initial-props initial-props
|
||||
:desktop/desktop (merge desktop (:desktop/desktop app-db))
|
||||
:network-status network-status
|
||||
:peers-count (or peers-count 0)
|
||||
:peers-summary (or peers-summary [])
|
||||
|
@ -149,6 +157,7 @@
|
|||
(let [{:universal-links/keys [url]
|
||||
:keys [accounts/accounts accounts/create networks/networks network
|
||||
network-status peers-count peers-summary view-id navigation-stack
|
||||
desktop/desktop
|
||||
status-module-initialized? device-UUID semaphores accounts/login]
|
||||
:node/keys [status on-ready]
|
||||
:or {network (get app-db :network)}} db
|
||||
|
@ -162,6 +171,7 @@
|
|||
:node/status status
|
||||
:node/on-ready on-ready
|
||||
:accounts/create create
|
||||
:desktop/desktop (merge desktop (:desktop/desktop app-db))
|
||||
:networks/networks networks
|
||||
:account/account current-account
|
||||
:accounts/login login
|
||||
|
@ -215,6 +225,10 @@
|
|||
:init/init-store
|
||||
init-store!)
|
||||
|
||||
(re-frame/reg-fx
|
||||
:init/restore-native-settings
|
||||
restore-native-settings!)
|
||||
|
||||
(re-frame/reg-fx
|
||||
:init/status-module-initialized
|
||||
status/module-initialized!)
|
||||
|
@ -231,3 +245,4 @@
|
|||
(re-frame/reg-fx
|
||||
:init/reset-account-data
|
||||
reset-account-data!)
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@
|
|||
:on-cancel nil}})
|
||||
|
||||
(fx/defn save-logging-enabled
|
||||
[{:keys [db now] :as cofx} enabled]
|
||||
[{:keys [db] :as cofx} enabled]
|
||||
(.setValue rn-dependencies/desktop-config "logging_enabled" enabled)
|
||||
(let [settings (get-in db [:account/account :settings])]
|
||||
(.setLoggingEnabled rn-dependencies/desktop-config enabled)
|
||||
(accounts.update/update-settings cofx
|
||||
(-> settings
|
||||
(assoc :logging-enabled enabled)
|
||||
(#(if enabled (assoc %1 :log-level "INFO") (dissoc %1 :log-level))))
|
||||
(accounts.update/update-settings (assoc-in cofx [:db :desktop/desktop :logging-enabled] enabled)
|
||||
(if enabled (assoc settings :log-level "INFO") (dissoc settings :log-level))
|
||||
{:success-event [:accounts.update.callback/save-settings-success]})))
|
||||
|
||||
|
|
|
@ -134,13 +134,10 @@
|
|||
(views/letsubs [logging-enabled [:settings/logging-enabled]]
|
||||
[react/view {:style (styles/profile-row false)}
|
||||
[react/text {:style (assoc (styles/profile-row-text colors/black)
|
||||
:font-size 14)} "Logging enabled?"]
|
||||
(let [_ (log/debug "### logging-display" logging-enabled)]
|
||||
[react/switch {:on-tint-color colors/blue
|
||||
:value logging-enabled
|
||||
:on-value-change #(do
|
||||
(log/debug "### changelogging-enabled:" logging-enabled)
|
||||
(re-frame/dispatch [:log-level.ui/logging-enabled (not logging-enabled)]))}])]))
|
||||
:font-size 14)} (i18n/label :t/logging-enabled)]
|
||||
[react/switch {:on-tint-color colors/blue
|
||||
:value logging-enabled
|
||||
:on-value-change #(re-frame/dispatch [:log-level.ui/logging-enabled (not logging-enabled)])}]]))
|
||||
|
||||
(views/defview advanced-settings []
|
||||
(views/letsubs [installations [:pairing/installations]
|
||||
|
@ -180,7 +177,7 @@
|
|||
(installations-section installations))
|
||||
;
|
||||
[react/view {:style styles/title-separator}]
|
||||
[react/text {:style styles/adv-settings-subtitle} "Logging"]
|
||||
[react/text {:style styles/adv-settings-subtitle} (i18n/label :t/logging)]
|
||||
[logging-display]])))
|
||||
|
||||
(views/defview backup-recovery-phrase []
|
||||
|
|
|
@ -11,4 +11,5 @@
|
|||
(re-frame/reg-sub
|
||||
:settings/logging-enabled
|
||||
(fn [db _]
|
||||
(or (get-in db [:account/account :settings :logging-enabled]) false)))
|
||||
(or (get-in db [:desktop/desktop :logging-enabled]) false)))
|
||||
|
||||
|
|
|
@ -564,6 +564,8 @@
|
|||
"transactions-sign-transaction": "Sign transaction",
|
||||
"wallet-backup-recovery-title": "Backup your recovery phrase",
|
||||
"change-log-level": "Change log level to {{log-level}}",
|
||||
"logging": "Logging",
|
||||
"logging-enabled": "Logging enabled?",
|
||||
"change-logging-enabled": "Are you sure you want to {{enable}} logging?",
|
||||
"enable": "enable",
|
||||
"disable": "disable",
|
||||
|
|
Loading…
Reference in New Issue