1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Add basic kde wallpaper installation

This commit is contained in:
Elias Steurer 2021-12-03 14:23:45 +01:00
parent 41fb12c6b1
commit 996526c1cd
6 changed files with 84 additions and 17 deletions

View File

@ -1,6 +1,7 @@
project(CMake)
set(FILES # cmake-format: sortable
CopyRecursive.cmake
QtUpdateTranslations.cmake)
add_custom_target(

29
CMake/CopyRecursive.cmake Normal file
View File

@ -0,0 +1,29 @@
# Copies all files with the same hierarchy (folder)
# via configure_file but only when the file content is different:
#
# copy_recursive(${SOURCE_PATH} ${DESTINATION_PATH} ${REGEX})
#
# If you want to copy all files simply set the parameter to: "*"
# Example:
#
# include(CopyRecursive)
# copy_recursive(${CMAKE_CURRENT_SOURCE_DIR}/kde/ScreenPlay ${CMAKE_BINARY_DIR}/bin/kde/ScreenPlay "*")
#
function(copy_recursive SOURCE_PATH DESTINATION_PATH REGEX)
file(GLOB_RECURSE
FILES
${SOURCE_PATH}
"${SOURCE_PATH}/${REGEX}")
foreach(file ${FILES})
# To recreate the same folder structure we first need to read the base folder
file(RELATIVE_PATH RELATIVE_FILE_PATH ${SOURCE_PATH} ${file})
get_filename_component(FOLDER ${RELATIVE_FILE_PATH} DIRECTORY ${SOURCE_PATH})
file(MAKE_DIRECTORY ${DESTINATION_PATH}/${FOLDER} )
message(STATUS "${file} - ${DESTINATION_PATH}/${RELATIVE_FILE_PATH}")
configure_file(${file} "${DESTINATION_PATH}/${RELATIVE_FILE_PATH}" COPYONLY)
endforeach()
endfunction()

View File

@ -186,8 +186,6 @@ add_library(ScreenPlayLib ${SOURCES} ${HEADER} ${RESOURCES} ${FONTS})
target_include_directories(ScreenPlayLib PUBLIC ./ src/ ${LibArchive_INCLUDE_DIRS})
find_package(LibArchive REQUIRED)
target_link_libraries(
ScreenPlayLib
PUBLIC ScreenPlaySDK

View File

@ -2,6 +2,7 @@
#include "steam/steam_qt_enums_generated.h"
#include <QProcessEnvironment>
#include <QVersionNumber>
namespace ScreenPlay {
/*!
@ -99,7 +100,6 @@ App::App()
qRegisterMetaType<MonitorListModel*>();
qRegisterMetaType<ProfileListModel*>();
// TODO: This is a workaround because I don't know how to
// init this in the ScreenPlayWorkshop plugin.
// Move to workshop plugin.
@ -215,6 +215,9 @@ void App::init()
// Needed for macos .app files
m_mainWindowEngine->addPluginPath(QGuiApplication::instance()->applicationDirPath());
#endif
if (m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE) {
setupKDE();
}
m_mainWindowEngine->load(QUrl(QStringLiteral("qrc:/ScreenPlay/main.qml")));
// Must be called last to display a error message on startup by the qml engine
@ -247,31 +250,61 @@ bool App::setupKDE()
qInfo() << qgetenv("XDG_CURRENT_DESKTOP");
QProcess plasmaShellVersionProcess;
plasmaShellVersionProcess.start("plasmashell",{"--version"});
plasmaShellVersionProcess.start("plasmashell", { "--version" });
plasmaShellVersionProcess.waitForFinished();
QString versionOut = plasmaShellVersionProcess.readAll();
if(!versionOut.contains("plasmashell ")){
QString versionOut = plasmaShellVersionProcess.readAll();
if (!versionOut.contains("plasmashell ")) {
qWarning() << "Unable to read plasma shell version";
return false;
}
const QString basePath = QDir(QDir::homePath() + "/.local/share/plasma/wallpapers/ScreenPlay/").canonicalPath();
const QFileInfo wallpaperMetadata(basePath + "/metadata.desktop");
if (wallpaperMetadata.exists()) {
const QString appPath = QGuiApplication::instance()->applicationDirPath() + "/kde";
const QString kdeWallpaperPath = QDir(QDir::homePath() + "/.local/share/plasma/wallpapers/ScreenPlay/").canonicalPath();
const QFileInfo installedWallpaperMetadata(kdeWallpaperPath + "/metadata.desktop");
const QString appKdeWallapperPath = QGuiApplication::instance()->applicationDirPath() + "/kde";
const QFileInfo currentWallpaperMetadata(appKdeWallapperPath + "/ScreenPlay/metadata.desktop");
process.setWorkingDirectory(appPath);
if (!installedWallpaperMetadata.exists()) {
process.setWorkingDirectory(appKdeWallapperPath);
process.start("plasmapkg2", { "--install", "ScreenPlay" });
process.waitForFinished();
process.terminate();
qInfo() << "Install ScreenPlay KDE Wallpaper";
} else {
QSettings installedWallpaperSettings(installedWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat);
installedWallpaperSettings.beginGroup("Desktop Entry");
const QString installedWallpaperVersion = installedWallpaperSettings.value("Version").toString();
installedWallpaperSettings.endGroup();
const QVersionNumber installedVersionNumber = QVersionNumber::fromString(installedWallpaperVersion);
QSettings currentWallpaperSettings(currentWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat);
currentWallpaperSettings.beginGroup("Desktop Entry");
const QString currentWallpaperVersion = currentWallpaperSettings.value("Version").toString();
currentWallpaperSettings.endGroup();
const QVersionNumber currentVersionNumber = QVersionNumber::fromString(installedWallpaperVersion);
if (installedVersionNumber.isNull() || currentVersionNumber.isNull()) {
qCritical() << "Unable to parse version number from:" << currentWallpaperVersion << installedWallpaperVersion;
return false;
}
if (installedVersionNumber < currentVersionNumber)
return true;
qInfo() << "Upgrade ScreenPlay KDE Wallpaper";
process.setWorkingDirectory(appKdeWallapperPath);
process.start("plasmapkg2", { "--upgrade", "ScreenPlay" });
process.waitForFinished();
process.terminate();
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
process.start("kquitapp5", { "plasmashell" });
process.waitForFinished();
process.terminate();
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
process.startDetached("kstart5", { "plasmashell" });
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
}
qInfo() << "Restart KDE ";
process.start("kquitapp5", { "plasmashell" });
process.waitForFinished();
process.terminate();
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
process.startDetached("kstart5", { "plasmashell" });
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
return true;
}
}

View File

@ -68,6 +68,11 @@ target_link_libraries(
Qt6::WebEngineCore
Qt6::WebEngineQuick)
if (UNIX AND NOT APPLE)
include(CopyRecursive)
copy_recursive(${CMAKE_CURRENT_SOURCE_DIR}/kde/ScreenPlay ${CMAKE_BINARY_DIR}/bin/kde/ScreenPlay "*")
endif()
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa")

View File

@ -3,6 +3,7 @@ Encoding=UTF-8
Name=ScreenPlay
Keywords=ScreenPlay
Icon=preferences-desktop-wallpaper
Version=0.15.0
Type=Service