Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/client/StarClientApplication.cpp2
-rw-r--r--source/frontend/StarVoice.cpp26
-rw-r--r--source/frontend/StarVoice.hpp2
3 files changed, 20 insertions, 10 deletions
diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp
index 9894ed5..ba2bbd1 100644
--- a/source/client/StarClientApplication.cpp
+++ b/source/client/StarClientApplication.cpp
@@ -211,7 +211,7 @@ void ClientApplication::applicationInit(ApplicationControllerPtr appController)
appController->setUpdateTrackWindow(assets->json("/client.config:updateTrackWindow").toFloat());
if (auto jVoice = configuration->get("voice"))
- m_voice->loadJson(jVoice.toObject());
+ m_voice->loadJson(jVoice.toObject(), true);
m_voice->init();
}
diff --git a/source/frontend/StarVoice.cpp b/source/frontend/StarVoice.cpp
index 71a1a3d..d553fa1 100644
--- a/source/frontend/StarVoice.cpp
+++ b/source/frontend/StarVoice.cpp
@@ -141,7 +141,9 @@ Voice::~Voice() {
m_thread.finish();
- save();
+ if (m_nextSaveTime)
+ save();
+
closeDevice();
s_singleton = nullptr;
@@ -154,46 +156,54 @@ void Voice::init() {
template <typename T>
-inline bool change(T& value, T newValue) {
+inline bool change(T& value, T newValue, bool& out) {
bool changed = value != newValue;
+ out |= changed;
value = move(newValue);
return changed;
}
-void Voice::loadJson(Json const& config) {
+void Voice::loadJson(Json const& config, bool skipSave) {
// Not all keys are required
+ bool changed = false;
+
{
bool enabled = shouldEnableInput();
m_enabled = config.getBool("enabled", m_enabled);
m_inputEnabled = config.getBool("inputEnabled", m_inputEnabled);
- if (shouldEnableInput() != enabled)
+ if (shouldEnableInput() != enabled) {
+ changed = true;
resetDevice();
+ }
}
if (config.contains("deviceName") // Make sure null-type key exists
- && change(m_deviceName, config.optString("deviceName")))
+ && change(m_deviceName, config.optString("deviceName"), changed))
resetDevice();
m_threshold = config.getFloat("threshold", m_threshold);
m_inputVolume = config.getFloat("inputVolume", m_inputVolume);
m_outputVolume = config.getFloat("outputVolume", m_outputVolume);
- if (change(m_loopBack, config.getBool("loopBack", m_loopBack)))
+ if (change(m_loopBack, config.getBool("loopBack", m_loopBack), changed))
m_clientSpeaker->playing = false;
if (auto inputMode = config.optString("inputMode")) {
- if (change(m_inputMode, VoiceInputModeNames.getLeft(*inputMode)))
+ if (change(m_inputMode, VoiceInputModeNames.getLeft(*inputMode), changed))
m_lastInputTime = 0;
}
if (auto channelMode = config.optString("channelMode")) {
- if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode))) {
+ if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode), changed)) {
closeDevice();
resetEncoder();
resetDevice();
}
}
+
+ if (changed && !skipSave)
+ scheduleSave();
}
diff --git a/source/frontend/StarVoice.hpp b/source/frontend/StarVoice.hpp
index 15d9cd6..0cd8ca8 100644
--- a/source/frontend/StarVoice.hpp
+++ b/source/frontend/StarVoice.hpp
@@ -113,7 +113,7 @@ public:
void init();
- void loadJson(Json const& config);
+ void loadJson(Json const& config, bool skipSave = false);
Json saveJson() const;
void save() const;