Commit 34eacf89 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Run only a single instance, and open urls in the same

parent ed537fcd
......@@ -32,7 +32,7 @@ include(KDECompilerSettings NO_POLICY_SCOPE)
################# Find dependencies #################
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui Svg QuickControls2 Sql)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 Purpose I18n Config CoreAddons)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 Purpose I18n Config CoreAddons DBusAddons)
# Necessary to support QtWebEngine installed in a different prefix than the rest of Qt (e.g flatpak)
find_package(Qt5WebEngine REQUIRED)
......
......@@ -31,6 +31,7 @@ target_link_libraries(angelfish
KF5::I18n
KF5::ConfigCore
KF5::ConfigGui
KF5::DBusAddons
)
install(TARGETS angelfish ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
......
......@@ -86,6 +86,7 @@ QString BrowserManager::initialUrl() const
void BrowserManager::setInitialUrl(const QString &initialUrl)
{
m_initialUrl = initialUrl;
Q_EMIT initialUrlChanged();
}
BrowserManager *BrowserManager::instance()
......
......@@ -25,6 +25,7 @@
#include <KLocalizedContext>
#include <KLocalizedString>
#include <KDBusService>
#include "bookmarkshistorymodel.h"
#include "browsermanager.h"
......@@ -64,14 +65,35 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// QML loading
QQmlApplicationEngine engine;
// Open links in the already running window when e.g clicked on in another application.
KDBusService service(KDBusService::Unique, &app);
QObject::connect(&service, &KDBusService::activateRequested, &app, [&parser, &engine](const QStringList &arguments) {
parser.parse(arguments);
if (!parser.positionalArguments().isEmpty()) {
const QString initialUrl = QUrl::fromUserInput(parser.positionalArguments().constFirst()).toString();
const auto *webbrowserWindow = engine.rootObjects().first();
if (!webbrowserWindow) {
qWarning() << "No webbrowser window is open, can't open the url";
return;
}
// Can be normal or private web view, whatever is open right now;
const auto *currentListWebView = webbrowserWindow->property("tabs").value<QObject *>();
auto *currentTabsModel = currentListWebView->property("tabsModel").value<TabsModel *>();
currentTabsModel->newTab(initialUrl);
}
});
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.addImageProvider(IconImageProvider::providerId(), new IconImageProvider(&engine));
// initial url command line parameter
QString initialUrl;
if (!parser.positionalArguments().isEmpty())
initialUrl = QUrl::fromUserInput(parser.positionalArguments().constFirst()).toString();
if (!parser.positionalArguments().isEmpty()) {
const QString initialUrl = QUrl::fromUserInput(parser.positionalArguments().constFirst()).toString();
BrowserManager::instance()->setInitialUrl(initialUrl);
}
// Exported types
qmlRegisterType<BookmarksHistoryModel>("org.kde.mobile.angelfish", 1, 0, "BookmarksHistoryModel");
......@@ -84,8 +106,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
return static_cast<QObject *>(new UrlUtils());
});
BrowserManager::instance()->setInitialUrl(initialUrl);
// Browser Manager
qmlRegisterSingletonType<BrowserManager>("org.kde.mobile.angelfish", 1, 0, "BrowserManager", [](QQmlEngine *, QJSEngine *) -> QObject * {
return static_cast<QObject *>(BrowserManager::instance());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment