aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-01-27 18:43:21 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-01-27 18:43:21 +0200
commit51574b7396bc9bb917a1d442c3b3f7ff1cd31c2c (patch)
tree1632b836d19ea37eb841235a222118c3d022d732
parentpluginloader: generate keys by meson (diff)
downloadsmolbote-51574b7396bc9bb917a1d442c3b3f7ff1cd31c2c.tar.xz
Refactor Browser::addPlugin to ::loadPlugins
-rw-r--r--Kconfig14
-rw-r--r--src/browser.cpp38
-rw-r--r--src/browser.h8
-rw-r--r--src/main.cpp47
-rw-r--r--src/mainwindow/menubar.cpp2
5 files changed, 41 insertions, 68 deletions
diff --git a/Kconfig b/Kconfig
index 62309b0..1564f19 100644
--- a/Kconfig
+++ b/Kconfig
@@ -144,20 +144,20 @@ config USEPLUGINS
menu "Plugin Settings"
depends on USEPLUGINS
- config plugins.path
+ config PLUGINS_PATH
string "Plugin load location"
default "~/.config/smolbote/plugins.d"
- choice PLUGIN_SIGNATURE_CHECK
+ choice PLUGINS_SIGNATURE_CHECK
bool "Plugin Signature enforcement"
- default PLUGIN_SIGNATURE_CHECKED
- config PLUGIN_SIGNATURE_IGNORED
+ default PLUGINS_SIGNATURE_CHECKED
+ config PLUGINS_SIGNATURE_IGNORED
bool "Don't check plugin signatures"
- config PLUGIN_SIGNATURE_CHECKED
+ config PLUGINS_SIGNATURE_CHECKED
bool "Don't load plugins with invalid signatures"
- config PLUGIN_SIGNATURE_ENFORCED
+ config PLUGINS_SIGNATURE_ENFORCED
bool "Only load plugins with valid signatures"
endchoice
- config PLUGIN_SIGNATURE_HASH
+ config PLUGINS_SIGNATURE_HASH
string "Hashing algorithm used by the signature"
default "SHA256"
endmenu
diff --git a/src/browser.cpp b/src/browser.cpp
index 86d8f13..20367aa 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -125,10 +125,10 @@ void Browser::loadProfiles(const QStringList &profilePaths)
}
}
-QPluginLoader *Browser::addPlugin(const QString &path)
+void Browser::loadPlugins(const QStringList &paths, const std::function<void(const QPluginLoader *)> &callback)
{
- if(path.isEmpty())
- return nullptr;
+ if(paths.isEmpty())
+ return;
Configuration conf;
const PluginLoader::SignatureState state(
@@ -136,33 +136,29 @@ QPluginLoader *Browser::addPlugin(const QString &path)
conf.value<bool>("plugins.signature.checked").value(),
conf.value<bool>("plugins.signature.enforced").value());
- auto *loader = new PluginLoader(path, state, this);
- const bool loaded = loader->load();
- spdlog::info("Loading plugin [{}]: {}", qUtf8Printable(path), loaded ? "passed" : "failed");
+ for(const auto &path : paths) {
+ auto *loader = new PluginLoader(path, state, this);
+ const bool loaded = loader->load();
- if(!loaded) {
- delete loader;
- return nullptr;
- }
+ callback(loader);
- auto *info = new PluginInfo(loader);
- m_plugins.append(info);
+ if(!loaded) {
+ delete loader;
+ } else {
+ auto *info = new PluginInfo(loader);
+ m_plugins.append(info);
- for(MainWindow *window : qAsConst(m_windows)) {
- addPluginTo(info, window);
+ for(MainWindow *window : qAsConst(m_windows)) {
+ addPluginTo(info, window);
+ }
+ }
}
-
- return loader;
}
-void Browser::setup(QVector<QPluginLoader *> plugins)
+void Browser::setup()
{
Configuration conf;
- for(QPluginLoader *loader : plugins) {
- m_plugins.append(new PluginInfo(loader));
- }
-
if(auto stylesheet = conf.value<QString>("browser.stylesheet")) {
QFile f(stylesheet.value());
if(f.open(QIODevice::ReadOnly)) {
diff --git a/src/browser.h b/src/browser.h
index d4117ba..ec6bb57 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -40,10 +40,10 @@ public:
// interface
[[deprecated]] const QList<QPair<QString, Profile *>> profileList() const;
void loadProfiles(const QStringList &profilePaths);
-
- QPluginLoader *addPlugin(const QString &path = QString());
-
- void setup(QVector<QPluginLoader *> plugins);
+ void loadPlugins(
+ const QStringList &paths,
+ const std::function<void(const QPluginLoader *)> &callback = [](const auto) {});
+ void setup();
const QVector<MainWindow *> windows() const
{
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<QPluginLoader *> plugins;
- CommandHash_t pluginCommands;
-
- // Load plugins
- [&]() {
- Configuration conf;
- spdlog::debug("plugins.path={}", conf.value<std::string>("plugins.path").value());
-
- const PluginLoader::SignatureState state(
- conf.value<bool>("plugins.signature.ignored").value(),
- conf.value<bool>("plugins.signature.checked").value(),
- conf.value<bool>("plugins.signature.enforced").value());
-
- for(const QString &path : Util::files(conf.value<QString>("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<PluginInterface *>(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<bool>("usebreakpad").value()) {
CrashHandler::Context ctx(
conf.value<std::string>("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<QString>("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<QString>("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());
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp
index eecb61a..27a8561 100644
--- a/src/mainwindow/menubar.cpp
+++ b/src/mainwindow/menubar.cpp
@@ -137,7 +137,7 @@ MenuBar::MenuBar(MainWindow *parent)
smolbote->addSeparator();
smolbote->addAction(tr("Load Plugin"), browser, [browser]() {
const QString path = QFileDialog::getOpenFileName(nullptr, tr("Select Plugin"), QDir::homePath(), tr("Plugins (*.so)"));
- browser->addPlugin(path);
+ browser->loadPlugins(QStringList(path));
});
pluginInsertLocation = smolbote->addSeparator();