diff --git a/doc/user.xml b/doc/user.xml
index b01703173..a9c92be15 100644
--- a/doc/user.xml
+++ b/doc/user.xml
@@ -898,6 +898,18 @@ systemctl start mpd.socket
(+wx).
+
+
+
+ state_file_interval
+ SECONDS
+
+
+ Auto-save the state file this number of seconds
+ after each state change. Defaults to
+ 120 (2 minutes).
+
+
diff --git a/src/Main.cxx b/src/Main.cxx
index d8dbdb5d2..d8384abfb 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -279,7 +279,10 @@ glue_state_file_init(Error &error)
#endif
}
- state_file = new StateFile(std::move(path_fs),
+ unsigned interval = config_get_unsigned(CONF_STATE_FILE_INTERVAL,
+ StateFile::DEFAULT_INTERVAL);
+
+ state_file = new StateFile(std::move(path_fs), interval,
*instance->partition,
*instance->event_loop);
state_file->Read();
diff --git a/src/StateFile.cxx b/src/StateFile.cxx
index e0f0cedb1..7e9e35cc3 100644
--- a/src/StateFile.cxx
+++ b/src/StateFile.cxx
@@ -36,10 +36,11 @@
static constexpr Domain state_file_domain("state_file");
-StateFile::StateFile(AllocatedPath &&_path,
+StateFile::StateFile(AllocatedPath &&_path, unsigned _interval,
Partition &_partition, EventLoop &_loop)
:TimeoutMonitor(_loop),
path(std::move(_path)), path_utf8(path.ToUTF8()),
+ interval(_interval),
partition(_partition),
prev_volume_version(0), prev_output_version(0),
prev_playlist_version(0)
@@ -137,7 +138,7 @@ void
StateFile::CheckModified()
{
if (!IsActive() && IsModified())
- ScheduleSeconds(2 * 60);
+ ScheduleSeconds(interval);
}
void
diff --git a/src/StateFile.hxx b/src/StateFile.hxx
index 4bacb3449..15ba13b97 100644
--- a/src/StateFile.hxx
+++ b/src/StateFile.hxx
@@ -34,6 +34,8 @@ class StateFile final : private TimeoutMonitor {
const AllocatedPath path;
const std::string path_utf8;
+ const unsigned interval;
+
Partition &partition;
/**
@@ -44,7 +46,10 @@ class StateFile final : private TimeoutMonitor {
prev_playlist_version;
public:
- StateFile(AllocatedPath &&path, Partition &partition, EventLoop &loop);
+ static constexpr unsigned DEFAULT_INTERVAL = 2 * 60;
+
+ StateFile(AllocatedPath &&path, unsigned interval,
+ Partition &partition, EventLoop &loop);
void Read();
void Write();
diff --git a/src/config/ConfigOption.hxx b/src/config/ConfigOption.hxx
index 506c9e9dc..8eb4c7eaf 100644
--- a/src/config/ConfigOption.hxx
+++ b/src/config/ConfigOption.hxx
@@ -32,6 +32,7 @@ enum ConfigOption {
CONF_LOG_FILE,
CONF_PID_FILE,
CONF_STATE_FILE,
+ CONF_STATE_FILE_INTERVAL,
CONF_RESTORE_PAUSED,
CONF_USER,
CONF_GROUP,
diff --git a/src/config/ConfigTemplates.cxx b/src/config/ConfigTemplates.cxx
index 8eaa22bdd..58ee56425 100644
--- a/src/config/ConfigTemplates.cxx
+++ b/src/config/ConfigTemplates.cxx
@@ -32,6 +32,7 @@ const ConfigTemplate config_templates[] = {
{ "log_file", false, false },
{ "pid_file", false, false },
{ "state_file", false, false },
+ { "state_file_interval", false, false },
{ "restore_paused", false, false },
{ "user", false, false },
{ "group", false, false },