30
30
#include < QQmlContext>
31
31
#include < QQuickWindow>
32
32
#include < QtDebug>
33
+ #if defined(Q_PROCESSOR_ARM)
34
+ #include < filesystem>
35
+ #endif
33
36
34
37
#include " bluetooth.h"
35
38
#include " commandlinehandler.h"
@@ -94,8 +97,8 @@ int main(int argc, char* argv[]) {
94
97
bool configError = false ;
95
98
if (!QFile::exists (cmdLineHandler.configFile ())) {
96
99
qFatal (" App configuration file not found: %s" , cmdLineHandler.configFile ().toLatin1 ().constData ());
97
- return 1 ;
98
100
}
101
+
99
102
Config* config = new Config (&engine, cmdLineHandler.configFile (), cmdLineHandler.configSchemaFile (), appPath);
100
103
if (!config->readConfig ()) {
101
104
qCCritical (CLASS_LC).noquote () << " Invalid configuration!" << endl << config->getError ();
@@ -207,6 +210,47 @@ int main(int argc, char* argv[]) {
207
210
ButtonHandler* buttonHandler = new ButtonHandler (hwFactory->getInterruptHandler (), yioapi);
208
211
qmlRegisterSingletonType<ButtonHandler>(" ButtonHandler" , 1 , 0 , " ButtonHandler" , &ButtonHandler::getQMLInstance);
209
212
213
+ #if defined(Q_PROCESSOR_ARM)
214
+ // reset combination was pressed on startup (only on the remote hardware)
215
+ if (buttonHandler->resetButtonsPressed ()) {
216
+ QString defaultConfigPath = qEnvironmentVariable (Environment::ENV_YIO_APP_DIR, appPath) + " /config.json" ;
217
+
218
+ if (QFile::exists (defaultConfigPath)) {
219
+ // create marker file
220
+ QFile file (" /firstrun" );
221
+ if (file.open (QIODevice::WriteOnly)) {
222
+ file.close ();
223
+
224
+ // make a copy of existing configuration
225
+ if (!std::filesystem::copy_file (" /boot/config.json" , " /boot/config.json.old" ,
226
+ std::filesystem::copy_options::overwrite_existing)) {
227
+ qCCritical (CLASS_LC) << " Error backing up existing configuration." ;
228
+ } else {
229
+ if (!std::filesystem::copy_file (defaultConfigPath.toStdString (), " /boot/config.json" ,
230
+ std::filesystem::copy_options::overwrite_existing)) {
231
+ qCCritical (CLASS_LC) << " Error copying default configuration." ;
232
+ } else {
233
+ // reset wifi settings
234
+ wifiControl->clearConfiguredNetworks ();
235
+
236
+ // reboot
237
+ Launcher ().launch (" reboot" );
238
+
239
+ return -1 ;
240
+ }
241
+ }
242
+ } else {
243
+ qCCritical (CLASS_LC) << " Error writing firstrun marker file" ;
244
+ notifications.add (
245
+ true , QGuiApplication::tr (" An error occured while restoring to defaults. Please try again." ));
246
+ }
247
+ } else {
248
+ qCCritical (CLASS_LC) << " Default config file not found. Cannot restore to defaults." ;
249
+ notifications.add (true , QGuiApplication::tr (" Default config file not found. Cannot restore to defaults." ));
250
+ }
251
+ }
252
+ #endif
253
+
210
254
// STANDBY CONTROL
211
255
StandbyControl* standbyControl =
212
256
new StandbyControl (displayControl, hwFactory->getProximitySensor (), hwFactory->getLightSensor (),
@@ -216,7 +260,7 @@ int main(int argc, char* argv[]) {
216
260
qmlRegisterSingletonType<StandbyControl>(" StandbyControl" , 1 , 0 , " StandbyControl" , &StandbyControl::getQMLInstance);
217
261
218
262
// SOFTWARE UPDATE
219
- QVariantMap appUpdCfg = config->getSettings ().value (" softwareupdate" ).toMap ();
263
+ QVariantMap appUpdCfg = config->getSettings ().value (" softwareupdate" ).toMap ();
220
264
SoftwareUpdate* softwareUpdate = new SoftwareUpdate (appUpdCfg, hwFactory->getBatteryFuelGauge ());
221
265
qmlRegisterSingletonType<SoftwareUpdate>(" SoftwareUpdate" , 1 , 0 , " SoftwareUpdate" , &SoftwareUpdate::getQMLInstance);
222
266
0 commit comments