Skip to content

Commit

Permalink
fix crash on startup if appdatadir defined in config
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Apr 2, 2023
1 parent 80e4487 commit 85514f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/settings.cpp
Expand Up @@ -51,11 +51,8 @@ ShotcutSettings &ShotcutSettings::singleton()

ShotcutSettings::ShotcutSettings()
: QObject()
, m_recent(QDir(appDataLocation()).filePath(RECENT_INI_FILENAME), QSettings::IniFormat)
{
// Setup separate INI file for recent storage
QDir dir(appDataLocation());
m_recent = new QSettings(dir.filePath(RECENT_INI_FILENAME), QSettings::IniFormat, this);

// Migrate old startup layout to a custom layout and start fresh
if (!settings.contains("geometry2")) {
auto geometry = settings.value("geometry").toByteArray();
Expand All @@ -78,7 +75,7 @@ ShotcutSettings::ShotcutSettings()
}
}
setRecent(newRecents);
m_recent->sync();
m_recent.sync();
// settings.remove("recent");
settings.sync();
}
Expand All @@ -88,6 +85,7 @@ ShotcutSettings::ShotcutSettings(const QString &appDataLocation)
: QObject()
, settings(appDataLocation + SHOTCUT_INI_FILENAME, QSettings::IniFormat)
, m_appDataLocation(appDataLocation)
, m_recent(QDir(appDataLocation).filePath(RECENT_INI_FILENAME), QSettings::IniFormat)
{
ShotcutSettings();
}
Expand Down Expand Up @@ -156,15 +154,15 @@ void ShotcutSettings::setSavePath(const QString &s)

QStringList ShotcutSettings::recent() const
{
return m_recent->value(kRecentKey).toStringList();
return m_recent.value(kRecentKey).toStringList();
}

void ShotcutSettings::setRecent(const QStringList &ls)
{
if (ls.isEmpty())
m_recent->remove(kRecentKey);
m_recent.remove(kRecentKey);
else if (!clearRecent())
m_recent->setValue(kRecentKey, ls);
m_recent.setValue(kRecentKey, ls);
}

QString ShotcutSettings::theme() const
Expand Down
7 changes: 4 additions & 3 deletions src/settings.h
Expand Up @@ -71,8 +71,6 @@ class ShotcutSettings : public QObject
static const qsizetype MaxPath {32767};

static ShotcutSettings &singleton();
explicit ShotcutSettings();
explicit ShotcutSettings(const QString &appDataLocation);
void log();

// general
Expand Down Expand Up @@ -312,9 +310,12 @@ public slots:
void askOutputFilterChanged();

private:
explicit ShotcutSettings();
explicit ShotcutSettings(const QString &appDataLocation);

QSettings settings;
QString m_appDataLocation;
QSettings *m_recent;
QSettings m_recent;
};

#define Settings ShotcutSettings::singleton()
Expand Down

0 comments on commit 85514f0

Please sign in to comment.