From 51574b7396bc9bb917a1d442c3b3f7ff1cd31c2c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 27 Jan 2020 18:43:21 +0200 Subject: Refactor Browser::addPlugin to ::loadPlugins --- src/main.cpp | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 3394a84..e04f58a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,35 +98,6 @@ int main(int argc, char **argv) return -1; } - QVector plugins; - CommandHash_t pluginCommands; - - // Load plugins - [&]() { - Configuration conf; - spdlog::debug("plugins.path={}", conf.value("plugins.path").value()); - - const PluginLoader::SignatureState state( - conf.value("plugins.signature.ignored").value(), - conf.value("plugins.signature.checked").value(), - conf.value("plugins.signature.enforced").value()); - - for(const QString &path : Util::files(conf.value("plugins.path").value(), { "*.so", "*.dll" })) { - auto *loader = new PluginLoader(path, state); - const bool loaded = loader->load(); - spdlog::info("{} plugin {}", loaded ? "Loaded" : "Failed to load", qUtf8Printable(path)); - - if(loaded) { - plugins.append(loader); - auto *plugin = qobject_cast(loader->instance()); - pluginCommands.unite(plugin->commands()); - } else { - spdlog::warn("{}", qUtf8Printable(loader->errorString())); - delete loader; - } - } - }(); - // argc, argv, allowSecondary Browser app(argc, argv); // set this, otherwise the webview becomes black when using a stylesheet @@ -134,6 +105,7 @@ int main(int argc, char **argv) { Configuration conf; + if(conf.value("usebreakpad").value()) { CrashHandler::Context ctx( conf.value("path.crashdump").value(), @@ -145,6 +117,15 @@ int main(int argc, char **argv) spdlog::warn("Failed to install breakpad crash handler: {}", ctx.dumppath); } } + + // load plugins + app.loadPlugins(Util::files(conf.value("plugins.path").value(), { "*.so", "*.dll" }), + [](const auto *loader) { + if(loader->isLoaded()) + spdlog::info("Loaded plugin [{}]", qUtf8Printable(loader->fileName())); + else + spdlog::warn("Loading plugin [{}] failed: {}", qUtf8Printable(loader->fileName()), qUtf8Printable(loader->errorString())); + }); } const auto profile = []() { @@ -152,16 +133,12 @@ int main(int argc, char **argv) return c.value("profile.default").value(); }(); - app.setup(plugins); + app.setup(); QStringList urls; for(const auto &u : args::get(cmd_args)) { - if(pluginCommands.contains(QString::fromStdString(u))) { - return pluginCommands.value(QString::fromStdString(u))(); - } else { - urls.append(QString::fromStdString(u)); - } + urls.append(QString::fromStdString(u)); } if(urls.isEmpty()) urls.append(QString()); -- cgit v1.2.1