Browse Source

Adding XDG standard directory for flatpak compatibility on Linux

Felix Turo 2 years ago
parent
commit
116a999c1e
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/classes/paths.cpp

+ 18 - 0
src/classes/paths.cpp

@@ -10,6 +10,23 @@ Paths::Paths()
 
 const bool Paths::setup()
 {
+
+// Define the application paths. This will be standard locations on all platforms eventually
+// but for now on Windows and MacOS use the application runtime directory to make it easier to
+// debug and develop. On Linux XDG standard directories are required for the flatpak to work.
+
+#ifdef linux
+    LOG << "Setting up directories at: " << QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+    const QString dir_path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+    for(const auto& str : qAsConst(directories)){
+        QDir dir(dir_path + str);
+        if(!dir.exists()) {
+            if (!dir.mkpath(dir.absolutePath()))
+                return false;
+        }
+    }
+    return true;
+#else
     LOG << "Setting up directories at: " << QCoreApplication::applicationDirPath();
     const QString dir_path = QCoreApplication::applicationDirPath();
     for(const auto& str : qAsConst(directories)){
@@ -20,6 +37,7 @@ const bool Paths::setup()
         }
     }
     return true;
+#endif
 }
 
 const QDir Paths::directory(Directories location)