Sfoglia il codice sorgente

try to fix restart (#1613)

* consider AppImage and macOS bundle

* a
Le Tan 4 anni fa
parent
commit
c2e10f5783
4 ha cambiato i file con 33 aggiunte e 5 eliminazioni
  1. 26 4
      src/core/configmgr.cpp
  2. 4 0
      src/core/configmgr.h
  3. 1 1
      src/main.cpp
  4. 2 0
      src/widgets/toolbarhelper.cpp

+ 26 - 4
src/core/configmgr.cpp

@@ -76,11 +76,12 @@ ConfigMgr::~ConfigMgr()
 
 void ConfigMgr::locateConfigFolder()
 {
+    const auto appDirPath = getApplicationDirPath();
+    qInfo() << "app folder" << appDirPath;
     // Check app config.
     {
         const QString configFolderName("vnotex_files");
-        QString folderPath(QCoreApplication::applicationDirPath()
-                           + '/' + configFolderName);
+        QString folderPath(appDirPath + '/' + configFolderName);
         if (QDir(folderPath).exists()) {
             // Config folder in app/.
             m_appConfigFolderPath = PathUtils::cleanPath(folderPath);
@@ -92,8 +93,7 @@ void ConfigMgr::locateConfigFolder()
     // Check user config.
     {
         const QString configFolderName("user_files");
-        QString folderPath(QCoreApplication::applicationDirPath()
-                           + '/' + configFolderName);
+        QString folderPath(appDirPath + '/' + configFolderName);
         if (QDir(folderPath).exists()) {
             // Config folder in app/.
             m_userConfigFolderPath = PathUtils::cleanPath(folderPath);
@@ -375,3 +375,25 @@ QString ConfigMgr::getLogFile() const
 {
     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());
+}

+ 4 - 0
src/core/configmgr.h

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

+ 1 - 1
src/main.cpp

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

+ 2 - 0
src/widgets/toolbarhelper.cpp

@@ -313,11 +313,13 @@ 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.