]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
main: cleanup argument parsing
authortobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 00:17:51 +0000 (02:17 +0200)
committertobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 00:17:51 +0000 (02:17 +0200)
src/main.cpp

index 43a9e7207efb6b4d750bc4d89e7b63d7110f5e10..e1512a001797a62b35a13473f0796fe8c81d1b9a 100644 (file)
@@ -66,8 +66,6 @@ void signal_handler(int signum) {
 
 int main(int argc, char *argv[])
 {
-    qDebug() << "Reached main";
-
     Q_INIT_RESOURCE(assets);
 
 #if defined(Q_OS_LINUX) && defined(STACK_TRACE)
@@ -86,32 +84,42 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
 }
 #endif
 
-    QStringList argv_;
-    for(int i = 0; i != argc; i++){
-        argv_ << QString::fromStdString(argv[i]);
-    }
+#if defined(Q_OS_LINUX)
+    // PassThrough results in muddy text
+    QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
+#endif
+
+#if defined(Q_OS_MAC)
+    // https://github.com/itay-grudev/SingleApplication/issues/136#issuecomment-1925441403
+    QApplication app(argc, argv);
+#else
+    SingleApplication app(argc, argv);
+#endif
+
+    QApplication::setApplicationName("Feather");
+    QApplication::setApplicationVersion(FEATHER_VERSION);
 
     QCommandLineParser parser;
-    parser.setApplicationDescription("feather");
-    parser.addHelpOption();
-    parser.addVersionOption();
+    parser.setApplicationDescription("Feather - a free Monero desktop wallet");
+    QCommandLineOption helpOption = parser.addHelpOption();
+    QCommandLineOption versionOption = parser.addVersionOption();
 
-    QCommandLineOption useLocalTorOption(QStringList() << "use-local-tor", "Use system wide installed Tor instead of the bundled.");
+    QCommandLineOption useLocalTorOption("use-local-tor", "Use system wide installed Tor instead of the bundled.");
     parser.addOption(useLocalTorOption);
 
-    QCommandLineOption quietModeOption(QStringList() << "quiet", "Limit console output");
+    QCommandLineOption quietModeOption("quiet", "Limit console output");
     parser.addOption(quietModeOption);
 
-    QCommandLineOption stagenetOption(QStringList() << "stagenet", "Stagenet is for development purposes only.");
+    QCommandLineOption stagenetOption("stagenet", "Stagenet is for development purposes only.");
     parser.addOption(stagenetOption);
 
-    QCommandLineOption testnetOption(QStringList() << "testnet", "Testnet is for development purposes only.");
+    QCommandLineOption testnetOption("testnet", "Testnet is for development purposes only.");
     parser.addOption(testnetOption);
 
-    bool parsed = parser.parse(argv_);
-    if (!parsed) {
-        qCritical() << parser.errorText();
-        exit(1);
+    parser.process(app);
+
+    if (parser.isSet(versionOption) || parser.isSet(helpOption)) {
+        return EXIT_SUCCESS;
     }
 
     bool stagenet = parser.isSet(stagenetOption);
@@ -126,26 +134,8 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
     else
         constants::networkType = NetworkType::MAINNET;
 
-    // Setup QApplication
-    QApplication::setDesktopSettingsAware(true); // use system font
-    QApplication::setApplicationVersion(FEATHER_VERSION);
-
-#if defined(Q_OS_LINUX)
-    // PassThrough results in muddy text
-    QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
-#endif
-
-    qDebug() << "Setting up QApplication";
-
-#if defined(Q_OS_MAC)
-    // https://github.com/itay-grudev/SingleApplication/issues/136#issuecomment-1925441403
-    QApplication app(argc, argv);
-#else
-    SingleApplication app(argc, argv);
-#endif
-
     QApplication::setQuitOnLastWindowClosed(false);
-    QApplication::setApplicationName("FeatherWallet");
+    QApplication::setDesktopSettingsAware(true); // use system font
 
     // Setup config directories
     QString configDir = Config::defaultConfigDir().path();
@@ -254,5 +244,7 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
     });
 #endif
 
-    return QApplication::exec();
+    int exitCode = QApplication::exec();
+    qDebug() << "QApplication::exec() returned";
+    return exitCode;
 }