From 3672dbc5af1403c8ea1a1f36d2890fed7dd4c6a1 Mon Sep 17 00:00:00 2001 From: dada513 Date: Sun, 27 Mar 2022 12:43:49 +0200 Subject: [PATCH 1/7] Fix flatpak properly --- launcher/CMakeLists.txt | 2 ++ launcher/DesktopServices.cpp | 48 +++++++++++++++++++++++++++++++----- launcher/Flatpak.cpp | 14 +++++++++++ launcher/Flatpak.h | 4 +++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 launcher/Flatpak.cpp create mode 100644 launcher/Flatpak.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 98cb0a3b..1a16485e 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -582,6 +582,8 @@ SET(LAUNCHER_SOURCES ApplicationMessage.cpp # GUI - general utilities + Flatpak.h + Flatpak.cpp DesktopServices.h DesktopServices.cpp VersionProxyModel.h diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp index dcc1b0ce..5de97210 100644 --- a/launcher/DesktopServices.cpp +++ b/launcher/DesktopServices.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "Flatpak.h" /** * This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing. @@ -84,7 +85,14 @@ bool openDirectory(const QString &path, bool ensureExists) return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - return IndirectOpen(f); + if(!Flatpak::IsFlatpak()) + { + return IndirectOpen(f); + } + else + { + return f(); + } #else return f(); #endif @@ -98,7 +106,14 @@ bool openFile(const QString &path) return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - return IndirectOpen(f); + if(!Flatpak::IsFlatpak()) + { + return IndirectOpen(f); + } + else + { + return f(); + } #else return f(); #endif @@ -109,10 +124,17 @@ bool openFile(const QString &application, const QString &path, const QString &wo qDebug() << "Opening file" << path << "using" << application; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave - return IndirectOpen([&]() + if(!Flatpak::IsFlatpak()) { - return QProcess::startDetached(application, QStringList() << path, workingDirectory); - }, pid); + return IndirectOpen([&]() + { + return QProcess::startDetached(application, QStringList() << path, workingDirectory); + }, pid); + } + else + { + return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid); + } #else return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid); #endif @@ -122,11 +144,18 @@ bool run(const QString &application, const QStringList &args, const QString &wor { qDebug() << "Running" << application << "with args" << args.join(' '); #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) + if(!Flatpak::IsFlatpak()) + { // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave return IndirectOpen([&]() { return QProcess::startDetached(application, args, workingDirectory); }, pid); + } + else + { + return QProcess::startDetached(application, args, workingDirectory, pid); + } #else return QProcess::startDetached(application, args, workingDirectory, pid); #endif @@ -140,7 +169,14 @@ bool openUrl(const QUrl &url) return QDesktopServices::openUrl(url); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - return IndirectOpen(f); + if(!Flatpak::IsFlatpak()) + { + return IndirectOpen(f); + } + else + { + return f(); + } #else return f(); #endif diff --git a/launcher/Flatpak.cpp b/launcher/Flatpak.cpp new file mode 100644 index 00000000..8b61f903 --- /dev/null +++ b/launcher/Flatpak.cpp @@ -0,0 +1,14 @@ +#include + +namespace Flatpak +{ + bool IsFlatpak() + { + #ifdef Q_OS_LINUX + QFileInfo check_file("/.flatpak-info"); + return check_file.exists(); + #else + return false; + #endif + } +} diff --git a/launcher/Flatpak.h b/launcher/Flatpak.h new file mode 100644 index 00000000..da6eb7c3 --- /dev/null +++ b/launcher/Flatpak.h @@ -0,0 +1,4 @@ +namespace Flatpak +{ + bool IsFlatpak(); +} \ No newline at end of file From 6a180f495f28db0ae254a17112618291369e86a2 Mon Sep 17 00:00:00 2001 From: dada513 Date: Sun, 27 Mar 2022 14:42:02 +0200 Subject: [PATCH 2/7] more flatpak fixes --- .gitignore | 4 ++++ launcher/DesktopServices.cpp | 34 ++++++++++++++++++++++++++++++++++ launcher/Flatpak.cpp | 19 ++++++++++++++++++- launcher/Flatpak.h | 17 +++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ba90e8f8..dc4cd1c5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,7 @@ run/ # Nix/NixOS result/ + +# Flatpak +.flatpak-builder +flatbuild \ No newline at end of file diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp index 5de97210..f4226c15 100644 --- a/launcher/DesktopServices.cpp +++ b/launcher/DesktopServices.cpp @@ -1,3 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 dada513 + * + * 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, version 3. + * + * 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 . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2022 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "DesktopServices.h" #include #include diff --git a/launcher/Flatpak.cpp b/launcher/Flatpak.cpp index 8b61f903..2c28903c 100644 --- a/launcher/Flatpak.cpp +++ b/launcher/Flatpak.cpp @@ -1,3 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 dada513 + * + * 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, version 3. + * + * 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 . + */ #include namespace Flatpak @@ -10,5 +27,5 @@ namespace Flatpak #else return false; #endif - } + } } diff --git a/launcher/Flatpak.h b/launcher/Flatpak.h index da6eb7c3..50c6d734 100644 --- a/launcher/Flatpak.h +++ b/launcher/Flatpak.h @@ -1,3 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 dada513 + * + * 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, version 3. + * + * 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 . + */ namespace Flatpak { bool IsFlatpak(); From 0a5dfeb3d7767a024f3b9032ea84df82570c7052 Mon Sep 17 00:00:00 2001 From: dada513 Date: Sun, 27 Mar 2022 14:44:40 +0200 Subject: [PATCH 3/7] fix newline (scrumplex nitpick not allowed) --- launcher/Flatpak.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/Flatpak.h b/launcher/Flatpak.h index 50c6d734..8fd315fb 100644 --- a/launcher/Flatpak.h +++ b/launcher/Flatpak.h @@ -18,4 +18,4 @@ namespace Flatpak { bool IsFlatpak(); -} \ No newline at end of file +} From 424f4a72ffd4d5e6748559d2ce76ec2fd3b4cde1 Mon Sep 17 00:00:00 2001 From: dada513 Date: Sun, 27 Mar 2022 16:08:11 +0200 Subject: [PATCH 4/7] Inform user about possible issues when using a Portal as instance folder --- launcher/ui/pages/global/LauncherPage.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/launcher/ui/pages/global/LauncherPage.cpp b/launcher/ui/pages/global/LauncherPage.cpp index 6f7e1cc7..c3dde8e6 100644 --- a/launcher/ui/pages/global/LauncherPage.cpp +++ b/launcher/ui/pages/global/LauncherPage.cpp @@ -2,6 +2,7 @@ /* * PolyMC - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield + * Copyright (c) 2022 dada513 * * 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 @@ -48,6 +49,7 @@ #include "Application.h" #include "BuildConfig.h" #include "ui/themes/ITheme.h" +#include "Flatpak.h" #include #include @@ -141,6 +143,25 @@ void LauncherPage::on_instDirBrowseBtn_clicked() ui->instDirTextBox->setText(cooked_dir); } } + else if(Flatpak::IsFlatpak() && raw_dir.startsWith("/run/user")) + { + QMessageBox warning; + warning.setText(tr("You're trying to specify an instance folder " + "which was granted temporaily via Flatpak.\n" + "This is known to cause problems, " + "after a restart the launcher might break, " + "because it will no longer have access to that directory.\n\n" + "Granting PolyMC access to it via Flatseal is recommended.")); + warning.setInformativeText( + tr("Do you really want to use this path?\n" + "Selecting \"No\" will close this and not alter your instance path.")); + warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + int result = warning.exec(); + if (result == QMessageBox::Yes) + { + ui->instDirTextBox->setText(cooked_dir); + } + } else { ui->instDirTextBox->setText(cooked_dir); From 3a7eeff135f92c807fdc066cb06d835f295b66d3 Mon Sep 17 00:00:00 2001 From: dada513 Date: Mon, 28 Mar 2022 20:55:03 +0200 Subject: [PATCH 5/7] Fix --- launcher/Application.cpp | 10 ++++++++ launcher/Application.h | 2 ++ launcher/CMakeLists.txt | 2 -- launcher/DesktopServices.cpp | 12 ++++----- launcher/Flatpak.cpp | 31 ----------------------- launcher/Flatpak.h | 21 --------------- launcher/ui/pages/global/LauncherPage.cpp | 18 ++++++------- 7 files changed, 26 insertions(+), 70 deletions(-) delete mode 100644 launcher/Flatpak.cpp delete mode 100644 launcher/Flatpak.h diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 33b1774c..abdfc06d 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1139,6 +1139,16 @@ std::vector Application::getValidApplicationThemes() return ret; } +bool Application::isFlatpak() +{ + #ifdef Q_OS_LINUX + QFileInfo check_file("/.flatpak-info"); + return check_file.exists(); + #else + return false; + #endif +} + void Application::setApplicationTheme(const QString& name, bool initial) { auto systemPalette = qApp->palette(); diff --git a/launcher/Application.h b/launcher/Application.h index c3e29ef5..54d9ba5f 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -104,6 +104,8 @@ public: QIcon getThemedIcon(const QString& name); + bool isFlatpak(); + void setIconTheme(const QString& name); std::vector getValidApplicationThemes(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 1a16485e..98cb0a3b 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -582,8 +582,6 @@ SET(LAUNCHER_SOURCES ApplicationMessage.cpp # GUI - general utilities - Flatpak.h - Flatpak.cpp DesktopServices.h DesktopServices.cpp VersionProxyModel.h diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp index f4226c15..c29cbe7d 100644 --- a/launcher/DesktopServices.cpp +++ b/launcher/DesktopServices.cpp @@ -37,7 +37,7 @@ #include #include #include -#include "Flatpak.h" +#include "Application.h" /** * This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing. @@ -119,7 +119,7 @@ bool openDirectory(const QString &path, bool ensureExists) return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - if(!Flatpak::IsFlatpak()) + if(!APPLICATION->isFlatpak()) { return IndirectOpen(f); } @@ -140,7 +140,7 @@ bool openFile(const QString &path) return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - if(!Flatpak::IsFlatpak()) + if(!APPLICATION->isFlatpak()) { return IndirectOpen(f); } @@ -158,7 +158,7 @@ bool openFile(const QString &application, const QString &path, const QString &wo qDebug() << "Opening file" << path << "using" << application; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave - if(!Flatpak::IsFlatpak()) + if(!APPLICATION->isFlatpak()) { return IndirectOpen([&]() { @@ -178,7 +178,7 @@ bool run(const QString &application, const QStringList &args, const QString &wor { qDebug() << "Running" << application << "with args" << args.join(' '); #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - if(!Flatpak::IsFlatpak()) + if(!APPLICATION->isFlatpak()) { // FIXME: the pid here is fake. So if something depends on it, it will likely misbehave return IndirectOpen([&]() @@ -203,7 +203,7 @@ bool openUrl(const QUrl &url) return QDesktopServices::openUrl(url); }; #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - if(!Flatpak::IsFlatpak()) + if(!APPLICATION->isFlatpak()) { return IndirectOpen(f); } diff --git a/launcher/Flatpak.cpp b/launcher/Flatpak.cpp deleted file mode 100644 index 2c28903c..00000000 --- a/launcher/Flatpak.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 dada513 - * - * 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, version 3. - * - * 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 . - */ -#include - -namespace Flatpak -{ - bool IsFlatpak() - { - #ifdef Q_OS_LINUX - QFileInfo check_file("/.flatpak-info"); - return check_file.exists(); - #else - return false; - #endif - } -} diff --git a/launcher/Flatpak.h b/launcher/Flatpak.h deleted file mode 100644 index 8fd315fb..00000000 --- a/launcher/Flatpak.h +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 dada513 - * - * 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, version 3. - * - * 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 . - */ -namespace Flatpak -{ - bool IsFlatpak(); -} diff --git a/launcher/ui/pages/global/LauncherPage.cpp b/launcher/ui/pages/global/LauncherPage.cpp index c3dde8e6..42ad5ae3 100644 --- a/launcher/ui/pages/global/LauncherPage.cpp +++ b/launcher/ui/pages/global/LauncherPage.cpp @@ -49,7 +49,6 @@ #include "Application.h" #include "BuildConfig.h" #include "ui/themes/ITheme.h" -#include "Flatpak.h" #include #include @@ -136,28 +135,27 @@ void LauncherPage::on_instDirBrowseBtn_clicked() warning.setInformativeText( tr("Do you really want to use this path? " "Selecting \"No\" will close this and not alter your instance path.")); - warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + warning.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); int result = warning.exec(); - if (result == QMessageBox::Yes) + if (result == QMessageBox::Ok) { ui->instDirTextBox->setText(cooked_dir); } } - else if(Flatpak::IsFlatpak() && raw_dir.startsWith("/run/user")) + else if(APPLICATION->isFlatpak() && raw_dir.startsWith("/run/user")) { QMessageBox warning; warning.setText(tr("You're trying to specify an instance folder " "which was granted temporaily via Flatpak.\n" - "This is known to cause problems, " - "after a restart the launcher might break, " + "This is known to cause problems. " + "After a restart the launcher might break, " "because it will no longer have access to that directory.\n\n" "Granting PolyMC access to it via Flatseal is recommended.")); warning.setInformativeText( - tr("Do you really want to use this path?\n" - "Selecting \"No\" will close this and not alter your instance path.")); - warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + tr("Do you want to proceed anyway?")); + warning.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); int result = warning.exec(); - if (result == QMessageBox::Yes) + if (result == QMessageBox::Ok) { ui->instDirTextBox->setText(cooked_dir); } From 954074942e6361223b0beee6eff16a73d2a936a7 Mon Sep 17 00:00:00 2001 From: dada513 Date: Mon, 28 Mar 2022 20:56:24 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=98=A2=20fix=20bully?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dc4cd1c5..c9a762f5 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ result/ # Flatpak .flatpak-builder -flatbuild \ No newline at end of file +flatbuild From 59b3e30821bd20a3dc9e9fe4617ffa461f3a89b8 Mon Sep 17 00:00:00 2001 From: dada513 Date: Thu, 31 Mar 2022 16:11:04 +0200 Subject: [PATCH 7/7] Scrumplex moment --- launcher/Application.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index af1cfe85..91b7b82c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1143,8 +1143,7 @@ std::vector Application::getValidApplicationThemes() bool Application::isFlatpak() { #ifdef Q_OS_LINUX - QFileInfo check_file("/.flatpak-info"); - return check_file.exists(); + return QFile::exists("/.flatpak-info"); #else return false; #endif