2020-10-07 10:36:04 +00:00
// SPDX-License-Identifier: BSD-3-Clause
2020-12-26 19:56:06 +00:00
// Copyright (c) 2020-2021, The Monero Project.
2020-10-07 10:36:04 +00:00
# include <QResource>
# include <QApplication>
# include <QtCore>
# include <QtGui>
2021-03-30 09:52:29 +00:00
# include "config-wowlet.h"
2020-10-07 10:36:04 +00:00
# include "mainwindow.h"
# include "cli.h"
2021-04-02 11:07:11 +00:00
# ifdef HAS_OPENVR
# include "vr/main.h"
# endif
2021-04-19 22:02:37 +00:00
# ifdef HAS_ANDROID_DEBUG
# include "mobile/main.h"
# elif HAS_ANDROID
# include "mobile/main.h"
# endif
2020-12-08 16:02:11 +00:00
# if defined(Q_OS_WIN)
# include <windows.h>
# endif
2020-10-09 00:37:05 +00:00
# if defined(Q_OS_LINUX) && defined(STATIC)
2020-10-07 10:36:04 +00:00
Q_IMPORT_PLUGIN ( QXcbIntegrationPlugin )
# endif
int main ( int argc , char * argv [ ] )
{
Q_INIT_RESOURCE ( assets ) ;
2022-03-21 17:12:11 +00:00
qputenv ( " QML_DISABLE_DISK_CACHE " , " 1 " ) ;
2020-10-07 10:36:04 +00:00
2020-12-11 13:36:08 +00:00
# if defined(Q_OS_MAC) && defined(HAS_TOR_BIN)
2020-10-17 21:14:56 +00:00
Q_INIT_RESOURCE ( assets_tor_macos ) ;
2020-12-11 13:36:08 +00:00
# elif defined(HAS_TOR_BIN)
2020-10-17 21:14:56 +00:00
Q_INIT_RESOURCE ( assets_tor ) ;
# endif
2020-12-08 16:02:11 +00:00
# ifdef _WIN32
if ( AttachConsole ( ATTACH_PARENT_PROCESS ) ) {
freopen ( " CONOUT$ " , " w " , stdout ) ;
freopen ( " CONOUT$ " , " w " , stderr ) ;
}
# endif
2020-10-07 10:36:04 +00:00
QStringList argv_ ;
for ( int i = 0 ; i ! = argc ; i + + ) {
argv_ < < QString : : fromStdString ( argv [ i ] ) ;
}
2021-04-19 22:02:37 +00:00
QCoreApplication : : setApplicationName ( " wowlet " ) ;
QCoreApplication : : setOrganizationDomain ( " wownero.org " ) ;
QCoreApplication : : setOrganizationName ( " wownero.org " ) ;
2020-10-07 10:36:04 +00:00
QCommandLineParser parser ;
2021-02-22 06:51:09 +00:00
parser . setApplicationDescription ( " wowlet " ) ;
2020-10-07 10:36:04 +00:00
parser . addHelpOption ( ) ;
parser . addVersionOption ( ) ;
QCommandLineOption useLocalTorOption ( QStringList ( ) < < " use-local-tor " , " Use system wide installed Tor instead of the bundled. " ) ;
parser . addOption ( useLocalTorOption ) ;
QCommandLineOption torPortOption ( QStringList ( ) < < " tor-port " , " Port of running Tor instance. " , " torPort " ) ;
parser . addOption ( torPortOption ) ;
QCommandLineOption debugModeOption ( QStringList ( ) < < " debug " , " Run program in debug mode. " ) ;
parser . addOption ( debugModeOption ) ;
QCommandLineOption quietModeOption ( QStringList ( ) < < " quiet " , " Limit console output " ) ;
parser . addOption ( quietModeOption ) ;
2020-12-21 20:34:36 +00:00
// QCommandLineOption stagenetOption(QStringList() << "stagenet", "Stagenet is for development purposes only.");
// parser.addOption(stagenetOption);
//
// QCommandLineOption testnetOption(QStringList() << "testnet", "Testnet is for development purposes only.");
// parser.addOption(testnetOption);
2020-10-07 10:36:04 +00:00
QCommandLineOption walletPathOption ( QStringList ( ) < < " wallet-file " , " Path to wallet keys file. " , " file " ) ;
parser . addOption ( walletPathOption ) ;
QCommandLineOption walletPasswordOption ( QStringList ( ) < < " password " , " Wallet password (escape/quote as needed) " , " password " ) ;
parser . addOption ( walletPasswordOption ) ;
QCommandLineOption daemonAddressOption ( QStringList ( ) < < " daemon-address " , " Daemon address (IPv4:port) " , " daemonAddress " ) ;
parser . addOption ( daemonAddressOption ) ;
QCommandLineOption exportContactsOption ( QStringList ( ) < < " export-contacts " , " Output wallet contacts as CSV to specified path. " , " file " ) ;
parser . addOption ( exportContactsOption ) ;
QCommandLineOption exportTxHistoryOption ( QStringList ( ) < < " export-txhistory " , " Output wallet transaction history as CSV to specified path. " , " file " ) ;
parser . addOption ( exportTxHistoryOption ) ;
2021-04-04 11:05:20 +00:00
QCommandLineOption backgroundOption ( QStringList ( ) < < " daemon " , " Start WOWlet in the background and start a websocket server (IPv4:port) " , " backgroundAddress " ) ;
2021-03-27 18:59:21 +00:00
parser . addOption ( backgroundOption ) ;
QCommandLineOption backgroundPasswordOption ( QStringList ( ) < < " daemon-password " , " Password for connecting to the wowlet websocket service " , " backgroundPassword " ) ;
parser . addOption ( backgroundPasswordOption ) ;
2021-04-02 11:07:11 +00:00
QCommandLineOption openVROption ( QStringList ( ) < < " openvr " , " Start Wowlet OpenVR " ) ;
parser . addOption ( openVROption ) ;
2021-04-19 22:02:37 +00:00
QCommandLineOption openVRDebugOption ( QStringList ( ) < < " openvr-debug " , " Start the Wowlet VR interface without initializing OpenVR - for debugging purposes. Requires -DOPENVR=ON CMake definition. " ) ;
2021-04-02 11:07:11 +00:00
parser . addOption ( openVRDebugOption ) ;
2021-04-19 22:02:37 +00:00
QCommandLineOption androidDebugOption ( QStringList ( ) < < " android-debug " , " Start the Android interface without actually running on Android - for debugging purposes. Requires -DANDROID_DEBUG=ON CMake definition. " ) ;
parser . addOption ( androidDebugOption ) ;
2022-03-14 16:55:27 +00:00
QCommandLineOption backendHostOption ( QStringList ( ) < < " backend-host " , " specify your own `wowlet-backend` host " , " backend-host " ) ;
parser . addOption ( backendHostOption ) ;
QCommandLineOption backendPortOption ( QStringList ( ) < < " backend-port " , " specify your own `wowlet-backend` port " , " backend-port " ) ;
parser . addOption ( backendPortOption ) ;
QCommandLineOption backendTLS ( QStringList ( ) < < " backend-tls " , " `wowlet-backend` is running via TLS? 'wss://' and 'https://' will be used. " , " backend-tls " ) ;
parser . addOption ( backendTLS ) ;
2020-10-07 10:36:04 +00:00
auto parsed = parser . parse ( argv_ ) ;
if ( ! parsed ) {
qCritical ( ) < < parser . errorText ( ) ;
exit ( 1 ) ;
}
const QStringList args = parser . positionalArguments ( ) ;
bool debugMode = parser . isSet ( debugModeOption ) ;
bool localTor = parser . isSet ( useLocalTorOption ) ;
2020-12-21 20:34:36 +00:00
bool stagenet = false ;
bool testnet = false ;
2020-10-07 10:36:04 +00:00
bool quiet = parser . isSet ( quietModeOption ) ;
bool exportContacts = parser . isSet ( exportContactsOption ) ;
bool exportTxHistory = parser . isSet ( exportTxHistoryOption ) ;
2021-03-27 18:59:21 +00:00
bool backgroundAddressEnabled = parser . isSet ( backgroundOption ) ;
2021-04-02 11:07:11 +00:00
bool openVREnabled = parser . isSet ( openVROption ) ;
2021-03-27 18:59:21 +00:00
bool cliMode = exportContacts | | exportTxHistory | | backgroundAddressEnabled ;
2021-04-19 22:02:37 +00:00
bool androidDebug = parser . isSet ( androidDebugOption ) ;
bool android = false ;
# ifdef __ANDROID__
android = true ;
# endif
2021-03-27 18:59:21 +00:00
qRegisterMetaType < QVector < QString > > ( ) ;
2020-10-07 10:36:04 +00:00
2021-05-15 23:05:05 +00:00
# ifdef __ANDROID__
2021-04-19 22:02:37 +00:00
if ( android | | androidDebug ) {
QCoreApplication : : setAttribute ( Qt : : AA_EnableHighDpiScaling ) ;
QGuiApplication mobile_app ( argc , argv ) ;
auto * ctx = new AppContext ( & parser ) ;
auto * mobile = new mobile : : Mobile ( ctx , & parser , & mobile_app ) ;
return mobile_app . exec ( ) ;
}
2021-05-15 23:05:05 +00:00
# endif
2021-04-19 22:02:37 +00:00
2021-04-02 11:07:11 +00:00
if ( openVREnabled ) {
# ifdef HAS_OPENVR
2021-04-11 17:40:52 +00:00
QCoreApplication : : setAttribute ( Qt : : AA_EnableHighDpiScaling ) ;
2021-04-02 11:07:11 +00:00
QApplication vr_app ( argc , argv ) ;
auto * ctx = new AppContext ( & parser ) ;
2021-04-02 12:22:37 +00:00
auto * vr = new wowletvr : : WowletVR ( ctx , & parser , & vr_app ) ;
2021-04-02 11:07:11 +00:00
if ( vr - > errors . length ( ) > 0 )
return 1 ;
vr - > render ( ) ;
return vr_app . exec ( ) ;
# else
qCritical ( ) < < " Wowlet compiled without OpenVR support. " ;
exit ( 1 ) ;
# endif
}
2020-10-07 10:36:04 +00:00
if ( cliMode ) {
2021-04-02 11:07:11 +00:00
auto * ctx = new AppContext ( & parser ) ;
2020-10-07 10:36:04 +00:00
QCoreApplication cli_app ( argc , argv ) ;
ctx - > applicationPath = QString ( argv [ 0 ] ) ;
ctx - > isDebug = debugMode ;
auto * cli = new CLI ( ctx , & cli_app ) ;
QObject : : connect ( cli , & CLI : : closeApplication , & cli_app , & QCoreApplication : : quit ) ;
if ( exportContacts ) {
if ( ! quiet )
qInfo ( ) < < " CLI mode: Address book export " ;
cli - > mode = CLIMode : : CLIModeExportContacts ;
QTimer : : singleShot ( 0 , cli , & CLI : : run ) ;
} else if ( exportTxHistory ) {
if ( ! quiet )
qInfo ( ) < < " CLI mode: Transaction history export " ;
cli - > mode = CLIMode : : CLIModeExportTxHistory ;
2021-03-27 18:59:21 +00:00
QTimer : : singleShot ( 0 , cli , & CLI : : run ) ;
} else if ( backgroundAddressEnabled ) {
if ( ! quiet )
qInfo ( ) < < " CLI mode: daemonize " ;
cli - > mode = CLIMode : : CLIDaemonize ;
auto backgroundHostPort = parser . value ( backgroundOption ) ;
if ( ! backgroundHostPort . contains ( " : " ) ) {
qCritical ( ) < < " the format is: --background ipv4:port " ;
return 1 ;
}
auto spl = backgroundHostPort . split ( " : " ) ;
cli - > backgroundWebsocketAddress = spl . at ( 0 ) ;
cli - > backgroundWebsocketPort = ( quint16 ) spl . at ( 1 ) . toInt ( ) ;
cli - > backgroundWebsocketPassword = parser . value ( backgroundPasswordOption ) ;
if ( cli - > backgroundWebsocketPassword . isEmpty ( ) ) {
qCritical ( ) < < " --daemon-password needs to be set when using --daemon " ;
return 1 ;
}
2020-10-07 10:36:04 +00:00
QTimer : : singleShot ( 0 , cli , & CLI : : run ) ;
}
return QCoreApplication : : exec ( ) ;
}
QApplication : : setAttribute ( Qt : : AA_EnableHighDpiScaling ) ;
2020-10-11 18:02:23 +00:00
QApplication : : setAttribute ( Qt : : AA_DisableWindowContextHelpButton ) ;
2020-10-07 10:36:04 +00:00
QApplication : : setDesktopSettingsAware ( true ) ; // use system font
2021-03-30 09:52:29 +00:00
QApplication : : setApplicationVersion ( WOWLET_VERSION ) ;
2020-10-07 10:36:04 +00:00
QApplication app ( argc , argv ) ;
parser . process ( app ) ; // Parse again for --help and --version
if ( ! quiet ) {
QMap < QString , QString > info ;
info [ " Qt " ] = QT_VERSION_STR ;
2021-03-30 09:52:29 +00:00
info [ " WOWlet " ] = WOWLET_VERSION ;
2020-10-07 10:36:04 +00:00
if ( stagenet ) info [ " Mode " ] = " Stagenet " ;
else if ( testnet ) info [ " Mode " ] = " Testnet " ;
else info [ " Mode " ] = " Mainnet " ;
2021-04-19 22:02:37 +00:00
# ifndef QT_NO_SSL
2020-10-07 10:36:04 +00:00
info [ " SSL " ] = QSslSocket : : sslLibraryVersionString ( ) ;
info [ " SSL build " ] = QSslSocket : : sslLibraryBuildVersionString ( ) ;
2021-04-19 22:02:37 +00:00
# endif
2020-10-07 10:36:04 +00:00
for ( const auto & k : info . keys ( ) )
qWarning ( ) . nospace ( ) . noquote ( ) < < QString ( " %1: %2 " ) . arg ( k ) . arg ( info [ k ] ) ;
}
auto * ctx = new AppContext ( & parser ) ;
ctx - > applicationPath = QString ( argv [ 0 ] ) ;
ctx - > isDebug = debugMode ;
# if defined(Q_OS_MAC)
// For some odd reason, if we don't do this, QPushButton's
// need to be clicked *twice* in order to fire ?!
QFont fontDef = QApplication : : font ( ) ;
fontDef . setPointSize ( fontDef . pointSize ( ) + 1 ) ;
QApplication : : setFont ( fontDef ) ;
# endif
qInstallMessageHandler ( Utils : : applicationLogHandler ) ;
auto * mainWindow = new MainWindow ( ctx ) ;
return QApplication : : exec ( ) ;
}