/* * This file is part of smolbote. It's copyrighted by the contributors recorded * in the version control history of the file, available from its original * location: https://neueland.iserlohn-fortress.net/smolbote.hg * * SPDX-License-Identifier: GPL-3.0 */ #include "commandline.h" #include "mainwindow/mainwindow.h" #include "version.h" #include "webengine/webprofile.h" #include "browser.h" #include #include int main(int argc, char **argv) { Browser app(argc, argv); CommandLine parser; parser.parseCommandLine(app); // create and load configuration std::shared_ptr config = std::make_shared(); config->read(parser.value(parser.configOption)); // parse command-line overrides // we assume the users knows what they're doing, so we only pass the unknown options to program_options // passing any unknown options though will cause it to fail, so we need to filter out the regular options // unfortunately, QCommandLineParser will only give us the unknown option // names, so we need to build a list, add them as options, reparse, and then // we get their values if(!parser.unknownOptions.isEmpty()) { int _argc = parser.unknownOptions.length() + 1; const char *_argv[_argc]; // program_options requires 0 to be the program name, otherwise it seems to fail _argv[0] = qUtf8Printable(app.arguments().at(0)); for(int i = 1; i < _argc; ++i) { _argv[i] = qUtf8Printable(QString("--%1=%2").arg(parser.unknownOptions[i - 1].names().at(0), parser.value(parser.unknownOptions[i - 1]))); } config->parse(_argc, _argv); } app.setConfiguration(config); // set up socket bool isSingleInstance = app.bindLocalSocket(parser.value(parser.socketOption)); #ifdef QT_DEBUG qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(parser.value(parser.socketOption)), isSingleInstance ? "true" : "false"); #endif // if we are the only instance, set up the browser if(isSingleInstance) { if(parser.isSet(parser.profileOption)) app.setup(parser.value(parser.profileOption)); else app.setup(QString::fromStdString(config->value("profile.default").value())); QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession); } app.sendMessage(parser.value(parser.profileOption), parser.isSet(parser.newWindowOption), parser.positionalArguments()); if(isSingleInstance) return app.exec(); else return 0; }