Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a custom JSON config file for Commandline application #256

Closed
MartinNievas opened this issue Oct 10, 2020 · 3 comments
Closed

Comments

@MartinNievas
Copy link
Contributor

Hi. I saw that in #243 the tool for the command line was introduced. But I can't find how to set the option:

-c, --custom-config <json-file> A custom JSON config file to load
                                    configuration for the watch.

In #190 there is an example of the JSON file, but I guess there is a way to generate it.
Could someone tell me the steps to create it? or from where can I find the format to create the file?

@centic9
Copy link
Contributor

centic9 commented Oct 11, 2020

Thanks for the reminder, this is actually not yet supported in the CLI or GUI, but only available locally for now until I can finish this.

For now you can apply the following patch to write the current settings and apps to JSON files as part of regular syncing in CLI or GUI.

Maybe you can come up with changes which add a GUI-setting/commandline-parameter for this and store the file in the configuration-directory instead of the current directory?

Index: src/movescount/movescount.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/movescount/movescount.cpp	(revision 3c70c4b5e4c03933af57ef7a48031ccf4d491200)
+++ src/movescount/movescount.cpp	(revision e6a3a4cb037ac60a272a78c5625b52f35ad08094)
@@ -27,6 +27,8 @@
 #include <QEventLoop>
 #include <QMutex>
 #include <QDebug>
+#include <QDir>
+#include <QJsonDocument>
 
 #include "logstore.h"
 
@@ -471,6 +473,20 @@
     }
 }
 
+void writeJson(QByteArray _data, const char* name) {
+    QFile logfile(name);
+    logfile.open(QIODevice::WriteOnly | QIODevice::Truncate);
+
+    // pretty print JSON
+    QJsonDocument doc = QJsonDocument::fromJson(_data);
+    QString formattedJsonString = doc.toJson(QJsonDocument::Indented);
+
+    //formattedJsonString.replace("", "");
+
+    logfile.write(formattedJsonString.toUtf8());
+    logfile.close();
+}
+
 int MovesCount::getCustomModeDataInThread(ambit_sport_mode_device_settings_t *ambitSettings)
 {
     int ret = -1;
@@ -482,6 +498,8 @@
         QByteArray _data = reply->readAll();
         MovescountSettings settings = MovescountSettings();
 
+        writeJson(_data, "settings.json");
+
         if (jsonParser.parseDeviceSettingsReply(_data, settings) == 0) {
             settings.toAmbitData(ambitSettings);
             ret = 0;
@@ -501,6 +519,8 @@
     if (checkReplyAuthorization(reply)) {
         QByteArray _data = reply->readAll();
 
+        writeJson(_data, "apprules.json");
+
         if (jsonParser.parseAppRulesReply(_data, ambitApps) == 0) {
             ret = 0;
         }

@MartinNievas
Copy link
Contributor Author

Hi, thanks for the reply.
I successfully apply the patch, but I was getting problems connecting, mainly because I don't understand what username and userkey was.

Reading this comment I understood that APPKEY is also device/account specific. All these values can be found in the file %AppData%\Roaming\Suunto\Moveslink2\Settings.xml on windows. After that, I was able to download the json files (apprules and settings) with openambit-cli.

Is there any other way to get those values? (APPKEY, username and userkey)

MartinNievas added a commit to MartinNievas/openambit that referenced this issue Oct 18, 2020
- This write the current settings and apps to JSON files as part of regular syncing in CLI or GUI.
- Files are saved in the same place as openambit.conf
@centic9
Copy link
Contributor

centic9 commented Oct 24, 2020

Writing the json-config to json-files is now available in the UI via #258 and in the command-line application via 6c3c781

@centic9 centic9 closed this as completed Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants