mirror of
https://github.com/jellyfin/jellyfin-desktop.git
synced 2026-10-26 16:45:24 +00:00
Add CLI option option to override config dir (--config-dir)
This commit also consolidates the default configuration directories
and makes the cache path consistent.
From:
~/.cache/Jellyfin Media Player
~/.local/share/jellyfinmediaplayer
~/.local/share/Jellyfin Media Player
To just:
~/.cache/jellyfinmediaplayer
~/.local/share/jellyfinmediaplayer
This commit is contained in:
1 parent
2cfe179739
commit
b1ae61f542
6 files changed
+76
-41
No files matched your search
@@ -22,7 +22,7 @@ include_directories(${QTROOT}/include)
|
||||
set(REQUIRED_QT_VERSION "5.7.0")
|
||||
|
||||
set(QTCONFIGROOT ${QTROOT}/lib/cmake/Qt5)
|
||||
set(components Core Network WebChannel Qml Quick Xml WebEngine Widgets)
|
||||
set(components Core Network WebChannel Qml Quick Xml WebEngine WebEngineWidgets Widgets)
|
||||
|
||||
if(UNIX AND (NOT APPLE) AND ((NOT BUILD_TARGET STREQUAL "RPI")))
|
||||
add_definitions(-DUSE_X11EXTRAS)
|
||||
|
||||
+38
-1
@@ -6,9 +6,11 @@
|
||||
#include <QIcon>
|
||||
#include <QtQml>
|
||||
#include <QtWebEngine/qtwebengineglobal.h>
|
||||
#include <QtWebEngineWidgets/QWebEngineProfile>
|
||||
#include <QErrorMessage>
|
||||
#include <QCommandLineOption>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
|
||||
#include "shared/Names.h"
|
||||
#include "system/SystemComponent.h"
|
||||
@@ -114,9 +116,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
auto devOption = QCommandLineOption("remote-debugging-port", "Port number for devtools.");
|
||||
devOption.setValueName("port");
|
||||
|
||||
auto configDirOption = QCommandLineOption("config-dir", "Override config directory path.");
|
||||
configDirOption.setValueName("path");
|
||||
|
||||
parser.addOption(scaleOption);
|
||||
parser.addOption(devOption);
|
||||
parser.addOption(platformOption);
|
||||
parser.addOption(configDirOption);
|
||||
|
||||
char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
|
||||
int newArgc = argc + g_qtFlags.size();
|
||||
@@ -167,8 +174,33 @@ int main(int argc, char *argv[])
|
||||
qputenv("QT_QPA_PLATFORM", platform.toUtf8());
|
||||
}
|
||||
|
||||
auto configDir = parser.value("config-dir");
|
||||
QString webEngineDataDir;
|
||||
if (!configDir.isEmpty())
|
||||
{
|
||||
QFileInfo fi(configDir);
|
||||
QString absPath = fi.absoluteFilePath();
|
||||
QDir parentDir = fi.dir();
|
||||
|
||||
if (!parentDir.exists())
|
||||
{
|
||||
qFatal("Config directory parent does not exist: %s", qPrintable(parentDir.absolutePath()));
|
||||
}
|
||||
|
||||
Paths::setConfigDir(absPath);
|
||||
QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, absPath);
|
||||
webEngineDataDir = absPath + "/QtWebEngine";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use Paths::dataDir() equivalent inline to avoid double nesting
|
||||
QDir d(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
d.mkpath(d.absolutePath() + "/" + Names::MainName());
|
||||
d.cd(Names::MainName());
|
||||
webEngineDataDir = d.absolutePath() + "/QtWebEngine";
|
||||
}
|
||||
|
||||
QApplication app(newArgc, newArgv);
|
||||
app.setApplicationName("Jellyfin Media Player");
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
// Setting window icon on OSX will break user ability to change it
|
||||
@@ -213,6 +245,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
QtWebEngine::initialize();
|
||||
|
||||
// Configure QtWebEngine paths
|
||||
QWebEngineProfile* defaultProfile = QWebEngineProfile::defaultProfile();
|
||||
defaultProfile->setCachePath(webEngineDataDir);
|
||||
defaultProfile->setPersistentStoragePath(webEngineDataDir);
|
||||
|
||||
// load QtWebChannel so that we can register our components with it.
|
||||
QQmlApplicationEngine *engine = Globals::Engine();
|
||||
|
||||
|
||||
@@ -13,13 +13,10 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QList>
|
||||
#include <QSettings>
|
||||
#include "input/InputComponent.h"
|
||||
#include "system/SystemComponent.h"
|
||||
#include "Version.h"
|
||||
|
||||
#define OLDEST_PREVIOUS_VERSION_KEY "oldestPreviousVersion"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
SettingsComponent::SettingsComponent(QObject *parent) : ComponentBase(parent), m_settingsVersion(-1)
|
||||
{
|
||||
@@ -314,11 +311,6 @@ void SettingsComponent::loadConf(const QString& path, bool storage)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void SettingsComponent::saveSettings()
|
||||
{
|
||||
if (m_oldestPreviousVersion.isEmpty())
|
||||
{
|
||||
qCritical() << "Not writing settings: uninitialized.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap sections;
|
||||
|
||||
@@ -708,9 +700,6 @@ bool SettingsComponent::componentInitialize()
|
||||
if (!loadDescription())
|
||||
return false;
|
||||
|
||||
// Must be called before we possibly write the config file.
|
||||
setupVersion();
|
||||
|
||||
load();
|
||||
|
||||
// add our AudioSettingsController that will inspect audio settings and react.
|
||||
@@ -726,24 +715,6 @@ bool SettingsComponent::componentInitialize()
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
void SettingsComponent::setupVersion()
|
||||
{
|
||||
QSettings settings;
|
||||
m_oldestPreviousVersion = settings.value(OLDEST_PREVIOUS_VERSION_KEY).toString();
|
||||
if (m_oldestPreviousVersion.isEmpty())
|
||||
{
|
||||
// Version key was not present. It could still be a pre-1.1 PMP install,
|
||||
// so here we try to find out whether this is the very first install, or
|
||||
// if an older one exists.
|
||||
QFile configFile(Paths::dataDir("jellyfinmediaplayer.conf"));
|
||||
if (configFile.exists())
|
||||
m_oldestPreviousVersion = "legacy";
|
||||
else
|
||||
m_oldestPreviousVersion = Version::GetVersionString();
|
||||
settings.setValue(OLDEST_PREVIOUS_VERSION_KEY, m_oldestPreviousVersion);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool SettingsComponent::resetAndSaveOldConfiguration()
|
||||
|
||||
@@ -94,11 +94,6 @@ public:
|
||||
//
|
||||
static bool resetAndSaveOldConfiguration();
|
||||
|
||||
QString oldestPreviousVersion() const
|
||||
{
|
||||
return m_oldestPreviousVersion;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit SettingsComponent(QObject *parent = nullptr);
|
||||
bool loadDescription();
|
||||
@@ -106,15 +101,12 @@ private:
|
||||
int platformMaskFromObject(const QJsonObject& object);
|
||||
Platform platformFromString(const QString& platformString);
|
||||
void saveSection(SettingsSection* section);
|
||||
void setupVersion();
|
||||
|
||||
QMap<QString, SettingsSection*> m_sections;
|
||||
|
||||
int m_settingsVersion;
|
||||
int m_sectionIndex;
|
||||
|
||||
QString m_oldestPreviousVersion;
|
||||
|
||||
void loadConf(const QString& path, bool storage);
|
||||
};
|
||||
|
||||
|
||||
+36
-2
@@ -13,6 +13,15 @@
|
||||
#include "Names.h"
|
||||
#include "Version.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
static QString g_configDirOverride;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
void Paths::setConfigDir(const QString& path)
|
||||
{
|
||||
g_configDirOverride = path;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
static QDir writableLocation(QStandardPaths::StandardLocation loc)
|
||||
{
|
||||
@@ -59,7 +68,22 @@ QString Paths::resourceDir(const QString& file)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
QString Paths::dataDir(const QString& file)
|
||||
{
|
||||
QDir d = writableLocation(QStandardPaths::GenericDataLocation);
|
||||
QDir d;
|
||||
|
||||
if (!g_configDirOverride.isEmpty())
|
||||
{
|
||||
d = QDir(g_configDirOverride);
|
||||
if (!d.mkpath(d.absolutePath()))
|
||||
{
|
||||
qWarning() << "Failed to create override directory:" << d.absolutePath();
|
||||
d = writableLocation(QStandardPaths::GenericDataLocation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
d = writableLocation(QStandardPaths::GenericDataLocation);
|
||||
}
|
||||
|
||||
if (file.isEmpty())
|
||||
return d.absolutePath();
|
||||
return d.filePath(file);
|
||||
@@ -83,7 +107,17 @@ QString Paths::logDir(const QString& file)
|
||||
ldir.cd("Library/Logs/" + Names::MainName());
|
||||
return ldir.filePath(file);
|
||||
#else
|
||||
QDir ldir = writableLocation(QStandardPaths::GenericDataLocation);
|
||||
QDir ldir;
|
||||
|
||||
if (!g_configDirOverride.isEmpty())
|
||||
{
|
||||
ldir = QDir(g_configDirOverride);
|
||||
}
|
||||
else
|
||||
{
|
||||
ldir = writableLocation(QStandardPaths::GenericDataLocation);
|
||||
}
|
||||
|
||||
ldir.mkpath(ldir.absolutePath() + "/logs");
|
||||
ldir.cd("logs");
|
||||
return ldir.filePath(file);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Paths
|
||||
{
|
||||
void setConfigDir(const QString& path);
|
||||
QString resourceDir(const QString& file = QString());
|
||||
QString dataDir(const QString& file = QString());
|
||||
QString cacheDir(const QString& file = QString());
|
||||
|
||||
Reference in new issue
Block a user