try to fix restart (#1613)

* consider AppImage and macOS bundle

* a
This commit is contained in:
Le Tan 2020-12-19 23:47:01 -08:00 committed by GitHub
parent d51e486a84
commit c2e10f5783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 5 deletions

View File

@ -76,11 +76,12 @@ ConfigMgr::~ConfigMgr()
void ConfigMgr::locateConfigFolder() void ConfigMgr::locateConfigFolder()
{ {
const auto appDirPath = getApplicationDirPath();
qInfo() << "app folder" << appDirPath;
// Check app config. // Check app config.
{ {
const QString configFolderName("vnotex_files"); const QString configFolderName("vnotex_files");
QString folderPath(QCoreApplication::applicationDirPath() QString folderPath(appDirPath + '/' + configFolderName);
+ '/' + configFolderName);
if (QDir(folderPath).exists()) { if (QDir(folderPath).exists()) {
// Config folder in app/. // Config folder in app/.
m_appConfigFolderPath = PathUtils::cleanPath(folderPath); m_appConfigFolderPath = PathUtils::cleanPath(folderPath);
@ -92,8 +93,7 @@ void ConfigMgr::locateConfigFolder()
// Check user config. // Check user config.
{ {
const QString configFolderName("user_files"); const QString configFolderName("user_files");
QString folderPath(QCoreApplication::applicationDirPath() QString folderPath(appDirPath + '/' + configFolderName);
+ '/' + configFolderName);
if (QDir(folderPath).exists()) { if (QDir(folderPath).exists()) {
// Config folder in app/. // Config folder in app/.
m_userConfigFolderPath = PathUtils::cleanPath(folderPath); m_userConfigFolderPath = PathUtils::cleanPath(folderPath);
@ -375,3 +375,25 @@ QString ConfigMgr::getLogFile() const
{ {
return PathUtils::concatenateFilePath(ConfigMgr::getInst().getUserFolder(), "vnotex.log"); return PathUtils::concatenateFilePath(ConfigMgr::getInst().getUserFolder(), "vnotex.log");
} }
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.
#elif defined(Q_OS_MACOS)
auto exePath = QCoreApplication::applicationFilePath();
const QString exeName = c_appName.toLower() + ".app";
int idx = exePath.indexOf(exeName + QStringLiteral("/Contents/MacOS/"));
if (idx != -1) {
return exePath.left(idx + exeName.size());
}
#endif
return QCoreApplication::applicationFilePath();
}
QString ConfigMgr::getApplicationDirPath()
{
return PathUtils::parentDirPath(getApplicationFilePath());
}

View File

@ -94,6 +94,10 @@ namespace vnotex
// Called at boostrap without QApplication instance. // Called at boostrap without QApplication instance.
static QString locateSessionConfigFilePathAtBootstrap(); static QString locateSessionConfigFilePathAtBootstrap();
static QString getApplicationFilePath();
static QString getApplicationDirPath();
static const QString c_orgName; static const QString c_orgName;
static const QString c_appName; static const QString c_appName;

View File

@ -131,7 +131,7 @@ int main(int argc, char *argv[])
if (ret == RESTART_EXIT_CODE) { if (ret == RESTART_EXIT_CODE) {
// Asked to restart VNote. // Asked to restart VNote.
guard.exit(); guard.exit();
QProcess::startDetached(qApp->applicationFilePath(), QStringList()); QProcess::startDetached(ConfigMgr::getApplicationFilePath(), QStringList());
return 0; return 0;
} }

View File

@ -313,11 +313,13 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too
[p_win]() { [p_win]() {
p_win->quitApp(); p_win->quitApp();
}); });
#if !defined(Q_OS_LINUX)
menu->addAction(MainWindow::tr("Restart"), menu->addAction(MainWindow::tr("Restart"),
menu, menu,
[p_win]() { [p_win]() {
p_win->restart(); p_win->restart();
}); });
#endif
} }
// Help. // Help.