more sane way to capture clipboard, also move extension dispatch off main thread
This commit is contained in:
parent
96e9b66e9f
commit
bdc083a62a
@ -117,13 +117,12 @@ namespace
|
||||
|
||||
void StartCapturingClipboard()
|
||||
{
|
||||
std::thread([]
|
||||
SetWindowsHookExW(WH_GETMESSAGE, [](int statusCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
for (std::wstring last; true; Sleep(500))
|
||||
if (auto text = Util::GetClipboardText())
|
||||
if (last != text.value())
|
||||
Host::GetThread(CLIPBOARD)->AddSentence(last = text.value());
|
||||
}).detach();
|
||||
if (statusCode == HC_ACTION && wParam == PM_REMOVE && ((MSG*)lParam)->message == WM_CLIPBOARDUPDATE)
|
||||
if (auto text = Util::GetClipboardText()) Host::GetThread(CLIPBOARD)->PushSentence(text.value());
|
||||
return CallNextHookEx(NULL, statusCode, wParam, lParam);
|
||||
}, NULL, GetCurrentThreadId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,6 +206,6 @@ namespace Host
|
||||
|
||||
void AddConsoleOutput(std::wstring text)
|
||||
{
|
||||
GetThread(CONSOLE)->AddSentence(text);
|
||||
GetThread(CONSOLE)->PushSentence(text);
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@ TextThread::~TextThread()
|
||||
OnDestroy(this);
|
||||
}
|
||||
|
||||
void TextThread::AddSentence(std::wstring sentence)
|
||||
{
|
||||
if (Output(this, sentence)) storage->append(sentence);
|
||||
}
|
||||
|
||||
void TextThread::Push(const BYTE* data, int len)
|
||||
{
|
||||
if (len < 0) return;
|
||||
@ -35,6 +30,13 @@ void TextThread::Push(const BYTE* data, int len)
|
||||
lastPushTime = GetTickCount();
|
||||
}
|
||||
|
||||
void TextThread::PushSentence(std::wstring sentence)
|
||||
{
|
||||
LOCK(bufferMutex);
|
||||
buffer += sentence;
|
||||
lastPushTime = 0;
|
||||
}
|
||||
|
||||
void TextThread::Flush()
|
||||
{
|
||||
std::wstring sentence;
|
||||
@ -48,5 +50,5 @@ void TextThread::Flush()
|
||||
if (Util::RemoveRepetition(sentence)) repeatingChars = std::unordered_set(sentence.begin(), sentence.end());
|
||||
else repeatingChars.clear();
|
||||
}
|
||||
AddSentence(sentence);
|
||||
if (Output(this, sentence)) storage->append(sentence);
|
||||
}
|
||||
|
@ -19,8 +19,9 @@ public:
|
||||
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});
|
||||
~TextThread();
|
||||
|
||||
void AddSentence(std::wstring sentence);
|
||||
void Push(const BYTE* data, int len);
|
||||
// Flushes ASAP
|
||||
void PushSentence(std::wstring sentence);
|
||||
|
||||
ThreadSafe<std::wstring> storage;
|
||||
const int64_t handle;
|
||||
|
Loading…
x
Reference in New Issue
Block a user