mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 10:45:39 +03:00
implement installer for flatpak
This commit is contained in:
parent
9a8edbfc86
commit
ea2c3732b0
@ -44,6 +44,7 @@ endif()
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
option(FLATPAK "Building for flatpak" OFF)
|
||||
option(DEBUG_FLATPAK "Building but using flatpak urls for testing" OFF)
|
||||
|
||||
# Require C++17.
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
@ -79,6 +80,10 @@ if(FLATPAK)
|
||||
add_compile_definitions(FLATPAK)
|
||||
endif()
|
||||
|
||||
if(DEBUG_FLATPAK)
|
||||
add_compile_definitions(DEBUG_FLATPAK)
|
||||
endif()
|
||||
|
||||
set(QT_TRANSLATIONS_DIR "${Qt5_DIR}/../../../translations")
|
||||
set(QT_TRANSLATIONS_DIR "/usr/share/qt/translations")
|
||||
|
||||
|
@ -32,8 +32,16 @@ if(APPLE)
|
||||
elseif(UNIX)
|
||||
set_target_properties(relauncher PROPERTIES INSTALL_RPATH "$ORIGIN")
|
||||
|
||||
install(
|
||||
TARGETS relauncher
|
||||
DESTINATION .
|
||||
COMPONENT ${GITTYUP_NAME})
|
||||
if(FLATPAK)
|
||||
# Install application.
|
||||
install(
|
||||
TARGETS relauncher
|
||||
DESTINATION ./bin # otherwise the executable will not be found by flatpak
|
||||
COMPONENT ${GITTYUP_NAME})
|
||||
else()
|
||||
install(
|
||||
TARGETS relauncher
|
||||
DESTINATION .
|
||||
COMPONENT ${GITTYUP_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
@ -57,7 +57,7 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
|
||||
"Would you like to download it now?</p>"
|
||||
"<b>Release Notes:</b>")
|
||||
.arg(appName, version, appVersion);
|
||||
#elif defined(FLATPAK)
|
||||
#elif defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
QString label =
|
||||
tr("<h3>A new version of %1 is available!</h3>"
|
||||
"<p>%1 %2 is now available - you have %3.</p>"
|
||||
@ -82,7 +82,7 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
|
||||
browser->document()->setDefaultStyleSheet(kStyleSheet);
|
||||
browser->setHtml(changelog);
|
||||
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK)
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
QCheckBox *download =
|
||||
new QCheckBox(tr("Automatically download and install updates"), this);
|
||||
download->setChecked(Settings::instance()->value("update/download").toBool());
|
||||
@ -92,7 +92,7 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
|
||||
#endif
|
||||
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox(this);
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK)
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
buttons->addButton(tr("Install Update"), QDialogButtonBox::AcceptRole);
|
||||
buttons->addButton(tr("Remind Me Later"), QDialogButtonBox::RejectRole);
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &UpdateDialog::accept);
|
||||
@ -120,7 +120,7 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
|
||||
new QPushButton(QIcon(":/liberapay_icon_130890.png"), tr("Donate"), this);
|
||||
QSpacerItem *spacer =
|
||||
new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK)
|
||||
#if !defined(Q_OS_LINUX) || defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
l->addWidget(download);
|
||||
#endif
|
||||
l->addItem(spacer);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "UpToDateDialog.h"
|
||||
#include "conf/Settings.h"
|
||||
#include "ui/MainWindow.h"
|
||||
#include "git/Command.h"
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QDialog>
|
||||
@ -158,7 +159,7 @@ void Updater::update(bool spontaneous) {
|
||||
QString platform(PLATFORM);
|
||||
QString platformArg;
|
||||
QString extension = "sh";
|
||||
#ifdef FLATPAK
|
||||
#if defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
extension = "flatpak";
|
||||
platformArg = "";
|
||||
// The bundle does not have any version in its filename
|
||||
@ -268,7 +269,45 @@ Updater *Updater::instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
|
||||
#if defined(FLATPAK) || defined(DEBUG_FLATPAK)
|
||||
bool Updater::install(const DownloadRef &download, QString &error) {
|
||||
QString path = download->file()->fileName();
|
||||
|
||||
QDir dir(QCoreApplication::applicationDirPath());
|
||||
QStringList args;
|
||||
args.append("-c");
|
||||
args.append(
|
||||
QString("flatpak-spawn --host flatpak install --user -y %1").arg(path));
|
||||
qDebug() << "Install arguments: " << args;
|
||||
qDebug() << "Download file: " << path;
|
||||
QProcess *p = new QProcess(this);
|
||||
|
||||
QString bash = git::Command::bashPath();
|
||||
qDebug() << "Bash: " << bash;
|
||||
p->start(bash, args);
|
||||
if (!p->waitForFinished()) {
|
||||
const QString es = p->errorString();
|
||||
error = tr("Installer script failed: %1").arg(es);
|
||||
qDebug() << "Installer script failed: " + es;
|
||||
return false;
|
||||
} else {
|
||||
qDebug() << "Successfully installed bundle: " + p->readAll();
|
||||
}
|
||||
|
||||
auto relauncher_cmd = dir.filePath("relauncher");
|
||||
qDebug() << "Relauncher command: " << relauncher_cmd;
|
||||
|
||||
// Start the relaunch helper.
|
||||
QString app = "flatpak-spawn --host flatpak run com.github.Murmele.Gittyup";
|
||||
QString pid = QString::number(QCoreApplication::applicationPid());
|
||||
if (!QProcess::startDetached(relauncher_cmd, {app, pid})) {
|
||||
error = tr("Helper application failed to start");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#elif !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
|
||||
bool Updater::install(const DownloadRef &download, QString &error) {
|
||||
QString path = download->file()->fileName();
|
||||
QDir dir(QCoreApplication::applicationDirPath());
|
||||
|
Loading…
Reference in New Issue
Block a user