summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-08-11 19:12:29 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-08-11 19:13:12 +0800
commit2941e3aad472ffb1a8ed038b5ae59eb5102b0fe6 (patch)
tree0288296dc29f2535069cec69ca78a2083eab3ee2
parent2d3ebada700f3825e1a5884eddcca80a7460fa60 (diff)
fix(Clip): decodeAndCopy function
cleanup: remove unused vars optimize: list
-rw-r--r--services/Clip.qml41
1 files changed, 13 insertions, 28 deletions
diff --git a/services/Clip.qml b/services/Clip.qml
index 81fea60..26eff11 100644
--- a/services/Clip.qml
+++ b/services/Clip.qml
@@ -15,30 +15,24 @@ Searchable {
property list<string> _clipImg: []
property list<string> _clipImgIds: _clipImg.map(p => p.split("/").pop().split(".").shift())
- property string toDecode: ""
+ property var toDecode: ""
property string toCopy: ""
- property string decoded: ""
list: {
- const arr = [];
if (!_clipHist?.length)
- return arr;
+ return [];
- const imgMap = {};
- const nimg = Math.min(_clipImg.length, _clipImgIds.length);
- for (let i = 0; i < nimg; i++) {
- const id = _clipImgIds[i];
+ const imgMap = _clipImgIds.slice(0, Math.min(_clipImg.length, _clipImgIds.length)).reduce((map, id, i) => {
if (id)
- imgMap[id] = _clipImg[i];
- }
+ map[id] = _clipImg[i];
+ return map;
+ }, {});
- for (let i = 0; i < _clipHist.length; i++) {
- const raw = _clipHist[i];
- if (!raw)
- continue;
+ return _clipHist.filter(raw => raw).map(raw => {
const tab = raw.indexOf("\t");
let idNum = -1;
let payload = raw;
+
if (tab > 0) {
const n = parseInt(raw.slice(0, tab), 10);
if (!Number.isNaN(n)) {
@@ -51,17 +45,16 @@ Searchable {
const imgPath = idStr ? imgMap[idStr] || "" : "";
const isImg = !!imgPath;
- arr.push({
+ return {
index: idNum,
isImage: isImg,
data: isImg ? imgPath : payload,
raw: raw
- });
- }
- return arr;
+ };
+ });
}
- function transformSearch(search: string): string {
+ function transformSearch(search) {
return search.toLowerCase();
}
@@ -83,15 +76,7 @@ Searchable {
Process {
id: decodeAndCopyProc
running: false
- command: ["sh", "-c", "cliphist decode" + toDecode + " | wl-copy"]
- stdout: StdioCollector {
- onStreamFinished: () => {
- decoded = data;
- }
- }
- onStarted: {
- decoded = "";
- }
+ command: ["sh", "-c", "cliphist decode " + toDecode + " | wl-copy"]
onExited: {
toDecode = "";
}