diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-08-17 15:52:10 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-08-19 20:15:21 +0800 |
| commit | fb05769b2c0c20654a3e41d6b8f6aaf24f176ce6 (patch) | |
| tree | d9d52a5ecc288241498ba5fcbf6fe7e0089f8214 /services | |
| parent | 17b0230ea1fb6cb36b75ef4544fd09222d689e81 (diff) | |
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.
Diffstat (limited to 'services')
| -rw-r--r-- | services/Clip.qml | 26 |
1 files 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; } } } |
