Autosave named scenes with revision and disk conflict safety
This commit is contained in:
@@ -25,7 +25,8 @@ class AuthoringService {
|
||||
const Json& operations, const std::string& idempotency_key = "");
|
||||
Json undo(const std::string& document, std::uint64_t expected_revision);
|
||||
Json redo(const std::string& document, std::uint64_t expected_revision);
|
||||
Json save(const std::string& document, const std::filesystem::path& relative = {});
|
||||
Json save(const std::string& document, const std::filesystem::path& relative = {},
|
||||
std::optional<std::uint64_t> expected_revision = std::nullopt);
|
||||
Json recovery_documents() const;
|
||||
Json recover(const std::string& document,
|
||||
std::optional<std::uint64_t> expected_revision = std::nullopt);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <faset/core/json.hpp>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace faset::editor {
|
||||
|
||||
class AutosaveController {
|
||||
public:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
using SaveFn = std::function<Json(const std::string&, std::uint64_t)>;
|
||||
explicit AutosaveController(SaveFn save);
|
||||
|
||||
// Called from the Editor event loop with an injected monotonic clock for
|
||||
// deterministic tests. Only a named dirty scene becomes eligible to save.
|
||||
void observe(const Json& documents, Clock::time_point now, bool enabled);
|
||||
Json status() const;
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
std::uint64_t revision{};
|
||||
std::string path, state = "saved", error;
|
||||
Clock::time_point deadline{};
|
||||
};
|
||||
SaveFn save_;
|
||||
mutable std::mutex mutex_;
|
||||
std::map<std::string, Entry> entries_;
|
||||
bool enabled_ = true;
|
||||
};
|
||||
|
||||
} // namespace faset::editor
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <faset/assets/asset_pipeline.hpp>
|
||||
#include <faset/core/process.hpp>
|
||||
#include <faset/editor/build_service.hpp>
|
||||
#include <faset/editor/autosave.hpp>
|
||||
#include <faset/editor/commands.hpp>
|
||||
#include <faset/editor/plugins.hpp>
|
||||
#include <memory>
|
||||
@@ -62,6 +63,8 @@ class Session {
|
||||
Commands commands_;
|
||||
assets::AssetPipeline assets_;
|
||||
BuildService builds_;
|
||||
AutosaveController autosave_;
|
||||
bool autosave_enabled_ = true;
|
||||
std::map<std::string, std::shared_ptr<ImportTask>> imports_;
|
||||
std::vector<std::jthread> workers_;
|
||||
std::vector<std::string> logs_;
|
||||
|
||||
Reference in New Issue
Block a user