Skip to content

Commit

Permalink
#2751 updater: fix multiple AppImage application path fetching issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Mar 18, 2023
1 parent d553224 commit 2c428e6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- the size of search items that are stored in the "stored searches" history
is now limited to prevent clogging the application settings with them
(for [#2752](https://github.com/pbek/QOwnNotes/issues/2752))
- another AppImage update issue that came with the changes from
[#2728](https://github.com/pbek/QOwnNotes/issues/2728) should now be fixed
(for [#2751](https://github.com/pbek/QOwnNotes/issues/2751))

## 23.3.4
- the **amd64 Snap build process was re-invented**, because the necessary
Expand Down
7 changes: 1 addition & 6 deletions src/dialogs/updatedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,7 @@ bool UpdateDialog::initializeMacOSUpdateProcess(const QString &releaseUrl) {
* Initializes the Linux update process
*/
bool UpdateDialog::initializeLinuxUpdateProcess(const QString &filePath) {
// This doesn't report the correct path for the AppImages of the deployment process for Ubuntu 20.04!
// (see https://github.com/pbek/QOwnNotes/issues/2728#issuecomment-1466522381)
// const QString appPath = qApp->property("arguments").toStringList()[0];

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QString appPath = env.value("APPIMAGE");
const QString appPath = Utils::Misc::applicationPath();

qDebug() << __func__ << " - 'filePath': " << filePath;
qDebug() << __func__ << " - 'appPath': " << appPath;
Expand Down
21 changes: 19 additions & 2 deletions src/utils/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ QString Utils::Misc::portableDataPath() {
// argument of the executable arguments, because the applicationDirPath
// will be some temporary path
if (Utils::Misc::isAppImage()) {
const QFileInfo fileInfo(qApp->property("arguments").toStringList().at(0));
const QFileInfo fileInfo(Utils::Misc::applicationPath());
path = fileInfo.absolutePath();
} else {
path = QCoreApplication::applicationDirPath();
Expand Down Expand Up @@ -877,7 +877,7 @@ void Utils::Misc::needRestart() { qApp->setProperty("needsRestart", true); }
void Utils::Misc::restartApplication() {
// QApplication::arguments() didn't contain any parameters!
QStringList parameters = qApp->property("arguments").toStringList();
const QString appPath = parameters.takeFirst();
const QString appPath = Utils::Misc::applicationPath();

// we don't want to have our settings cleared again after a restart
parameters.removeOne(QStringLiteral("--clear-settings"));
Expand All @@ -894,6 +894,23 @@ void Utils::Misc::restartApplication() {
QApplication::quit();
}

QString Utils::Misc::applicationPath() {
QString appPath;

if (isAppImage()) {
// qApp->property("arguments").toStringList() doesn't report the correct path for the
// AppImages of the deployment process for Ubuntu 20.04!
// (see https://github.com/pbek/QOwnNotes/issues/2728#issuecomment-1466522381)
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
appPath = env.value("APPIMAGE");
} else {
QStringList parameters = qApp->property("arguments").toStringList();
appPath = parameters.takeFirst();
}

return appPath;
}

QString Utils::Misc::appendSingleAppInstanceTextIfNeeded(QString text) {
if (QSettings().value("allowOnlyOneAppInstance").toBool()) {
text.append(QStringLiteral("\n\n") +
Expand Down
1 change: 1 addition & 0 deletions src/utils/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void waitMsecs(int msecs);
QString portableDataPath();
bool isInPortableMode();
bool isAppImage();
QString applicationPath();
QString prependPortableDataPathIfNeeded(QString path, bool ifNotEmptyOnly = false);
QString makePathRelativeToPortableDataPathIfNeeded(QString path);
QString htmlToMarkdown(QString text);
Expand Down

0 comments on commit 2c428e6

Please sign in to comment.