LunaHook-mirror/LunaHost/textthread.h

45 lines
1.1 KiB
C
Raw Normal View History

2024-02-07 20:59:24 +08:00
#pragma once
class TextThread
{
public:
2024-10-03 14:53:59 +08:00
using OutputCallback = std::function<bool(TextThread &, std::wstring &)>;
2024-02-07 20:59:24 +08:00
inline static OutputCallback Output;
inline static bool filterRepetition = false;
2024-10-03 14:53:59 +08:00
inline static int flushDelay = 100;
2024-10-08 19:21:30 +08:00
inline static int maxBufferSize = 3000;
2024-02-07 20:59:24 +08:00
inline static int maxHistorySize = 10'000'000;
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});
void Start();
void Stop();
void AddSentence(std::wstring sentence);
2024-10-03 14:53:59 +08:00
void Push(BYTE *data, int length);
void Push(const wchar_t *data);
2024-02-07 20:59:24 +08:00
Synchronized<std::wstring> storage;
const int64_t handle;
const std::wstring name;
const ThreadParam tp;
HookParam hp;
private:
inline static int threadCounter = 0;
void Flush();
std::wstring buffer;
BYTE leadByte = 0;
std::unordered_set<wchar_t> repeatingChars;
std::mutex bufferMutex;
DWORD64 lastPushTime = 0;
Synchronized<std::vector<std::wstring>> queuedSentences;
2024-10-03 14:53:59 +08:00
struct TimerDeleter
{
void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); }
};
2024-02-07 20:59:24 +08:00
AutoHandle<TimerDeleter> timer = NULL;
};