Skip to content

Commit 02a29e7

Browse files
committed
feat: implement AppImage auto-updater for Linux
Signed-off-by: der_spotter <jayjag@posteo.de>
1 parent 2a64578 commit 02a29e7

10 files changed

Lines changed: 512 additions & 62 deletions

File tree

src/common/utility.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ namespace Utility {
170170
constexpr bool isBSD(); // use with care, does not match OS X
171171

172172
OCSYNC_EXPORT QString platformName();
173+
174+
// AppImage helpers (Linux only, return empty/false elsewhere)
175+
OCSYNC_EXPORT QString appImagePath();
176+
OCSYNC_EXPORT bool isRunningInAppImage();
173177
// crash helper for --debug
174178
OCSYNC_EXPORT void crash();
175179

src/common/utility_mac.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

1919
namespace OCC {
2020

21+
QString Utility::appImagePath()
22+
{
23+
return {};
24+
}
25+
26+
bool Utility::isRunningInAppImage()
27+
{
28+
return false;
29+
}
30+
2131
QVector<Utility::ProcessInfosForOpenFile> Utility::queryProcessInfosKeepingFileOpen(const QString &filePath)
2232
{
2333
Q_UNUSED(filePath)

src/common/utility_unix.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919
namespace OCC {
2020

21+
QString Utility::appImagePath()
22+
{
23+
return qEnvironmentVariable("APPIMAGE");
24+
}
25+
26+
bool Utility::isRunningInAppImage()
27+
{
28+
const auto currentAppImagePath = appImagePath();
29+
return !currentAppImagePath.isEmpty() && QFile::exists(currentAppImagePath);
30+
}
31+
2132
QVector<Utility::ProcessInfosForOpenFile> Utility::queryProcessInfosKeepingFileOpen(const QString &filePath)
2233
{
2334
Q_UNUSED(filePath)
@@ -99,9 +110,9 @@ void Utility::setLaunchOnStartup(const QString &appName, const QString &guiName,
99110
}
100111
// When running inside an AppImage, we need to set the path to the
101112
// AppImage instead of the path to the executable
102-
const QString appImagePath = qEnvironmentVariable("APPIMAGE");
103-
const bool runningInsideAppImage = !appImagePath.isNull() && QFile::exists(appImagePath);
104-
const QString executablePath = runningInsideAppImage ? appImagePath : QCoreApplication::applicationFilePath();
113+
const auto currentAppImagePath = appImagePath();
114+
const auto runningInsideAppImage = isRunningInAppImage();
115+
const auto executablePath = runningInsideAppImage ? currentAppImagePath : QCoreApplication::applicationFilePath();
105116

106117
QTextStream ts(&iniFile);
107118
ts << QLatin1String("[Desktop Entry]\n")
@@ -134,10 +145,7 @@ QString Utility::getCurrentUserName()
134145

135146
void Utility::registerUriHandlerForLocalEditing()
136147
{
137-
const auto appImagePath = qEnvironmentVariable("APPIMAGE");
138-
const auto runningInsideAppImage = !appImagePath.isNull() && QFile::exists(appImagePath);
139-
140-
if (!runningInsideAppImage) {
148+
if (!isRunningInAppImage()) {
141149
// only register x-scheme-handler if running inside appImage
142150
return;
143151
}

src/common/utility_win.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ static const char runPathC[] = R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\C
3434

3535
namespace OCC {
3636

37+
QString Utility::appImagePath()
38+
{
39+
return {};
40+
}
41+
42+
bool Utility::isRunningInAppImage()
43+
{
44+
return false;
45+
}
46+
3747
QVector<Utility::ProcessInfosForOpenFile> Utility::queryProcessInfosKeepingFileOpen(const QString &filePath)
3848
{
3949
QVector<ProcessInfosForOpenFile> results;

src/gui/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ IF(BUILD_UPDATER)
285285
updater/updater.h
286286
updater/updater.cpp
287287
)
288+
# Linux AppImage updater
289+
if(UNIX AND NOT APPLE)
290+
list(APPEND updater_SRCS
291+
updater/appimageupdater.h
292+
updater/appimageupdater.cpp
293+
)
294+
endif()
288295
endif()
289296

290297
IF( APPLE )

0 commit comments

Comments
 (0)