diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 149 | ||||
-rw-r--r-- | src/settings.h.in | 29 |
2 files changed, 87 insertions, 91 deletions
diff --git a/src/main.cpp b/src/main.cpp index dad1f73..3976f53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,7 +77,9 @@ int main(int argc, char **argv) return builtins::build(); // create and load configuration - spdlog::debug("Loading configuration {}", init_conf(args::get(cmd_config))); + auto conf = init_conf(args::get(cmd_config)); + conf.ptr->make_global(); + spdlog::debug("Loading configuration {}", conf.path); if(cmd_args) { const auto front = args::get(cmd_args).front(); @@ -87,92 +89,87 @@ int main(int argc, char **argv) } } - } catch(args::Help &) { - std::cout << parser; - return 0; - - } catch(args::Error &e) { - std::cerr << e.what() << std::endl; - std::cerr << parser; - return -1; - } - - // argc, argv, allowSecondary - Browser app(argc, argv); - // set this, otherwise the webview becomes black when using a stylesheet - app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); - - { - Configuration conf; - - if(conf.value<bool>("usebreakpad").value()) { - CrashHandler::Context ctx( - conf.value<std::string>("path.crashdump").value(), - conf.value<std::string>("path.crashhandler").value()); - - if(CrashHandler::install_handler(ctx)) { - spdlog::info("Installed breakpad crash handler: {}", ctx.dumppath); - } else { - spdlog::warn("Failed to install breakpad crash handler: {}", ctx.dumppath); + // argc, argv, allowSecondary + Browser app(argc, argv); + // set this, otherwise the webview becomes black when using a stylesheet + app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); + + { + if(conf.ptr->value<bool>("usebreakpad").value()) { + CrashHandler::Context ctx( + conf.ptr->value<std::string>("path.crashdump").value(), + conf.ptr->value<std::string>("path.crashhandler").value()); + + if(CrashHandler::install_handler(ctx)) { + spdlog::info("Installed breakpad crash handler: {}", ctx.dumppath); + } else { + spdlog::warn("Failed to install breakpad crash handler: {}", ctx.dumppath); + } } - } - // load plugins - for(const QString &path : Util::files(conf.value<QString>("plugins.path").value(), { "*.so", "*.dll" })) { - if(app.loadPlugin(path)) { - spdlog::debug("Loaded plugin [{}]", qUtf8Printable(path)); - } else { - spdlog::warn("Failed loading plugin [{}]", qUtf8Printable(path)); + // load plugins + for(const QString &path : Util::files(conf.ptr->value<QString>("plugins.path").value(), { "*.so", "*.dll" })) { + if(app.loadPlugin(path)) { + spdlog::debug("Loaded plugin [{}]", qUtf8Printable(path)); + } else { + spdlog::warn("Failed loading plugin [{}]", qUtf8Printable(path)); + } } } - } - const auto profile = []() { - Configuration c; - return c.value<QString>("profile.default").value(); - }(); + const auto profile = conf.ptr->value<QString>("profile.default").value(); - QStringList urls; - for(const auto &u : args::get(cmd_args)) { - urls.append(QString::fromStdString(u)); - } - if(urls.isEmpty()) { - urls.append(QString()); - } + QStringList urls; + for(const auto &u : args::get(cmd_args)) { + urls.append(QString::fromStdString(u)); + } + if(urls.isEmpty()) { + urls.append(QString()); + } - // if app is primary, create new sessions from received messages - if(app.isPrimary() && !cmd_noRemote) { - QObject::connect(&app, &Browser::receivedMessage, &app, [&app](quint32 instanceId, QByteArray message) { - Q_UNUSED(instanceId); - JsonSession session(message); - app.open(session.get()); - }); - } + // if app is primary, create new sessions from received messages + if(app.isPrimary() && !cmd_noRemote) { + QObject::connect(&app, &Browser::receivedMessage, &app, [&app](quint32 instanceId, QByteArray message) { + Q_UNUSED(instanceId); + JsonSession session(message); + app.open(session.get()); + }); + } - { - const auto session = [&]() { - if(cmd_session) { - QFile sessionJson(QString::fromStdString(args::get(cmd_session))); - if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { - return JsonSession(sessionJson.readAll()); + { + const auto session = [&]() { + if(cmd_session) { + QFile sessionJson(QString::fromStdString(args::get(cmd_session))); + if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { + return JsonSession(sessionJson.readAll()); + } } - } - if(cmd_pickSession) { - SessionDialog dlg; - if(const auto pick = dlg.pickSession()) { - return JsonSession(pick.value()); + if(cmd_pickSession) { + SessionDialog dlg; + if(const auto pick = dlg.pickSession()) { + return JsonSession(pick.value()); + } } + return JsonSession(profile, urls); + }(); + + if(app.isPrimary() || cmd_noRemote) { + app.open(session.get()); + } else { + // app is secondary and not standalone + return app.sendMessage(session.serialize()); } - return JsonSession(profile, urls); - }(); - - if(app.isPrimary() || cmd_noRemote) { - app.open(session.get()); - } else { - // app is secondary and not standalone - return app.sendMessage(session.serialize()); } - } - return app.exec(); + return app.exec(); + + } catch(args::Help &) { + std::cout << parser; + return 0; + + } catch(args::Error &e) { + std::cerr << e.what() << std::endl; + std::cerr << parser; + return -1; + } } diff --git a/src/settings.h.in b/src/settings.h.in index 88fbcf5..605288e 100644 --- a/src/settings.h.in +++ b/src/settings.h.in @@ -4,29 +4,28 @@ #include <configuration.h> #include <fstream> -inline const std::string init_conf(const std::string &path) +inline auto init_conf(const std::string &path) { - auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({ + struct { + std::string path; + std::unique_ptr<Configuration> ptr; + } conf; + + conf.ptr = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({ @__DEFAULT_CFG__ }); - const std::string cfgpath = [&]() { - if(path.empty()) - return value_map->value<std::string>("poi.cfg.path").value(); - - auto p = path; - if(p.front() == '~') - p.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()); - return p; - }(); + conf.path = path.empty() ? conf.ptr->value<std::string>("poi.cfg.path").value() : path; + if(conf.path.front() == '~') { + conf.path.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()); + }; std::fstream fs; - fs.open(cfgpath, std::fstream::in); + fs.open(conf.path, std::fstream::in); if(fs.is_open()) { - value_map->read(fs); + conf.ptr->read(fs); fs.close(); } - Configuration::move_global(std::move(value_map)); - return cfgpath; + return conf; } |