From fb05769b2c0c20654a3e41d6b8f6aaf24f176ce6 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 17 Aug 2025 15:52:10 +0800 Subject: fix(Clip): better seperator Fixed the parsing logic. Removed the weird data += '\n' line and properly handles multiple separators in a single data chunk. Now it splits the data properly and processes each part correctly. --- services/Clip.qml | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/services/Clip.qml b/services/Clip.qml index 734e2f2..7021b01 100644 --- a/services/Clip.qml +++ b/services/Clip.qml @@ -174,8 +174,9 @@ Searchable { id: clipDecodeProc property var tmp: ({}) property int index: 0 + property string separator: "\0\x01\x02CLIP_SEP_7b9a4c8d\x02\x01\0" running: true - command: ["sh", "-c", 'cliphist list | while IFS= read -r line; do\n' + ' cliphist decode "$line"; ' + 'printf "THIS IS A SEPERATOR 123 -----";\n' + 'done'] + command: ["sh", "-c", 'cliphist list | while IFS= read -r line; do\n' + ' cliphist decode "$line"; ' + 'printf "\\0\\x01\\x02CLIP_SEP_7b9a4c8d\\x02\\x01\\0";\n' + 'done'] onStarted: { clipDecodeProc.tmp = []; clipDecodeProc.index = 0; @@ -186,22 +187,17 @@ Searchable { } stdout: SplitParser { onRead: data => { - data = data += '\n'; - if (data.includes("THIS IS A SEPERATOR 123 -----")) { - const split = data.split("THIS IS A SEPERATOR 123 -----"); - const first = split[0] || ""; - const second = split[1] || ""; - if (first) - clipDecodeProc.tmp[clipDecodeProc.index] += first; + const parts = data.split(clipDecodeProc.separator); + + if (!clipDecodeProc.tmp[clipDecodeProc.index]) + clipDecodeProc.tmp[clipDecodeProc.index] = ""; + + clipDecodeProc.tmp[clipDecodeProc.index] += parts[0]; + + for (let i = 1; i < parts.length; i++) { clipDecodeProc.index++; - if (second) - clipDecodeProc.tmp[clipDecodeProc.index] = second; - return; + clipDecodeProc.tmp[clipDecodeProc.index] = parts[i]; } - if (!clipDecodeProc.tmp[clipDecodeProc.index]) - clipDecodeProc.tmp[clipDecodeProc.index] = data; - else - clipDecodeProc.tmp[clipDecodeProc.index] += data; } } } -- cgit v1.2.3