aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 52df7ac1f554df00c81c460fc7e8418c44f0a13b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * 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 "browser.h"
#include "commandline.h"
#include "mainwindow/mainwindow.h"
#include "version.h"
#include "webengine/webprofile.h"
#include <configuration/configuration.h>
#include <memory>

int main(int argc, char **argv)
{
    Browser app(argc, argv);

    CommandLine parser;
    parser.parseCommandLine(app);

    // create and load configuration
    std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
    config->read(parser.value(parser.configOption));

    if(!parser.unknownOptionNames().isEmpty()) {
        qDebug("config->parse: %s", config->parse(argc, argv) ? "true" : "false");
    }

    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<std::string>("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;
}