aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp17
-rw-r--r--src/browser.h8
-rw-r--r--src/main.cpp16
3 files changed, 39 insertions, 2 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 09db2d1..91ba4f8 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -82,6 +82,14 @@ void Browser::setup(const QString &defaultProfile)
// plugins
m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value())));
+ // register commands
+ for(Plugin p : m_plugins) {
+ auto *plugin = qobject_cast<PluginInterface *>(p.instance.get());
+ if(plugin) {
+ m_commands.unite(plugin->commands());
+ }
+ }
+
// url request filter
m_urlFilter = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value()));
@@ -113,6 +121,15 @@ void Browser::setup(const QString &defaultProfile)
}
}
+void Browser::command(const QString &command)
+{
+ if(m_commands.contains(command)) {
+ m_commands.value(command)();
+ } else {
+ qWarning("No such command: %s", qUtf8Printable(command));
+ }
+}
+
void Browser::createSession(const QString &profileName, bool newWindow, const QStringList &urls)
{
if(m_windows.isEmpty()) {
diff --git a/src/browser.h b/src/browser.h
index 01de9bb..e5df9de 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -14,6 +14,7 @@
#include <QVector>
#include <memory>
#include <interfaces.h>
+#include <functional>
QVector<Plugin> loadPlugins(const QString &location);
@@ -34,6 +35,12 @@ public:
void setConfiguration(std::shared_ptr<Configuration> &config);
void setup(const QString &defaultProfile);
+ void command(const QString &command);
+ QStringList commands() const
+ {
+ return m_commands.keys();
+ }
+
public slots:
void createSession(const QString &profileName, bool newWindow, const QStringList &urls);
MainWindow *createWindow();
@@ -46,6 +53,7 @@ private:
QVector<MainWindow *> m_windows;
QVector<Plugin> m_plugins;
+ QHash<QString, std::function<void()>> m_commands;
};
#endif // SMOLBOTE_BROWSER_H
diff --git a/src/main.cpp b/src/main.cpp
index f1ac1ae..d578d24 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -49,6 +49,20 @@ int main(int argc, char **argv)
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
app.setConfiguration(config);
+ app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
+
+ if(config->exists("commands")) {
+ for(const QString &cmd : app.commands()) {
+ std::cout << cmd.toStdString() << std::endl;
+ }
+ return 0;
+ }
+
+ if(config->exists("command")) {
+ app.command(QString::fromStdString(config->value<std::string>("command").value()));
+ return 0;
+ }
+
// set up socket
bool isSingleInstance = app.bindLocalSocket(QString::fromStdString(config->value<std::string>("socket").value()));
#ifdef QT_DEBUG
@@ -66,12 +80,10 @@ int main(int argc, char **argv)
}
}
- app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession);
}
app.sendMessage("", false, config->positionalArguments());
-
if(isSingleInstance)
return app.exec();
else