From 06ee73dcd5bdd1c20f834c655ae09a95457dffc9 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 21 Dec 2020 04:48:30 -0800 Subject: [PATCH] fix restart on Linux (#1617) --- src/core/configmgr.cpp | 10 +++++++--- src/core/global.h | 3 --- src/main.cpp | 6 ++++-- src/widgets/mainwindow.cpp | 1 - src/widgets/mainwindow.h | 2 ++ src/widgets/toolbarhelper.cpp | 3 +-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/configmgr.cpp b/src/core/configmgr.cpp index 88758733..f9848e55 100644 --- a/src/core/configmgr.cpp +++ b/src/core/configmgr.cpp @@ -378,9 +378,13 @@ QString ConfigMgr::getLogFile() const QString ConfigMgr::getApplicationFilePath() { -#if defined(Q_OS_Linux) - // TODO: Check if it is from AppImage. - // We could get the APPIMAGE env variable from the AppRun script and pass it to vnote via cmd. +#if defined(Q_OS_LINUX) + // We could get the APPIMAGE env variable from the AppRun script. + auto appImageVar = QString::fromLocal8Bit(qgetenv("APPIMAGE")); + qInfo() << "APPIMAGE" << appImageVar; + if (!appImageVar.isEmpty()) { + return appImageVar; + } #elif defined(Q_OS_MACOS) auto exePath = QCoreApplication::applicationFilePath(); const QString exeName = c_appName.toLower() + ".app"; diff --git a/src/core/global.h b/src/core/global.h index 88a727c9..1d0a2380 100644 --- a/src/core/global.h +++ b/src/core/global.h @@ -72,9 +72,6 @@ namespace vnotex IncrementalSearch = 0x10U }; Q_DECLARE_FLAGS(FindOptions, FindOption); - - enum { RESTART_EXIT_CODE = 1000 }; - } // ns vnotex Q_DECLARE_OPERATORS_FOR_FLAGS(vnotex::FindOptions); diff --git a/src/main.cpp b/src/main.cpp index 9a66aebb..dc897f76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -131,7 +130,10 @@ int main(int argc, char *argv[]) if (ret == RESTART_EXIT_CODE) { // Asked to restart VNote. guard.exit(); - QProcess::startDetached(ConfigMgr::getApplicationFilePath(), QStringList()); + QProcess::startDetached(QCoreApplication::applicationFilePath(), QStringList()); + // Must use exit() in Linux to quit the parent process in Qt 5.12. + // Thanks to @ygcaicn. + exit(0); return 0; } diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index a05d7314..235e50a5 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "viewwindow.h" #include "outlineviewer.h" diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index 3fd5bea2..b9819af7 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -18,6 +18,8 @@ namespace vnotex class Event; class OutlineViewer; + enum { RESTART_EXIT_CODE = 1000 }; + class MainWindow : public QMainWindow { Q_OBJECT diff --git a/src/widgets/toolbarhelper.cpp b/src/widgets/toolbarhelper.cpp index f7dc3c9a..7abf6f4f 100644 --- a/src/widgets/toolbarhelper.cpp +++ b/src/widgets/toolbarhelper.cpp @@ -313,13 +313,12 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too [p_win]() { p_win->quitApp(); }); -#if !defined(Q_OS_LINUX) + menu->addAction(MainWindow::tr("Restart"), menu, [p_win]() { p_win->restart(); }); -#endif } // Help.