aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.cxx3
-rw-r--r--src/StateFile.cxx21
-rw-r--r--src/StateFile.hxx7
3 files changed, 14 insertions, 17 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index 9b6630d60..322f4d618 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -347,6 +347,9 @@ idle_event_emitted(void)
unsigned flags = idle_get();
if (flags != 0)
client_list->IdleAdd(flags);
+
+ if (flags & (IDLE_PLAYLIST|IDLE_PLAYER|IDLE_MIXER|IDLE_OUTPUT))
+ state_file->CheckModified();
}
/**
diff --git a/src/StateFile.cxx b/src/StateFile.cxx
index 301ae9abb..ae782335d 100644
--- a/src/StateFile.cxx
+++ b/src/StateFile.cxx
@@ -41,7 +41,6 @@ StateFile::StateFile(Path &&_path, const char *_path_utf8,
prev_volume_version(0), prev_output_version(0),
prev_playlist_version(0)
{
- ScheduleSeconds(5 * 60);
}
void
@@ -110,24 +109,16 @@ StateFile::Read()
RememberVersions();
}
-inline void
-StateFile::AutoWrite()
+void
+StateFile::CheckModified()
{
- if (!IsModified())
- /* nothing has changed - don't save the state file,
- don't spin up the hard disk */
- return;
-
- Write();
+ if (!IsActive() && IsModified())
+ ScheduleSeconds(2 * 60);
}
-/**
- * This function is called every 5 minutes by the GLib main loop, and
- * saves the state file.
- */
bool
StateFile::OnTimeout()
{
- AutoWrite();
- return true;
+ Write();
+ return false;
}
diff --git a/src/StateFile.hxx b/src/StateFile.hxx
index 7d57d5422..79693c70b 100644
--- a/src/StateFile.hxx
+++ b/src/StateFile.hxx
@@ -48,6 +48,11 @@ public:
void Read();
void Write();
+ /**
+ * Schedules a write if MPD's state was modified.
+ */
+ void CheckModified();
+
private:
/**
* Save the current state versions for use with IsModified().
@@ -61,8 +66,6 @@ private:
gcc_pure
bool IsModified() const;
- void AutoWrite();
-
/* virtual methods from TimeoutMonitor */
virtual bool OnTimeout() override;
};