fix restart on Linux (#1617)

This commit is contained in:
Le Tan 2020-12-21 04:48:30 -08:00 committed by GitHub
parent c2e10f5783
commit 06ee73dcd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 11 deletions

View File

@ -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";

View File

@ -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);

View File

@ -17,7 +17,6 @@
#include <core/singleinstanceguard.h>
#include <core/vnotex.h>
#include <core/logger.h>
#include <core/global.h>
#include <widgets/mainwindow.h>
#include <QWebEngineSettings>
#include <core/exception.h>
@ -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;
}

View File

@ -29,7 +29,6 @@
#include <core/coreconfig.h>
#include <core/events.h>
#include <core/fileopenparameters.h>
#include <core/global.h>
#include <widgets/dialogs/scrolldialog.h>
#include "viewwindow.h"
#include "outlineviewer.h"

View File

@ -18,6 +18,8 @@ namespace vnotex
class Event;
class OutlineViewer;
enum { RESTART_EXIT_CODE = 1000 };
class MainWindow : public QMainWindow
{
Q_OBJECT

View File

@ -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.