From 54a2b983b23b19e79d8e775db56fd2c42cb04c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Sat, 17 Aug 2024 03:52:08 +0200 Subject: [PATCH] Linux Portable: support desktop integration removal Run 'friction --xdg-remove' to uninstall desktop integration. Also update build scripts. --- src/app/main.cpp | 20 ++++++-- src/core/appsupport.cpp | 23 +++++++++ src/core/appsupport.h | 1 + src/scripts/build_vfxplatform_package.sh | 19 ++----- src/scripts/desktop_integration.sh | 63 ------------------------ 5 files changed, 45 insertions(+), 81 deletions(-) delete mode 100755 src/scripts/desktop_integration.sh diff --git a/src/app/main.cpp b/src/app/main.cpp index 1e7279716..c58e6c8f2 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -128,11 +128,18 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); setlocale(LC_NUMERIC, "C"); +#ifdef Q_OS_LINUX + if (AppSupport::isAppPortable()) { + if (QApplication::arguments().contains("--xdg-remove")) { + const bool removedXDG = AppSupport::removeXDGDesktopIntegration(); + qWarning() << "Removed XDG Integration:" << removedXDG; + return removedXDG ? 0 : -1; + } + } +#endif + #ifdef Q_OS_WIN -// we ship a custom build of Qt 5.12.12 (with this feature backported) on Windows, so ignore this check -// #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) QWindowsWindowFunctions::setHasBorderInFullScreenDefault(true); -// #endif #endif #ifndef Q_OS_DARWIN @@ -206,7 +213,12 @@ int main(int argc, char *argv[]) " This will add Friction to your application launcher" " and add mime type for project files.")); if (ask == QMessageBox::Yes) { - AppSupport::setupXDGDesktopIntegration(); + if (!AppSupport::setupXDGDesktopIntegration()) { + QMessageBox::warning(nullptr, + QObject::tr("Desktop Integration Failed"), + QObject::tr("Failed to install the required files for desktop integration," + " please check your permissions.")); + } } } } diff --git a/src/core/appsupport.cpp b/src/core/appsupport.cpp index 051850e0e..2d6483394 100644 --- a/src/core/appsupport.cpp +++ b/src/core/appsupport.cpp @@ -862,3 +862,26 @@ bool AppSupport::setupXDGDesktopIntegration() return true; } + +bool AppSupport::removeXDGDesktopIntegration() +{ + QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + if (path.isEmpty() || + !path.startsWith(QDir::homePath())) { path = QString("%1/.local/share").arg(QDir::homePath()); } + + QStringList files; + files << "applications/graphics.friction.Friction.desktop"; + files << "mime/packages/graphics.friction.Friction.xml"; + files << "icons/hicolor/scalable/apps/graphics.friction.Friction.svg"; + files << "icons/hicolor/256x256/apps/graphics.friction.Friction.png"; + files << "icons/hicolor/scalable/mimetypes/application-x-graphics.friction.Friction.svg"; + files << "icons/hicolor/256x256/mimetypes/application-x-graphics.friction.Friction.png"; + + for (const auto &file : files) { + QFile fileName(QString("%1/%2").arg(path, file)); + if (fileName.exists()) { + if (!fileName.remove()) { return false; } + } + } + return true; +} diff --git a/src/core/appsupport.h b/src/core/appsupport.h index 607cdccf6..6c6800149 100644 --- a/src/core/appsupport.h +++ b/src/core/appsupport.h @@ -121,6 +121,7 @@ class CORE_EXPORT AppSupport : public QObject static bool isAppPortable(); static bool hasXDGDesktopIntegration(); static bool setupXDGDesktopIntegration(); + static bool removeXDGDesktopIntegration(); }; #endif // APPSUPPORT_H diff --git a/src/scripts/build_vfxplatform_package.sh b/src/scripts/build_vfxplatform_package.sh index 764066f39..3584d28bf 100755 --- a/src/scripts/build_vfxplatform_package.sh +++ b/src/scripts/build_vfxplatform_package.sh @@ -171,14 +171,13 @@ rpmbuild -bb rpm.spec cp -a ${HOME}/rpmbuild/RPMS/*/*.rpm ${DISTFILES}/builds/${VERSION}/ # Portable -FRICTION_PORTABLE=${FRICTION_PKG}-portable-linux-x86_64 +FRICTION_PORTABLE=${FRICTION_PKG}-linux-x86_64 FRICTION_PORTABLE_DIR=${BUILD}/${FRICTION_PORTABLE} cd ${BUILD} rm -f ${FRICTION_PORTABLE_DIR} || true mv ${BUILD}/${FRICTION_PKG} ${FRICTION_PORTABLE_DIR} (cd ${FRICTION_PORTABLE_DIR} ; -cp ${BUILD}/friction/src/scripts/desktop_integration.sh . -chmod +x desktop_integration.sh +touch bin/portable.txt rm -rf usr mv opt/friction/* . rm -rf opt share/doc @@ -186,12 +185,12 @@ ln -sf bin/friction . ) cd ${BUILD} tar cvf ${FRICTION_PORTABLE}.tar ${FRICTION_PORTABLE} -bzip2 -9 ${FRICTION_PORTABLE}.tar -cp -a ${FRICTION_PORTABLE}.tar.bz2 ${DISTFILES}/builds/${VERSION}/ +xz -9 ${FRICTION_PORTABLE}.tar +cp -a ${FRICTION_PORTABLE}.tar.xz ${DISTFILES}/builds/${VERSION}/ # AppImage (cd ${FRICTION_PORTABLE_DIR} ; -rm -f desktop_integration.sh +rm -f bin/portable.txt rm -f friction mkdir usr mv lib bin plugins share usr/ @@ -203,14 +202,6 @@ ln -sf usr/share/icons/hicolor/256x256/apps/${APPID}.png .DirIcon tar xf ${DISTFILES}/linux/appimagetool-${APPIMAGETOOL}.tar.bz2 ARCH=x86_64 ./appimagetool/AppRun --verbose --runtime-file=${DISTFILES}/linux/runtime-x86_64-${APPIMAGERUNTIME}.bin ${FRICTION_PORTABLE} -# TODO -# FRICTION_ISO=${FRICTION_PKG}-x86_64.squashfs -# FRICTION_APP=${FRICTION_PKG}-test-x86_64.AppImage -# mksquashfs ${FRICTION_PORTABLE} ${FRICTION_ISO} -comp zstd -root-owned -noappend -b 1M -mkfs-time 0 -# cat ${DISTFILES}/linux/runtime-x86_64-${APPIMAGERUNTIME}.bin > ${FRICTION_APP} -# cat ${FRICTION_ISO} >> ${FRICTION_APP} -# chmod a+x ${FRICTION_ISO} - cp -a *.AppImage ${DISTFILES}/builds/${VERSION}/ echo "FRICTION PACKAGE DONE" diff --git a/src/scripts/desktop_integration.sh b/src/scripts/desktop_integration.sh deleted file mode 100755 index a2f4e06eb..000000000 --- a/src/scripts/desktop_integration.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh -# -# Friction - https://friction.graphics -# -# Copyright (c) Friction contributors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -# Desktop integration for Linux portable - -set -e -x - -CWD=`pwd` -SRC=${SRC:-${CWD}} -DEST=${DEST:-"${HOME}/.local/share"} - -DESKTOP_FILE=${SRC}/share/applications/graphics.friction.Friction.desktop -MIME_FILE=${SRC}/share/mime/packages/graphics.friction.Friction.xml -DESKTOP_ICON_SVG=${SRC}/share/icons/hicolor/scalable/apps/graphics.friction.Friction.svg -DESKTOP_ICON_PNG=${SRC}/share/icons/hicolor/256x256/apps/graphics.friction.Friction.png -MIME_ICON_SVG=${SRC}/share/icons/hicolor/scalable/mimetypes/application-x-graphics.friction.Friction.svg -MIME_ICON_PNG=${SRC}/share/icons/hicolor/256x256/mimetypes/application-x-graphics.friction.Friction.png - -if [ ! -d "${DEST}" ]; then - mkdir -p ${DEST} -fi -if [ ! -d "${DEST}/applications" ]; then - mkdir -p ${DEST}/applications -fi -if [ ! -d "${DEST}/mime/packages" ]; then - mkdir -p ${DEST}/mime/packages -fi -if [ ! -d "${DEST}/icons/hicolor/scalable/apps" ]; then - mkdir -p ${DEST}/icons/hicolor/scalable/apps -fi -if [ ! -d "${DEST}/icons/hicolor/scalable/mimetypes" ]; then - mkdir -p ${DEST}/icons/hicolor/scalable/mimetypes -fi -if [ ! -d "${DEST}/icons/hicolor/256x256/apps" ]; then - mkdir -p ${DEST}/icons/hicolor/256x256/apps -fi -if [ ! -d "${DEST}/icons/hicolor/256x256/mimetypes" ]; then - mkdir -p ${DEST}/icons/hicolor/256x256/mimetypes -fi - -cat ${DESKTOP_FILE} | sed 's#Exec=friction#Exec='${SRC}'/bin/friction#' > ${DEST}/applications/graphics.friction.Friction.desktop -cp -a ${MIME_FILE} ${DEST}/mime/packages/graphics.friction.Friction.xml -cp -a ${DESKTOP_ICON_SVG} ${DEST}/icons/hicolor/scalable/apps/graphics.friction.Friction.svg -cp -a ${DESKTOP_ICON_PNG} ${DEST}/icons/hicolor/256x256/apps/graphics.friction.Friction.png -cp -a ${MIME_ICON_SVG} ${DEST}/icons/hicolor/scalable/mimetypes/application-x-graphics.friction.Friction.svg -cp -a ${MIME_ICON_PNG} ${DEST}/icons/hicolor/256x256/mimetypes/application-x-graphics.friction.Friction.png