Release KSwitcher v0.6.75 with clearer diagnostics and custom replacements
This commit is contained in:
1 parent
1407b4d260
commit
384a93dfea
18 files changed
+154
-69
No files matched your search
+39
-5
@@ -188,6 +188,7 @@ class Transaction
|
||||
ClipboardSnapshot snapshot;
|
||||
DWORD expected{};
|
||||
bool captured{};
|
||||
bool clipboardModified{};
|
||||
mutable bool invalidLogged{};
|
||||
unsigned copyNumber{};
|
||||
std::wstring adopted;
|
||||
@@ -210,9 +211,14 @@ class Transaction
|
||||
expected = GetClipboardSequenceNumber();
|
||||
try
|
||||
{
|
||||
auto started = GetTickCount64();
|
||||
const bool image = IsClipboardFormatAvailable(CF_DIB) || IsClipboardFormatAvailable(CF_DIBV5) ||
|
||||
IsClipboardFormatAvailable(CF_BITMAP) || IsClipboardFormatAvailable(RegisterClipboardFormatW(L"PNG"));
|
||||
snapshot.capture(app.window, expected);
|
||||
if (expected != GetClipboardSequenceNumber())
|
||||
throw std::runtime_error("Clipboard changed while taking snapshot");
|
||||
diagnosticEvent(L"Clipboard snapshot captured: elapsedMs=" +
|
||||
std::to_wstring(GetTickCount64() - started) + L" image=" + std::to_wstring(image));
|
||||
break;
|
||||
}
|
||||
catch (...)
|
||||
@@ -236,10 +242,12 @@ class Transaction
|
||||
~Transaction()
|
||||
{
|
||||
if (farSnippet) finishSelection(false);
|
||||
if (captured && GetClipboardSequenceNumber() == expected)
|
||||
if (captured && clipboardModified && GetClipboardSequenceNumber() == expected)
|
||||
try
|
||||
{
|
||||
auto started = GetTickCount64();
|
||||
app.ownSequence = snapshot.restore(app.window, expected);
|
||||
diagnosticEvent(L"Clipboard snapshot restored: elapsedMs=" + std::to_wstring(GetTickCount64() - started));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -296,6 +304,7 @@ class Transaction
|
||||
auto temporary = c;
|
||||
const std::wstring exclusion = L"ExcludeClipboardContentFromMonitorProcessing";
|
||||
temporary.formats.push_back({RegisterClipboardFormatW(exclusion.c_str()), exclusion, Bytes{0}});
|
||||
clipboardModified = true;
|
||||
app.ownSequence = expected = writeClipboard(app.window, temporary);
|
||||
// A concurrent writer can win immediately after CloseClipboard, before we read its sequence.
|
||||
// Never adopt that writer's sequence as our own and paste its content.
|
||||
@@ -2026,7 +2035,8 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
DiagnosticJson record{{"attempt", std::to_string(attempt)}, {"process", utf8(processName(target))},
|
||||
{"command", transformCommandName(command)}, {"source", "Unknown"}, {"target", "Unknown"},
|
||||
{"outcome", "busy"}, {"verification", "not-attempted"}, {"problem", true},
|
||||
{"elapsedMs", GetTickCount64() - requestedAt}};
|
||||
{"elapsedMs", GetTickCount64() - requestedAt},
|
||||
{"activeAttempt", activeTransformAttempt.load()}};
|
||||
diagnosticOperation(record.dump());
|
||||
}
|
||||
catch (...) {}
|
||||
@@ -2038,6 +2048,7 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
autoPending = false;
|
||||
snippetPending = -1;
|
||||
}
|
||||
activeTransformAttempt = attempt;
|
||||
Run recent;
|
||||
std::optional<LastTransform> previous;
|
||||
Settings config;
|
||||
@@ -2059,20 +2070,24 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
struct BusyReset
|
||||
{
|
||||
std::atomic<bool> &b;
|
||||
std::atomic<uint64_t> &active;
|
||||
HWND window;
|
||||
bool deferred{};
|
||||
~BusyReset()
|
||||
{
|
||||
active = 0;
|
||||
if (deferred)
|
||||
PostMessageW(window, ReplayTypingMessage, 0, 0);
|
||||
else
|
||||
b = false;
|
||||
}
|
||||
} reset{busy, window, preDeferred};
|
||||
} reset{busy, activeTransformAttempt, window, preDeferred};
|
||||
const auto workerStarted = GetTickCount64();
|
||||
auto effectiveChat = requestedChat;
|
||||
if (lower(processName(target)) == L"chrome") effectiveChat = readChromeChat(target);
|
||||
config.cycle = chatCycle(config, languageProfileKey(config, target, effectiveChat), available);
|
||||
auto start = GetTickCount64();
|
||||
ULONGLONG verificationMs{};
|
||||
std::wstring reason = L"cancelled-before-selection";
|
||||
std::wstring text, result, expected, actual, verification = L"not-attempted";
|
||||
int hint = -1, to = command >= Direct ? command - Direct : -1;
|
||||
@@ -2087,6 +2102,8 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
expected += key == L' ' ? L' ' : layout.at(physicalLayout().code(key));
|
||||
}
|
||||
diagnosticEvent(L"Transform context id=" + std::to_wstring(attempt) +
|
||||
L" queueMs=" + std::to_wstring(workerStarted - requestedAt) +
|
||||
L" profileMs=" + std::to_wstring(start - workerStarted) +
|
||||
L" layouts=" + layoutIds + L" physicalKeys=" + diagnosticText(recent.keys) +
|
||||
L" trackedExpected=" + diagnosticText(expected));
|
||||
}
|
||||
@@ -2096,6 +2113,7 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
HWND target;
|
||||
uint64_t version, attempt;
|
||||
ULONGLONG start;
|
||||
const ULONGLONG &verificationMs;
|
||||
bool enabled;
|
||||
std::wstring &reason;
|
||||
std::wstring &text, &result, &expected;
|
||||
@@ -2116,7 +2134,8 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
{"outcome", utf8(reason)}, {"verification", utf8(verification)},
|
||||
{"problem", reason != L"Paste verified" && reason != L"layout-only" &&
|
||||
!(command == 0 && reason == L"paste-sent-unverified")},
|
||||
{"elapsedMs", GetTickCount64() - start}, {"foregroundSame", GetForegroundWindow() == target},
|
||||
{"elapsedMs", GetTickCount64() - start}, {"verificationMs", verificationMs},
|
||||
{"foregroundSame", GetForegroundWindow() == target},
|
||||
{"inputSame", app.inputVersion.load() == version}, {"original", bounded(text)},
|
||||
{"expected", bounded(verification == L"selection-mismatch" ? expected : result)}, {"actual", bounded(actual)},
|
||||
{"selectionExpected", bounded(expected)},
|
||||
@@ -2126,7 +2145,7 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
}
|
||||
catch (...) {} // Logging must never abort a completed input transaction.
|
||||
}
|
||||
} audit{*this, target, version, attempt, requestedAt, manual || snippet >= 0, reason, text, result, expected,
|
||||
} audit{*this, target, version, attempt, requestedAt, verificationMs, manual || snippet >= 0, reason, text, result, expected,
|
||||
actual, verification, hint, to, command, available};
|
||||
try
|
||||
{
|
||||
@@ -2191,7 +2210,12 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
bool farEditor;
|
||||
~SelectionReset() { if (selected && !farEditor && valid()) chord(VK_RIGHT); }
|
||||
} selectionReset{autoSelected, valid, farSnippet};
|
||||
reason = L"context-changed-before-snapshot";
|
||||
if (!valid()) return;
|
||||
reason = L"clipboard-snapshot";
|
||||
Transaction tx(*this, target, version, farSnippet, snippetEditor);
|
||||
reason = L"context-changed-before-selection";
|
||||
if (!tx.valid()) return;
|
||||
reason = L"selection-unavailable";
|
||||
diagnosticEvent(L"Transform target=" + processName(target) + L" command=" + std::to_wstring(command) +
|
||||
L" recent=" + std::to_wstring(config.recent) + L" keys=" +
|
||||
@@ -2311,6 +2335,11 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
std::to_wstring(recent.keys.size()) + L" match=" + std::to_wstring(hint));
|
||||
if (hint < 0)
|
||||
{
|
||||
if (!tx.valid())
|
||||
{
|
||||
reason = L"context-changed-during-selection";
|
||||
return;
|
||||
}
|
||||
actual = text;
|
||||
verification = L"selection-mismatch";
|
||||
reason = text.empty() ? L"recent-copy-empty" : L"recent-verification-mismatch";
|
||||
@@ -2386,7 +2415,10 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
}
|
||||
bool sent = false;
|
||||
const bool requireReadback = tx.recoveredSelection() || snippet >= 0;
|
||||
auto probeStarted = GetTickCount64();
|
||||
PasteProbe probe(!farSnippet && ((config.writeLog && manual) || requireReadback) && result != text, text, target);
|
||||
verificationMs = GetTickCount64() - probeStarted;
|
||||
diagnosticEvent(L"Paste probe prepared: elapsedMs=" + std::to_wstring(verificationMs) + L" status=" + probe.status);
|
||||
if (requireReadback && !farSnippet && result != text && probe.status != L"ready")
|
||||
{
|
||||
verification = probe.status;
|
||||
@@ -2424,6 +2456,7 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
verification = probe.status;
|
||||
if (tx.valid())
|
||||
{
|
||||
auto readStarted = GetTickCount64();
|
||||
auto observed = farSnippet ? tx.readFarSnippet(caretSteps(result)) :
|
||||
probe.read((int)caretSteps(result));
|
||||
// A native Edit may silently ignore Ctrl+V while the clipboard is busy.
|
||||
@@ -2437,6 +2470,7 @@ void App::transform(int command, int snippet, size_t snippetLength, HWND snippet
|
||||
else
|
||||
observed.reset();
|
||||
}
|
||||
verificationMs += GetTickCount64() - readStarted;
|
||||
verification = farSnippet ? (observed ? L"read-back-via-far-clipboard" :
|
||||
L"far-readback-unavailable") : probe.status;
|
||||
if (observed && tx.valid())
|
||||
|
||||
Reference in new issue
Block a user