Skip to content

Commit

Permalink
Add mutex for saving
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Jun 2, 2020
1 parent 3c3d7c5 commit 1bdf686
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char *argv[])
auto jsonData = settings.legacyToJson().toJson();
jsonFile.write(jsonData);
jsonFile.close();
settings = Settings();
settings.load();
}
// Check fallback icons
Icon::useFallbackIcons = settings.general.fallbackIcons;
Expand Down
5 changes: 4 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ void Settings::load()
spotify.bitrate = s["bitrate"].toInt(320);
}

void Settings::save() const
void Settings::save()
{
mutex.lock();

QJsonArray jsonHiddenSongHeaders;
for (auto &val : general.hiddenSongHeaders)
jsonHiddenSongHeaders.append(val);
Expand Down Expand Up @@ -123,6 +125,7 @@ void Settings::save() const
file.open(QIODevice::WriteOnly);
file.write(QJsonDocument(json).toJson(QJsonDocument::Indented));
file.close();
mutex.unlock();
}

QJsonDocument Settings::legacyToJson()
Expand Down
8 changes: 4 additions & 4 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QFile>
#include <QStandardPaths>
#include <QDebug>
#include <QMutex>

class Settings
{
Expand All @@ -17,7 +18,8 @@ class Settings
virtual ~Settings();

QJsonDocument legacyToJson();
void save() const;
void save();
void load();

enum Palette
{
Expand Down Expand Up @@ -87,9 +89,7 @@ class Settings
bool sptGlobalConfig();
bool fixedWidthTime();

void load();

static Settings *set;

QSettings *settings;
QMutex mutex;
};

0 comments on commit 1bdf686

Please sign in to comment.