Merge pull request #355 from dada513/flatpak_properly
Fix flatpak properly
This commit is contained in:
commit
382548e0a7
4
.gitignore
vendored
4
.gitignore
vendored
@ -42,3 +42,7 @@ run/
|
|||||||
|
|
||||||
# Nix/NixOS
|
# Nix/NixOS
|
||||||
result/
|
result/
|
||||||
|
|
||||||
|
# Flatpak
|
||||||
|
.flatpak-builder
|
||||||
|
flatbuild
|
||||||
|
@ -1140,6 +1140,15 @@ std::vector<ITheme *> Application::getValidApplicationThemes()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::isFlatpak()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
return QFile::exists("/.flatpak-info");
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Application::setApplicationTheme(const QString& name, bool initial)
|
void Application::setApplicationTheme(const QString& name, bool initial)
|
||||||
{
|
{
|
||||||
auto systemPalette = qApp->palette();
|
auto systemPalette = qApp->palette();
|
||||||
|
@ -104,6 +104,8 @@ public:
|
|||||||
|
|
||||||
QIcon getThemedIcon(const QString& name);
|
QIcon getThemedIcon(const QString& name);
|
||||||
|
|
||||||
|
bool isFlatpak();
|
||||||
|
|
||||||
void setIconTheme(const QString& name);
|
void setIconTheme(const QString& name);
|
||||||
|
|
||||||
std::vector<ITheme *> getValidApplicationThemes();
|
std::vector<ITheme *> getValidApplicationThemes();
|
||||||
|
@ -1,8 +1,43 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* PolyMC - Minecraft Launcher
|
||||||
|
* Copyright (C) 2022 dada513 <dada513@protonmail.com>
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* 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 "DesktopServices.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing.
|
* This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing.
|
||||||
@ -84,7 +119,14 @@ bool openDirectory(const QString &path, bool ensureExists)
|
|||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()));
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
return IndirectOpen(f);
|
if(!APPLICATION->isFlatpak())
|
||||||
|
{
|
||||||
|
return IndirectOpen(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return f();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
@ -98,7 +140,14 @@ bool openFile(const QString &path)
|
|||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
return QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
return IndirectOpen(f);
|
if(!APPLICATION->isFlatpak())
|
||||||
|
{
|
||||||
|
return IndirectOpen(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return f();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
@ -109,10 +158,17 @@ bool openFile(const QString &application, const QString &path, const QString &wo
|
|||||||
qDebug() << "Opening file" << path << "using" << application;
|
qDebug() << "Opening file" << path << "using" << application;
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#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
|
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
||||||
return IndirectOpen([&]()
|
if(!APPLICATION->isFlatpak())
|
||||||
{
|
{
|
||||||
return QProcess::startDetached(application, QStringList() << path, workingDirectory);
|
return IndirectOpen([&]()
|
||||||
}, pid);
|
{
|
||||||
|
return QProcess::startDetached(application, QStringList() << path, workingDirectory);
|
||||||
|
}, pid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
|
return QProcess::startDetached(application, QStringList() << path, workingDirectory, pid);
|
||||||
#endif
|
#endif
|
||||||
@ -122,11 +178,18 @@ bool run(const QString &application, const QStringList &args, const QString &wor
|
|||||||
{
|
{
|
||||||
qDebug() << "Running" << application << "with args" << args.join(' ');
|
qDebug() << "Running" << application << "with args" << args.join(' ');
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
|
if(!APPLICATION->isFlatpak())
|
||||||
|
{
|
||||||
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
// FIXME: the pid here is fake. So if something depends on it, it will likely misbehave
|
||||||
return IndirectOpen([&]()
|
return IndirectOpen([&]()
|
||||||
{
|
{
|
||||||
return QProcess::startDetached(application, args, workingDirectory);
|
return QProcess::startDetached(application, args, workingDirectory);
|
||||||
}, pid);
|
}, pid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QProcess::startDetached(application, args, workingDirectory, pid);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return QProcess::startDetached(application, args, workingDirectory, pid);
|
return QProcess::startDetached(application, args, workingDirectory, pid);
|
||||||
#endif
|
#endif
|
||||||
@ -140,7 +203,14 @@ bool openUrl(const QUrl &url)
|
|||||||
return QDesktopServices::openUrl(url);
|
return QDesktopServices::openUrl(url);
|
||||||
};
|
};
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
return IndirectOpen(f);
|
if(!APPLICATION->isFlatpak())
|
||||||
|
{
|
||||||
|
return IndirectOpen(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return f();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return f();
|
return f();
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* PolyMC - Minecraft Launcher
|
||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
* Copyright (c) 2022 dada513 <dada513@protonmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -134,13 +135,31 @@ void LauncherPage::on_instDirBrowseBtn_clicked()
|
|||||||
warning.setInformativeText(
|
warning.setInformativeText(
|
||||||
tr("Do you really want to use this path? "
|
tr("Do you really want to use this path? "
|
||||||
"Selecting \"No\" will close this and not alter your instance 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();
|
int result = warning.exec();
|
||||||
if (result == QMessageBox::Yes)
|
if (result == QMessageBox::Ok)
|
||||||
{
|
{
|
||||||
ui->instDirTextBox->setText(cooked_dir);
|
ui->instDirTextBox->setText(cooked_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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, "
|
||||||
|
"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 want to proceed anyway?"));
|
||||||
|
warning.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
|
int result = warning.exec();
|
||||||
|
if (result == QMessageBox::Ok)
|
||||||
|
{
|
||||||
|
ui->instDirTextBox->setText(cooked_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->instDirTextBox->setText(cooked_dir);
|
ui->instDirTextBox->setText(cooked_dir);
|
||||||
|
Loading…
Reference in New Issue
Block a user