diff --git a/CMakeLists.txt b/CMakeLists.txt index ba51fcb3..664977b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,91 +1,92 @@ cmake_minimum_required(VERSION 3.0) project(plasma-browser-integration) set(PROJECT_VERSION "5.16.80") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Gui DBus Widgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS KIO I18n Config + Crash DBusAddons Notifications Runner Activities ) add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) #add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) # Options option(INSTALL_CHROME_MANIFEST "Whether to install a configuration file that makes Chrome automatically download the extension from the store" FALSE) add_feature_info(INSTALL_CHROME_MANIFEST ${INSTALL_CHROME_MANIFEST} "Install extension from Chrome store automatically") # in ubuntu and derivatives, this should be installed in the chromium-browser/extensions, # but since this is distribution specific path, let's use what upstream uses # ideally ubuntu and derivatives should patch this in their packaging set(CHROMIUM_EXTENSIONS_DIR "chromium" CACHE STRING "Directory name to install Chromium extensions into") add_feature_info(CHROMIUM_EXTENSIONS_DIR On "Directory name to install Chromium extensions into is '${CHROMIUM_EXTENSIONS_DIR}'") option(COPY_MESSAGING_HOST_FILE_HOME "Copy the native messaging hosts json file to user home dir" FALSE) add_feature_info(COPY_MESSAGING_HOST_FILE_HOME ${COPY_MESSAGING_HOST_FILE_HOME} "Enable this option to copy the native messaging hosts json file to home dir if you install plasma-browser-integration to custom prefix (non-/usr)") set(MOZILLA_DIR "${CMAKE_INSTALL_PREFIX}/lib/mozilla" CACHE STRING "Mozilla directory") add_feature_info(MOZILLA_DIR On "Mozilla directory is '${MOZILLA_DIR}'") add_subdirectory(host) add_subdirectory(tabsrunner) add_subdirectory(reminder) if(NOT DEFINED CHROME_EXTENSION_ID) # The extension ID is based on the key used to sign the extension # see https://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development set(CHROME_EXTENSION_ID "cimiefiiaegbelhefglklhhakcgmhkai") endif() # TODO configure manifest.json configure_file(org.kde.plasma.chrome_integration.json.in org.kde.plasma.chrome_integration.json @ONLY) configure_file(org.kde.plasma.firefox_integration.json.in org.kde.plasma.firefox_integration.json @ONLY) # #chromium install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION ${KDE_INSTALL_FULL_SYSCONFDIR}/chromium/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) # #google-chrome install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION ${KDE_INSTALL_FULL_SYSCONFDIR}/opt/chrome/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) # firefox install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.firefox_integration.json DESTINATION ${MOZILLA_DIR}/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) if (COPY_MESSAGING_HOST_FILE_HOME) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.firefox_integration.json DESTINATION $ENV{HOME}/.mozilla/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION $ENV{HOME}/.config/chromium/NativeMessagingHosts/ RENAME org.kde.plasma.browser_integration.json) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION $ENV{HOME}/.config/google-chrome/NativeMessagingHosts/ RENAME org.kde.plasma.browser_integration.json) endif() if (INSTALL_CHROME_MANIFEST) # Install a policy to have browsers automatically add the extension # google-chrome install(FILES chrome_install_from_store_policy DESTINATION ${KDE_INSTALL_DATADIR}/google-chrome/extensions RENAME ${CHROME_EXTENSION_ID}.json) # chromium install(FILES chrome_install_from_store_policy DESTINATION ${KDE_INSTALL_DATADIR}/${CHROMIUM_EXTENSIONS_DIR}/extensions RENAME ${CHROME_EXTENSION_ID}.json) endif() # TODO firefox feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 136b07f2..35d9eb64 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -1,31 +1,32 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasma-browser-integration-host\") set(HOST_SOURCES main.cpp connection.cpp pluginmanager.cpp settings.cpp mprisplugin.cpp abstractbrowserplugin.cpp kdeconnectplugin.cpp downloadplugin.cpp downloadjob.cpp tabsrunnerplugin.cpp ) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.plasma.browser_integration.TabsRunner.xml tabsrunnerplugin.h TabsRunnerPlugin) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.plasma.browser_integration.Settings.xml settings.h Settings) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.xml mprisplugin.h MPrisPlugin mprisroot MPrisRoot) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.Player.xml mprisplugin.h MPrisPlugin mprisplayer MPrisPlayer) add_executable(plasma-browser-integration-host ${HOST_SOURCES}) target_link_libraries( plasma-browser-integration-host Qt5::DBus Qt5::Gui Qt5::Widgets + KF5::Crash KF5::I18n KF5::KIOCore ) install(TARGETS plasma-browser-integration-host ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/host/main.cpp b/host/main.cpp index ac232b8d..892bfe65 100644 --- a/host/main.cpp +++ b/host/main.cpp @@ -1,94 +1,98 @@ /* Copyright (C) 2017 by Kai Uwe Broulik Copyright (C) 2017 by David Edmundson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include +#include + #include "connection.h" #include "pluginmanager.h" #include "abstractbrowserplugin.h" #include "settings.h" #include "kdeconnectplugin.h" #include "downloadplugin.h" #include "tabsrunnerplugin.h" #include "mprisplugin.h" void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_UNUSED(type); Q_UNUSED(context); QJsonObject data; data[QStringLiteral("subsystem")] = QStringLiteral("debug"); switch(type) { case QtDebugMsg: case QtInfoMsg: data[QStringLiteral("action")] = QStringLiteral("debug"); break; default: data[QStringLiteral("action")] = QStringLiteral("warning"); } data[QStringLiteral("payload")] = QJsonObject({{QStringLiteral("message"), msg}}); Connection::self()->sendData(data); } int main(int argc, char *argv[]) { // otherwise when logging out, session manager will ask the host to quit // (it's a "regular X app" after all) and then the browser will complain qunsetenv("SESSION_MANAGER"); QApplication a(argc, argv); // otherwise will close when download job finishes a.setQuitOnLastWindowClosed(false); // applicationName etc will be set in Settings once the browser identifies to us qInstallMessageHandler(msgHandler); + KCrash::initialize(); + // NOTE if you add a new plugin here, make sure to adjust the // "DEFAULT_EXTENSION_SETTINGS" in constants.js or else it won't // even bother loading your shiny new plugin! PluginManager::self().addPlugin(&Settings::self()); PluginManager::self().addPlugin(new KDEConnectPlugin(&a)); PluginManager::self().addPlugin(new DownloadPlugin(&a)); PluginManager::self().addPlugin(new TabsRunnerPlugin(&a)); PluginManager::self().addPlugin(new MPrisPlugin(&a)); // TODO make this prettier, also prevent unloading them at any cost PluginManager::self().loadPlugin(&Settings::self()); QString serviceName = QStringLiteral("org.kde.plasma.browser_integration"); if (!QDBusConnection::sessionBus().registerService(serviceName)) { // now try appending PID in case multiple hosts are running serviceName.append(QLatin1String("-")).append(QString::number(QCoreApplication::applicationPid())); if (!QDBusConnection::sessionBus().registerService(serviceName)) { qWarning() << "Failed to register DBus service name" << serviceName; } } return a.exec(); }