Modules/Graphics/public/SessionRecording.hpp
Шурупов Илья Викторович 447b6fa31e Every application keeps its data in ~/<application>; pasted images go there
AppStorage (Modules) names an application's persistent folder, ~/<name>, with
images/ and sessions/ subfolders. WindowHost::persistentAppStorage() is pure
virtual, so every WidgetApplication must say where its data lives; widgets
reach it through ui()->windowHost().

MarkdownEditor without an explicit image store now saves a pasted image into
<application>/images/pasted-N.<ext> and links it by absolute path, instead of
ignoring it with "nowhere to save it". saveClipboardImage is the one writer of
pasted image files; the gallery's own store uses it too.

Session recordings default to <application>/sessions instead of
~/<application>-sessions; MODULES_SESSION_DIR still overrides it.
AppStorage::adoptLegacyDirectory moves an older folder in once, by rename.
2026-10-25 14:44:21 +03:00

71 lines
1.7 KiB
C++

#pragma once
#include "InputRecording.hpp"
#include <functional>
#include <memory>
#include <string>
namespace tp {
struct SessionEnvironment {
std::string revision;
std::string device;
std::string date;
Vec2F windowSize = { 0, 0 };
halnf contentScale = 1;
std::string application;
[[nodiscard]] std::string serialize() const;
};
struct SessionRecording {
using Saver = std::function<bool(const std::string& directory)>;
SessionEnvironment environment;
InputRecording input;
std::string recordedFrames;
Saver saveSnapshot;
bool save(const std::string& directory) const;
};
class SessionRecorderHost {
public:
virtual ~SessionRecorderHost() = default;
virtual void setRawInputTap(WindowInputObserver* tap) = 0;
[[nodiscard]] virtual SessionEnvironment environment() const = 0;
[[nodiscard]] virtual double nowMs() const = 0;
};
class SessionRecorder {
public:
using Snapshot = std::function<SessionRecording::Saver(const SessionEnvironment& environment)>;
explicit SessionRecorder(SessionRecorderHost& host);
~SessionRecorder();
SessionRecorder(const SessionRecorder&) = delete;
SessionRecorder& operator=(const SessionRecorder&) = delete;
void setSnapshot(Snapshot snapshot) { mSnapshot = std::move(snapshot); }
[[nodiscard]] bool isRecording() const { return mRecording != nullptr; }
[[nodiscard]] double elapsedMs() const;
void start();
[[nodiscard]] SessionRecording stop();
void cancel();
[[nodiscard]] static std::string defaultDirectory(const std::string& applicationSessionsDirectory);
[[nodiscard]] static std::string recordedFramesTsv();
private:
struct Recording;
SessionRecorderHost& mHost;
Snapshot mSnapshot;
std::unique_ptr<Recording> mRecording;
};
}