File indexing completed on 2024-04-28 16:51:32
0001 /* 0002 SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de> 0003 SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 #include <QApplication> 0009 #include <QDBusConnection> 0010 #include <QDebug> 0011 0012 #include <KCrash> 0013 0014 #include "abstractbrowserplugin.h" 0015 #include "connection.h" 0016 #include "pluginmanager.h" 0017 0018 #include "downloadplugin.h" 0019 #include "historyrunnerplugin.h" 0020 #include "kdeconnectplugin.h" 0021 #include "mprisplugin.h" 0022 #include "purposeplugin.h" 0023 #include "settings.h" 0024 #include "tabsrunnerplugin.h" 0025 0026 void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) 0027 { 0028 QJsonObject data; 0029 data[QStringLiteral("subsystem")] = QStringLiteral("debug"); 0030 switch (type) { 0031 case QtDebugMsg: 0032 case QtInfoMsg: 0033 data[QStringLiteral("action")] = QStringLiteral("debug"); 0034 break; 0035 default: 0036 data[QStringLiteral("action")] = QStringLiteral("warning"); 0037 } 0038 0039 QJsonObject payload{{QStringLiteral("message"), msg}}; 0040 0041 // NOTE For compatibility they are still action debug/warning 0042 switch (type) { 0043 case QtInfoMsg: 0044 payload.insert(QStringLiteral("severity"), QStringLiteral("info")); 0045 break; 0046 case QtCriticalMsg: 0047 payload.insert(QStringLiteral("severity"), QStringLiteral("critical")); 0048 break; 0049 case QtFatalMsg: 0050 payload.insert(QStringLiteral("severity"), QStringLiteral("fatal")); 0051 break; 0052 default: 0053 break; 0054 } 0055 0056 if (context.file) { 0057 payload.insert(QStringLiteral("file"), QString::fromUtf8(context.file)); 0058 } 0059 if (context.line) { 0060 payload.insert(QStringLiteral("line"), context.line); 0061 } 0062 if (context.function) { 0063 payload.insert(QStringLiteral("function"), QString::fromUtf8(context.function)); 0064 } 0065 if (context.category) { 0066 payload.insert(QStringLiteral("category"), QString::fromUtf8(context.category)); 0067 } 0068 0069 data[QStringLiteral("payload")] = payload; 0070 0071 Connection::self()->sendData(data); 0072 } 0073 0074 int main(int argc, char *argv[]) 0075 { 0076 // otherwise when logging out, session manager will ask the host to quit 0077 // (it's a "regular X app" after all) and then the browser will complain 0078 qunsetenv("SESSION_MANAGER"); 0079 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0080 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0081 #endif 0082 QApplication a(argc, argv); 0083 // otherwise will close when download job finishes 0084 a.setQuitOnLastWindowClosed(false); 0085 // applicationName etc will be set in Settings once the browser identifies to us 0086 0087 qInstallMessageHandler(msgHandler); 0088 0089 KCrash::initialize(); 0090 0091 // NOTE if you add a new plugin here, make sure to adjust the 0092 // "DEFAULT_EXTENSION_SETTINGS" in constants.js or else it won't 0093 // even bother loading your shiny new plugin! 0094 0095 PluginManager::self().addPlugin(&Settings::self()); 0096 PluginManager::self().addPlugin(new KDEConnectPlugin(&a)); 0097 PluginManager::self().addPlugin(new DownloadPlugin(&a)); 0098 PluginManager::self().addPlugin(new TabsRunnerPlugin(&a)); 0099 PluginManager::self().addPlugin(new HistoryRunnerPlugin(&a)); 0100 PluginManager::self().addPlugin(new MPrisPlugin(&a)); 0101 PluginManager::self().addPlugin(new PurposePlugin(&a)); 0102 0103 // TODO make this prettier, also prevent unloading them at any cost 0104 PluginManager::self().loadPlugin(&Settings::self()); 0105 0106 QString serviceName = QStringLiteral("org.kde.plasma.browser_integration"); 0107 if (!QDBusConnection::sessionBus().registerService(serviceName)) { 0108 // now try appending PID in case multiple hosts are running 0109 serviceName.append(QLatin1String("-")).append(QString::number(QCoreApplication::applicationPid())); 0110 if (!QDBusConnection::sessionBus().registerService(serviceName)) { 0111 qWarning() << "Failed to register DBus service name" << serviceName; 0112 } 0113 } 0114 0115 return a.exec(); 0116 }