feat(search): 系统/用户app增加中文和拼音搜索

This commit is contained in:
徐志鹏 2021-07-27 21:29:53 +08:00
parent 129f19bf39
commit ae87a9bd5a
7 changed files with 542 additions and 379 deletions

243
package-lock.json generated
View File

@ -283,6 +283,55 @@
}
}
},
"@mapbox/node-pre-gyp": {
"version": "1.0.5",
"resolved": "https://registry.nlark.com/@mapbox/node-pre-gyp/download/@mapbox/node-pre-gyp-1.0.5.tgz",
"integrity": "sha1-Kgsy/LQW+z8iUP0kyyqBQhpPWVA=",
"dev": true,
"optional": true,
"requires": {
"detect-libc": "^1.0.3",
"https-proxy-agent": "^5.0.0",
"make-dir": "^3.1.0",
"node-fetch": "^2.6.1",
"nopt": "^5.0.0",
"npmlog": "^4.1.2",
"rimraf": "^3.0.2",
"semver": "^7.3.4",
"tar": "^6.1.0"
},
"dependencies": {
"make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/make-dir/download/make-dir-3.1.0.tgz",
"integrity": "sha1-QV6WcEazp/HRhSd9hKpYIDcmoT8=",
"dev": true,
"optional": true,
"requires": {
"semver": "^6.0.0"
},
"dependencies": {
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npm.taobao.org/semver/download/semver-6.3.0.tgz?cache=0&sync_timestamp=1616463641178&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-6.3.0.tgz",
"integrity": "sha1-7gpkyK9ejO6mdoexM3YeG+y9HT0=",
"dev": true,
"optional": true
}
}
},
"nopt": {
"version": "5.0.0",
"resolved": "https://registry.npm.taobao.org/nopt/download/nopt-5.0.0.tgz?cache=0&sync_timestamp=1597649942437&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnopt%2Fdownload%2Fnopt-5.0.0.tgz",
"integrity": "sha1-UwlCu1ilEvzK/lP+IQ8TolNV3Ig=",
"dev": true,
"optional": true,
"requires": {
"abbrev": "1"
}
}
}
},
"@samverschueren/stream-to-observable": {
"version": "0.3.1",
"resolved": "http://npmreg.qa.91jkys.com/@samverschueren%2fstream-to-observable/-/stream-to-observable-0.3.1.tgz",
@ -939,7 +988,8 @@
"ansi-regex": {
"version": "3.0.0",
"resolved": "http://npmreg.qa.91jkys.com/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"ansi-styles": {
"version": "3.2.1",
@ -1136,7 +1186,8 @@
"aproba": {
"version": "1.2.0",
"resolved": "http://npmreg.qa.91jkys.com/aproba/-/aproba-1.2.0.tgz",
"integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo="
"integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=",
"dev": true
},
"archive-type": {
"version": "4.0.0",
@ -1157,6 +1208,7 @@
"version": "1.1.5",
"resolved": "http://npmreg.qa.91jkys.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"integrity": "sha1-SzXClE8GKov82mZBB2A1D+nd/CE=",
"dev": true,
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.6"
@ -2640,6 +2692,11 @@
"tweetnacl": "^0.14.3"
}
},
"big-integer": {
"version": "1.6.48",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz",
"integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w=="
},
"big.js": {
"version": "5.2.2",
"resolved": "http://npmreg.qa.91jkys.com/big.js/-/big.js-5.2.2.tgz",
@ -2888,6 +2945,14 @@
}
}
},
"bplist-parser": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.3.0.tgz",
"integrity": "sha512-zgmaRvT6AN1JpPPV+S0a1/FAtoxSreYDccZGIqEMSvZl9DMe70mJ7MFzpxa1X+gHVdkToE2haRUHHMiW1OdejA==",
"requires": {
"big-integer": "1.6.x"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "http://npmreg.qa.91jkys.com/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -4220,7 +4285,8 @@
"console-control-strings": {
"version": "1.1.0",
"resolved": "http://npmreg.qa.91jkys.com/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"dev": true
},
"consolidate": {
"version": "0.15.1",
@ -4951,7 +5017,8 @@
"delegates": {
"version": "1.0.0",
"resolved": "http://npmreg.qa.91jkys.com/delegates/-/delegates-1.0.0.tgz",
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
"dev": true
},
"depd": {
"version": "1.1.2",
@ -4993,7 +5060,8 @@
"detect-libc": {
"version": "1.0.3",
"resolved": "http://npmreg.qa.91jkys.com/detect-libc/-/detect-libc-1.0.3.tgz",
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=",
"dev": true
},
"detect-node": {
"version": "2.1.0",
@ -6550,11 +6618,6 @@
}
}
},
"expand-template": {
"version": "2.0.3",
"resolved": "http://npmreg.qa.91jkys.com/expand-template/-/expand-template-2.0.3.tgz",
"integrity": "sha1-bhSz/O4POmNA7LV9LokYaSBSpHw="
},
"expand-tilde": {
"version": "2.0.2",
"resolved": "http://npmreg.qa.91jkys.com/expand-tilde/-/expand-tilde-2.0.2.tgz",
@ -7041,6 +7104,7 @@
"version": "2.7.4",
"resolved": "http://npmreg.qa.91jkys.com/gauge/-/gauge-2.7.4.tgz",
"integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=",
"dev": true,
"requires": {
"aproba": "^1.0.3",
"console-control-strings": "^1.0.0",
@ -7055,12 +7119,14 @@
"ansi-regex": {
"version": "2.1.1",
"resolved": "http://npmreg.qa.91jkys.com/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "http://npmreg.qa.91jkys.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"dev": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -7069,6 +7135,7 @@
"version": "1.0.2",
"resolved": "http://npmreg.qa.91jkys.com/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"dev": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -7079,6 +7146,7 @@
"version": "3.0.1",
"resolved": "http://npmreg.qa.91jkys.com/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -7158,11 +7226,6 @@
"resolved": "http://npmreg.qa.91jkys.com/git-clone/-/git-clone-0.1.0.tgz",
"integrity": "sha1-DXYWN3gJOu9/HDAjjyqe8/B6Lrk="
},
"github-from-package": {
"version": "0.0.0",
"resolved": "http://npmreg.qa.91jkys.com/github-from-package/-/github-from-package-0.0.0.tgz",
"integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4="
},
"glob": {
"version": "7.1.7",
"resolved": "http://npmreg.qa.91jkys.com/glob/-/glob-7.1.7.tgz",
@ -7433,7 +7496,8 @@
"has-unicode": {
"version": "2.0.1",
"resolved": "http://npmreg.qa.91jkys.com/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"dev": true
},
"has-value": {
"version": "1.0.0",
@ -8244,7 +8308,8 @@
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "http://npmreg.qa.91jkys.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"is-glob": {
"version": "4.0.1",
@ -8667,6 +8732,12 @@
"resolved": "http://npmreg.qa.91jkys.com/keycode/-/keycode-2.2.0.tgz",
"integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ="
},
"keypress": {
"version": "0.1.0",
"resolved": "https://registry.npm.taobao.org/keypress/download/keypress-0.1.0.tgz",
"integrity": "sha1-SjGI1CkbZrT2XtuZ+AaqmuKTWSo=",
"dev": true
},
"keyv": {
"version": "3.0.0",
"resolved": "http://npmreg.qa.91jkys.com/keyv/-/keyv-3.0.0.tgz",
@ -9644,11 +9715,6 @@
"minimist": "^1.2.5"
}
},
"mkdirp-classic": {
"version": "0.5.3",
"resolved": "http://npmreg.qa.91jkys.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha1-+hDJEVzG2IZb4iG6R+6b7XhgERM="
},
"moment": {
"version": "2.29.1",
"resolved": "http://npmreg.qa.91jkys.com/moment/-/moment-2.29.1.tgz",
@ -9864,7 +9930,9 @@
"nan": {
"version": "2.14.2",
"resolved": "http://npmreg.qa.91jkys.com/nan/-/nan-2.14.2.tgz",
"integrity": "sha1-9TdkAGlRaPTMaUrJOT0MlYXu6hk="
"integrity": "sha1-9TdkAGlRaPTMaUrJOT0MlYXu6hk=",
"dev": true,
"optional": true
},
"nanomatch": {
"version": "1.2.13",
@ -9908,11 +9976,6 @@
"resolved": "http://npmreg.qa.91jkys.com/nanopop/-/nanopop-2.1.0.tgz",
"integrity": "sha1-I0dlE87iQFiIr9LopLVAZrcLnmA="
},
"napi-build-utils": {
"version": "1.0.2",
"resolved": "http://npmreg.qa.91jkys.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz",
"integrity": "sha1-sf3cCyxG44Cgt6dvmE3UfEGhOAY="
},
"natives": {
"version": "1.1.6",
"resolved": "http://npmreg.qa.91jkys.com/natives/-/natives-1.1.6.tgz",
@ -9986,6 +10049,7 @@
"version": "2.30.0",
"resolved": "http://npmreg.qa.91jkys.com/node-abi/-/node-abi-2.30.0.tgz",
"integrity": "sha1-i+U78+eUWjTuoQ4PyaWYJ3bPVQs=",
"dev": true,
"requires": {
"semver": "^5.4.1"
},
@ -9993,7 +10057,8 @@
"semver": {
"version": "5.7.1",
"resolved": "http://npmreg.qa.91jkys.com/semver/-/semver-5.7.1.tgz",
"integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc="
"integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc=",
"dev": true
}
}
},
@ -10166,6 +10231,26 @@
}
}
},
"nodejieba": {
"version": "2.5.2",
"resolved": "https://registry.nlark.com/nodejieba/download/nodejieba-2.5.2.tgz?cache=0&sync_timestamp=1619409865538&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fnodejieba%2Fdownload%2Fnodejieba-2.5.2.tgz",
"integrity": "sha1-/JKe4p+Twoxjlpa6wDGbrBFqKWo=",
"dev": true,
"optional": true,
"requires": {
"@mapbox/node-pre-gyp": "^1.0.4",
"node-addon-api": "^3.0.2"
},
"dependencies": {
"node-addon-api": {
"version": "3.2.1",
"resolved": "https://registry.nlark.com/node-addon-api/download/node-addon-api-3.2.1.tgz",
"integrity": "sha1-gTJeCiEXeJwBKNq2Xn448HzroWE=",
"dev": true,
"optional": true
}
}
},
"nopt": {
"version": "4.0.3",
"resolved": "http://npmreg.qa.91jkys.com/nopt/-/nopt-4.0.3.tgz",
@ -10284,6 +10369,7 @@
"version": "4.1.2",
"resolved": "http://npmreg.qa.91jkys.com/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=",
"dev": true,
"requires": {
"are-we-there-yet": "~1.1.2",
"console-control-strings": "~1.1.0",
@ -11082,6 +11168,28 @@
"pinkie": "^2.0.0"
}
},
"pinyin": {
"version": "2.10.2",
"resolved": "https://registry.npm.taobao.org/pinyin/download/pinyin-2.10.2.tgz",
"integrity": "sha1-k+Ozy0QwAJklFjutEMdBd4yFsBM=",
"dev": true,
"requires": {
"commander": "~1.1.1",
"nodejieba": "^2.2.1",
"object-assign": "^4.0.1"
},
"dependencies": {
"commander": {
"version": "1.1.1",
"resolved": "https://registry.nlark.com/commander/download/commander-1.1.1.tgz?cache=0&sync_timestamp=1624609539421&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fcommander%2Fdownload%2Fcommander-1.1.1.tgz",
"integrity": "sha1-UNFlGGiuYOzP8KLZ80WVN2vGsEE=",
"dev": true,
"requires": {
"keypress": "0.1.x"
}
}
}
},
"pkg-dir": {
"version": "2.0.0",
"resolved": "http://npmreg.qa.91jkys.com/pkg-dir/-/pkg-dir-2.0.0.tgz",
@ -11701,37 +11809,6 @@
"uniqs": "^2.0.0"
}
},
"prebuild-install": {
"version": "6.1.3",
"resolved": "http://npmreg.qa.91jkys.com/prebuild-install/-/prebuild-install-6.1.3.tgz",
"integrity": "sha1-jqH51zhqCzD37yAkfjb4srgoJaI=",
"requires": {
"detect-libc": "^1.0.3",
"expand-template": "^2.0.3",
"github-from-package": "0.0.0",
"minimist": "^1.2.3",
"mkdirp-classic": "^0.5.3",
"napi-build-utils": "^1.0.1",
"node-abi": "^2.21.0",
"npmlog": "^4.0.1",
"pump": "^3.0.0",
"rc": "^1.2.7",
"simple-get": "^3.0.3",
"tar-fs": "^2.0.0",
"tunnel-agent": "^0.6.0"
},
"dependencies": {
"pump": {
"version": "3.0.0",
"resolved": "http://npmreg.qa.91jkys.com/pump/-/pump-3.0.0.tgz",
"integrity": "sha1-tKIRaBW94vTh6mAjVOjHVWUQemQ=",
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
}
}
},
"prepend-http": {
"version": "2.0.0",
"resolved": "http://npmreg.qa.91jkys.com/prepend-http/-/prepend-http-2.0.0.tgz",
@ -12809,14 +12886,6 @@
}
}
},
"robotjs": {
"version": "git+ssh://git@github.com/Toinane/robotjs.git#66bf4fe6206d25400eed6090f9e68326faf3c18a",
"from": "git+ssh://git@github.com/Toinane/robotjs.git",
"requires": {
"nan": "^2.14.2",
"prebuild-install": "^6.1.2"
}
},
"run-queue": {
"version": "1.0.3",
"resolved": "http://npmreg.qa.91jkys.com/run-queue/-/run-queue-1.0.3.tgz",
@ -13046,7 +13115,8 @@
"set-blocking": {
"version": "2.0.0",
"resolved": "http://npmreg.qa.91jkys.com/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",
"dev": true
},
"set-value": {
"version": "2.0.1",
@ -13122,36 +13192,6 @@
"resolved": "http://npmreg.qa.91jkys.com/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha1-oUEMLt2PB3sItOJTyOrPyvBXRhw="
},
"simple-concat": {
"version": "1.0.1",
"resolved": "http://npmreg.qa.91jkys.com/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha1-9Gl2CCujXCJj8cirXt/ibEHJVS8="
},
"simple-get": {
"version": "3.1.0",
"resolved": "http://npmreg.qa.91jkys.com/simple-get/-/simple-get-3.1.0.tgz",
"integrity": "sha1-tFvgYkNeUNFZVAtXYgLO7EC5xrM=",
"requires": {
"decompress-response": "^4.2.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
},
"dependencies": {
"decompress-response": {
"version": "4.2.1",
"resolved": "http://npmreg.qa.91jkys.com/decompress-response/-/decompress-response-4.2.1.tgz",
"integrity": "sha1-QUAjzHowLaJc4uyC0NUjjMr9iYY=",
"requires": {
"mimic-response": "^2.0.0"
}
},
"mimic-response": {
"version": "2.1.0",
"resolved": "http://npmreg.qa.91jkys.com/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha1-0Tdj019hPQnsN+uzC6wEacDuj0M="
}
}
},
"single-line-log": {
"version": "1.1.2",
"resolved": "https://registry.npm.taobao.org/single-line-log/download/single-line-log-1.1.2.tgz",
@ -13783,6 +13823,7 @@
"version": "2.1.1",
"resolved": "http://npmreg.qa.91jkys.com/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha1-q5Pyeo3BPSjKyBXEYhQ6bZASrp4=",
"dev": true,
"requires": {
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
@ -13820,6 +13861,7 @@
"version": "4.0.0",
"resolved": "http://npmreg.qa.91jkys.com/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
@ -16134,6 +16176,7 @@
"version": "1.1.3",
"resolved": "http://npmreg.qa.91jkys.com/wide-align/-/wide-align-1.1.3.tgz",
"integrity": "sha1-rgdOa9wMFKQx6ATmJFScYzsABFc=",
"dev": true,
"requires": {
"string-width": "^1.0.2 || 2"
}

View File

@ -60,6 +60,7 @@
"dependencies": {
"ant-design-vue": "^1.7.5",
"axios": "^0.18.1",
"bplist-parser": "^0.3.0",
"download": "^8.0.0",
"download-git-repo": "^3.0.2",
"electron-store": "^8.0.0",
@ -73,9 +74,9 @@
"puppeteer-core": "^10.0.0",
"puppeteer-in-electron": "^3.0.3",
"query-string": "^7.0.0",
"robotjs": "git+https://github.com/Toinane/robotjs.git",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"robotjs": "git+https://github.com/Toinane/robotjs.git",
"semver": "^7.3.5",
"sudo-prompt": "^9.2.1",
"unzip": "^0.1.11",
@ -109,6 +110,7 @@
"electron-rebuild": "^2.3.5",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"iconv-lite": "^0.6.3",
"less": "^4.1.1",
"less-loader": "^5.0.0",
"listr": "^0.14.3",
@ -116,6 +118,7 @@
"multispinner": "^0.2.1",
"node-abi": "^2.30.0",
"node-loader": "^0.6.0",
"pinyin": "^2.10.2",
"react": "^17.0.2",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",

View File

@ -3,52 +3,65 @@
<div v-if="!searchType" class="rubick-select">
<div class="tag-container" v-if="selected">
<a-tag
:key="selected.key"
@close="closeTag"
class="select-tag"
color="green"
closable
:key="selected.key"
@close="closeTag"
class="select-tag"
color="green"
closable
>
{{ selected.name }}
</a-tag>
</div>
<a-input
id="search"
:placeholder="subPlaceHolder && selected && selected.key === 'plugin-container' ? subPlaceHolder : 'Hi, Rubick'"
class="main-input"
@change="e => search({value: e.target.value})"
:value="searchValue"
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
@keydown.down="(e) => changeCurrent(1)"
@keydown.up="() => changeCurrent(-1)"
@keypress.enter="(e) => targetSearch({value: e.target.value, type: 'enter'})"
@keypress.space="(e) => targetSearch({value: e.target.value, type: 'space'})"
id="search"
:placeholder="
subPlaceHolder && selected && selected.key === 'plugin-container'
? subPlaceHolder
: 'Hi, Rubick'
"
class="main-input"
@change="(e) => search({ value: e.target.value })"
:value="searchValue"
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
@keydown.down="(e) => changeCurrent(1)"
@keydown.up="() => changeCurrent(-1)"
@keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
@keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
>
<div @click="goMenu" class="suffix-tool" slot="suffix">
<a-icon v-show="selected && selected.key === 'plugin-container'" class="icon-more" type="more" />
<img class="icon-tool" v-if="selected && selected.icon" :src="selected.icon" />
<a-icon
v-show="selected && selected.key === 'plugin-container'"
class="icon-more"
type="more"
/>
<img
class="icon-tool"
v-if="selected && selected.icon"
:src="selected.icon"
/>
<div v-else class="rubick-logo">
<img src="./assets/logo.png" />
</div>
</div>
</a-input>
<div class="options" v-show="showOptions">
<a-list item-layout="horizontal" :data-source="options">
<a-list-item
@click="() => item.click($router)"
:class="currentSelect === index ? 'active op-item' : 'op-item'"
slot="renderItem"
slot-scope="item, index"
@click="() => item.click($router)"
:class="currentSelect === index ? 'active op-item' : 'op-item'"
slot="renderItem"
slot-scope="item, index"
>
<a-list-item-meta
:description="item.desc"
>
<span slot="title" v-html="renderTitle(item.name)" ></span>
<a-list-item-meta :description="item.desc">
<span slot="title" v-html="renderTitle(item.name)"></span>
<a-avatar
slot="avatar"
style="border-radius: 0;"
:src="item.icon"
slot="avatar"
style="border-radius: 0"
:src="item.icon"
/>
</a-list-item-meta>
<a-tag v-show="item.type === 'dev'">开发者</a-tag>
@ -59,14 +72,28 @@
</div>
<div class="rubick-select-subMenu" v-else>
<div>
<img class="icon-tool-sub" v-if="pluginInfo.icon" :src="pluginInfo.icon" />
<img
class="icon-tool-sub"
v-if="pluginInfo.icon"
:src="pluginInfo.icon"
/>
<a-input
:placeholder="subPlaceHolder"
class="sub-input"
@change="(e) => search({value: e.target.value, searchType: pluginInfo.searchType})"
:value="searchValue"
@keypress.enter="(e) => targetSearch({value: e.target.value, type: 'enter'})"
@keypress.space="(e) => targetSearch({value: e.target.value, type: 'space'})"
:placeholder="subPlaceHolder"
class="sub-input"
@change="
(e) =>
search({
value: e.target.value,
searchType: pluginInfo.searchType,
})
"
:value="searchValue"
@keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
@keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
></a-input>
</div>
@ -79,11 +106,16 @@
</a-layout>
</template>
<script>
import {mapActions, mapMutations, mapState} from "vuex";
import {ipcRenderer, remote} from "electron";
import {getWindowHeight, debounce, searchKeyValues, fileLists} from "./assets/common/utils";
const opConfig = remote.getGlobal('opConfig');
const {Menu, MenuItem} = remote;
import { mapActions, mapMutations, mapState } from "vuex";
import { ipcRenderer, remote } from "electron";
import {
getWindowHeight,
debounce,
searchKeyValues,
fileLists,
} from "./assets/common/utils";
const opConfig = remote.getGlobal("opConfig");
const { Menu, MenuItem } = remote;
export default {
data() {
@ -92,7 +124,7 @@ export default {
searchFn: null,
config: opConfig.get(),
currentSelect: 0,
}
};
},
created() {
@ -100,17 +132,17 @@ export default {
this.commonUpdate({
pluginInfo: pluginInfo,
});
}
};
},
mounted() {
ipcRenderer.on('init-rubick', this.closeTag);
ipcRenderer.on('new-window', this.newWindow);
ipcRenderer.on("init-rubick", this.closeTag);
ipcRenderer.on("new-window", this.newWindow);
//
ipcRenderer.on('superPanel-openPlugin', (e, args) => {
ipcRenderer.on("superPanel-openPlugin", (e, args) => {
this.closeTag();
ipcRenderer.send('msg-trigger', {
type: 'showMainWindow',
ipcRenderer.send("msg-trigger", {
type: "showMainWindow",
});
this.openPlugin({
cmd: args.cmd,
@ -118,45 +150,47 @@ export default {
feature: args.feature,
router: this.$router,
payload: args.data,
})
});
});
ipcRenderer.on('global-short-key', (e, args) => {
ipcRenderer.on("global-short-key", (e, args) => {
let config;
this.devPlugins.forEach((plugin) => {
// dev
if (plugin.type === 'dev' && !plugin.status) return;
if (plugin.type === "dev" && !plugin.status) return;
const feature = plugin.features;
feature.forEach(fe => {
feature.forEach((fe) => {
const cmd = searchKeyValues(fe.cmds, args)[0];
const systemPlugin = fileLists.filter(plugin => plugin.name.indexOf(args) >= 0)[0];
const systemPlugin = fileLists.filter(
(plugin) => plugin.name.indexOf(args) >= 0
)[0];
if (cmd) {
config = {
cmd: cmd,
plugin: plugin,
feature: fe,
router: this.$router
}
router: this.$router,
};
} else if (systemPlugin) {
config = {
plugin: systemPlugin,
router: this.$router
}
router: this.$router,
};
}
})
});
});
config && this.openPlugin(config);
});
//
ipcRenderer.on('tray-setting', () => {
ipcRenderer.on("tray-setting", () => {
this.showMainUI();
this.changePath({key: 'settings'});
this.changePath({ key: "settings" });
});
const searchNd = document.getElementById('search');
searchNd && searchNd.addEventListener('keydown', this.checkNeedInit)
const searchNd = document.getElementById("search");
searchNd && searchNd.addEventListener("keydown", this.checkNeedInit);
},
methods: {
...mapActions('main', ['onSearch', 'showMainUI', 'openPlugin']),
...mapMutations('main', ['commonUpdate']),
...mapActions("main", ["onSearch", "showMainUI", "openPlugin"]),
...mapMutations("main", ["commonUpdate"]),
search(v) {
if (!this.searchFn) {
this.searchFn = debounce(this.onSearch, 200);
@ -165,44 +199,55 @@ export default {
},
targetSearch(action) {
//
if((this.selected && this.selected.key === 'plugin-container') || this.searchType === 'subWindow') {
const webview = document.getElementById('webview');
if (action.type === 'space') {
if (
(this.selected && this.selected.key === "plugin-container") ||
this.searchType === "subWindow"
) {
const webview = document.getElementById("webview");
if (action.type === "space") {
if (this.config.perf.common.space) {
webview.send('msg-back-setSubInput', this.searchValue);
webview.send("msg-back-setSubInput", this.searchValue);
}
return;
}
webview.send('msg-back-setSubInput', this.searchValue);
webview.send("msg-back-setSubInput", this.searchValue);
} else if (this.showOptions) {
const item = this.options[this.currentSelect]
const item = this.options[this.currentSelect];
item.click(this.$router);
}
},
changeCurrent(index) {
const webview = document.getElementById('webview');
webview && webview.send('changeCurrent', index);
const webview = document.getElementById("webview");
webview && webview.send("changeCurrent", index);
if (!this.options) return;
if (this.currentSelect + index > this.options.length - 1 || this.currentSelect + index < 0) return;
if (
this.currentSelect + index > this.options.length - 1 ||
this.currentSelect + index < 0
)
return;
this.currentSelect = this.currentSelect + index;
},
renderTitle(title) {
if (typeof title !== 'string') return;
if (typeof title !== "string") return;
const result = title.split(this.searchValue);
return `<div>${result[0]}<span style="color: red">${this.searchValue}</span>${result[1]}</div>`
if (result && result.length > 1) {
return `<div>${result[0]}<span style="color: red">${this.searchValue}</span>${result[1]}</div>`;
} else {
return `<div>${result[0]}</div>`;
}
},
checkNeedInit(e) {
// tag
if (this.searchValue === '' && e.keyCode === 8) {
if (this.searchValue === "" && e.keyCode === 8) {
this.closeTag();
}
},
changePath({key}) {
this.$router.push({path: `/home/${key}`});
changePath({ key }) {
this.$router.push({ path: `/home/${key}` });
this.commonUpdate({
current: [key]
})
current: [key],
});
},
closeTag(v) {
this.commonUpdate({
@ -210,60 +255,72 @@ export default {
showMain: false,
options: [],
});
ipcRenderer.send('changeWindowSize-rubick', {
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight([]),
});
this.$router.push({
path: '/home',
path: "/home",
});
},
newWindow() {
ipcRenderer.send('new-window', {
...this.pluginInfo
ipcRenderer.send("new-window", {
...this.pluginInfo,
});
this.closeTag();
},
goMenu(type) {
if ((this.selected && this.selected.key === 'plugin-container') || type === 'separate') {
if (
(this.selected && this.selected.key === "plugin-container") ||
type === "separate"
) {
const pluginMenu = [
{
label: '开发者工具',
label: "开发者工具",
click: () => {
const webview = document.getElementById('webview');
webview.openDevTools()
}
const webview = document.getElementById("webview");
webview.openDevTools();
},
},
{
label: '当前插件信息',
label: "当前插件信息",
submenu: [
{
label: '简介',
label: "简介",
},
{
label: '功能'
}
]
label: "功能",
},
],
},
{
label: '隐藏插件',
label: "隐藏插件",
},
];
if (type !== 'separate') {
if (type !== "separate") {
pluginMenu.unshift({
label: '分离窗口',
click: this.newWindow
})
label: "分离窗口",
click: this.newWindow,
});
}
let menu = Menu.buildFromTemplate(pluginMenu);
menu.popup();
return;
}
this.showMainUI();
this.changePath({key: 'market'})
this.changePath({ key: "market" });
},
},
computed: {
...mapState('main', ['showMain', 'devPlugins', 'current', 'options', 'selected', 'searchValue', 'subPlaceHolder', 'pluginInfo']),
...mapState("main", [
"showMain",
"devPlugins",
"current",
"options",
"selected",
"searchValue",
"subPlaceHolder",
"pluginInfo",
]),
showOptions() {
//
if (this.options.length && !this.showMain) {
@ -271,9 +328,9 @@ export default {
}
},
searchType() {
return this.pluginInfo.searchType ? 'subWindow' : ''
}
}
return this.pluginInfo.searchType ? "subWindow" : "";
},
},
};
</script>
<style lang="less">
@ -289,7 +346,8 @@ export default {
width: 0;
}
}
.rubick-select, .rubick-select-subMenu {
.rubick-select,
.rubick-select-subMenu {
display: flex;
padding-left: 10px;
background: #fff;
@ -333,7 +391,7 @@ export default {
left: 0;
width: 100%;
z-index: 99;
max-height: calc(~'100vh - 60px');
max-height: calc(~"100vh - 60px");
overflow: auto;
.op-item {
padding: 0 10px;
@ -343,7 +401,7 @@ export default {
overflow: auto;
background: #fafafa;
&.active {
background: #DEE2E8;
background: #dee2e8;
}
}
}

View File

@ -1,4 +1,4 @@
export default {
development: 'http://118.195.176.247:8080',
production: 'http://118.195.176.247:8080',
production: 'http://118.195.176.247:8080'
};

View File

@ -4,65 +4,55 @@ const PRE_ITEM_HEIGHT = 60;
const SYSTEM_PLUGINS = [
{
"pluginName": "rubick 帮助文档",
"logo": require('../imgs/help.png'),
"features": [
pluginName: 'rubick 帮助文档',
logo: require('../imgs/help.png'),
features: [
{
"code": "help",
"explain": "rubick 帮助文档",
"cmds": [ "Help", "帮助" ]
},
code: 'help',
explain: 'rubick 帮助文档',
cmds: ['Help', '帮助']
}
],
"tag": 'rubick-help',
tag: 'rubick-help'
},
{
"pluginName": "屏幕颜色拾取",
"logo": require('../imgs/picker.png'),
"features": [
pluginName: '屏幕颜色拾取',
logo: require('../imgs/picker.png'),
features: [
{
"code": "pick",
"explain": "rubick 帮助文档",
"cmds": [ "取色", "拾色", 'Pick color' ]
},
code: 'pick',
explain: 'rubick 帮助文档',
cmds: ['取色', '拾色', 'Pick color']
}
],
"tag": 'rubick-color',
tag: 'rubick-color'
},
{
"pluginName": "截屏",
"logo": require('../imgs/screenshot.png'),
"features": [
pluginName: '截屏',
logo: require('../imgs/screenshot.png'),
features: [
{
"code": "shortCut",
"explain": "rubick 屏幕截取",
"cmds": [ "截屏", "shortCut" ]
},
code: 'shortCut',
explain: 'rubick 屏幕截取',
cmds: ['截屏', 'shortCut']
}
],
"tag": 'rubick-screen-short-cut',
tag: 'rubick-screen-short-cut'
},
{
"pluginName": "锁屏",
"logo": require('../imgs/lock.png'),
"features": [
pluginName: '锁屏',
logo: require('../imgs/lock.png'),
features: [
{
"code": "lock",
"explain": "锁屏",
"cmds": [ "锁屏", "lock screen" ]
},
code: 'lock',
explain: '锁屏',
cmds: ['锁屏', 'lock screen']
}
],
"tag": 'rubick-lock',
tag: 'rubick-lock'
}
];
const APP_FINDER_PATH = [
'/System/Applications',
'/Applications',
'/System/Library/PreferencePanes',
];
const APP_FINDER_PATH = ['/System/Applications', '/Applications', '/System/Library/PreferencePanes'];
export {
WINDOW_MAX_HEIGHT,
WINDOW_MIN_HEIGHT,
PRE_ITEM_HEIGHT,
SYSTEM_PLUGINS,
APP_FINDER_PATH,
}
export { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS, APP_FINDER_PATH };

View File

@ -1,26 +1,31 @@
import {WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS} from './constans';
import { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS } from './constans';
import path from 'path';
import fs from 'fs';
import process from 'child_process';
import Store from 'electron-store';
import downloadFile from 'download';
import {nativeImage, ipcRenderer} from 'electron';
import {APP_FINDER_PATH} from './constans';
import {getlocalDataFile} from "../../../main/common/utils";
import { nativeImage, ipcRenderer } from 'electron';
import { APP_FINDER_PATH } from './constans';
import { getlocalDataFile } from '../../../main/common/utils';
import iconvLite from 'iconv-lite';
import bpList from 'bplist-parser';
import pinyin from 'pinyin';
const store = new Store();
function getWindowHeight(searchList) {
if (!searchList) return WINDOW_MAX_HEIGHT;
if (!searchList.length) return WINDOW_MIN_HEIGHT;
return searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5 > WINDOW_MAX_HEIGHT ? WINDOW_MAX_HEIGHT : searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5;
return searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5 > WINDOW_MAX_HEIGHT
? WINDOW_MAX_HEIGHT
: searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5;
}
function searchKeyValues(lists, value){
return lists.filter(item => {
function searchKeyValues(lists, value) {
return lists.filter((item) => {
if (typeof item === 'string') return item.indexOf(value) >= 0;
return item.type.indexOf(value) >= 0;
})
});
}
function existOrNot(path) {
@ -47,7 +52,7 @@ async function downloadZip(downloadRepoUrl, name) {
await process.execSync(`rm -rf ${temp_dest}`);
}
await downloadFile(downloadRepoUrl, plugin_path,{extract: true});
await downloadFile(downloadRepoUrl, plugin_path, { extract: true });
return temp_dest;
} catch (e) {
@ -60,12 +65,12 @@ const sysFile = {
ipcRenderer.send('optionPlugin', {
plugins: plugins.filter((plugin) => {
let hasOption = false;
plugin.features.forEach(fe => {
fe.cmds.forEach(cmd => {
plugin.features.forEach((fe) => {
fe.cmds.forEach((cmd) => {
if (cmd.type) {
hasOption = true;
}
})
});
});
return hasOption;
})
@ -76,26 +81,26 @@ const sysFile = {
try {
return store.get('user-plugins');
} catch (e) {
return []
return [];
}
},
removeAllPlugins() {
store.delete('user-plugins');
}
}
};
function mergePlugins(plugins) {
const result = [
...plugins,
...SYSTEM_PLUGINS.map(plugin => {
...SYSTEM_PLUGINS.map((plugin) => {
return {
...plugin,
status: true,
sourceFile: '',
type: 'system',
}
type: 'system'
};
})
]
];
const target = [];
@ -103,28 +108,29 @@ function mergePlugins(plugins) {
let targetIndex = -1;
target.forEach((tg, j) => {
if (tg.tag === item.tag && tg.type === 'system') {
targetIndex = j
targetIndex = j;
}
});
if (targetIndex === -1) {
target.push(item)
target.push(item);
}
});
ipcRenderer && ipcRenderer.send('optionPlugin', {
plugins: target.filter((plugin) => {
let hasOption = false;
plugin.features.forEach(fe => {
fe.cmds.forEach(cmd => {
if (cmd.type) {
hasOption = true;
}
})
});
return hasOption;
})
});
ipcRenderer &&
ipcRenderer.send('optionPlugin', {
plugins: target.filter((plugin) => {
let hasOption = false;
plugin.features.forEach((fe) => {
fe.cmds.forEach((cmd) => {
if (cmd.type) {
hasOption = true;
}
});
});
return hasOption;
})
});
return target
return target;
}
function find(p, target = 'plugin.json') {
@ -132,7 +138,7 @@ function find(p, target = 'plugin.json') {
let result;
const fileList = fs.readdirSync(p);
for (let i = 0; i < fileList.length; i++) {
let thisPath = p + "/" + fileList[i];
let thisPath = p + '/' + fileList[i];
const data = fs.statSync(thisPath);
if (data.isFile() && fileList[i] === target) {
@ -150,14 +156,50 @@ function find(p, target = 'plugin.json') {
}
const fileLists = [];
// 默认搜索目录
APP_FINDER_PATH.forEach((searchPath) => {
const isZhRegex = /[\u4e00-\u9fa5]/;
const getDisplayNameRegex = /\"(?:CFBundleDisplayName)\"\s\=\s\"(.*)\"/;
async function getAppZhName(rootPath, appName) {
try {
const ERROR_RESULT = '';
const systemPath = path.join(rootPath, `${appName}/Contents/Resources/zh_CN.lproj/InfoPlist.strings`);
const customizePath = path.join(rootPath, `${appName}/Contents/Resources/zh-Hans.lproj/InfoPlist.strings`);
let appInfoPath = '';
if (fs.existsSync(systemPath)) {
appInfoPath = systemPath;
} else if (fs.existsSync(customizePath)) {
appInfoPath = customizePath;
} else {
return ERROR_RESULT;
}
let appZhName = '';
if (rootPath == '/Applications') {
const container = iconvLite.decode(fs.readFileSync(appInfoPath), 'utf-16');
if (container) {
const res = container.match(getDisplayNameRegex);
appZhName = res && res[1];
} else {
return ERROR_RESULT;
}
} else {
const [{ CFBundleDisplayName = '', CFBundleName = '' }] = await bpList.parseFile(appInfoPath);
appZhName = CFBundleDisplayName || CFBundleName;
}
return appZhName;
} catch (error) {
return ERROR_RESULT;
}
}
APP_FINDER_PATH.forEach((searchPath, index) => {
fs.readdir(searchPath, async (err, files) => {
try {
for (let i = 0; i < files.length; i++) {
const appName = files[i];
const extname = path.extname(appName);
const appSubStr = appName.split(extname)[0];
if ((extname === '.app' || extname === '.prefPane') >= 0 ) {
if ((extname === '.app' || extname === '.prefPane') >= 0) {
try {
const path1 = path.join(searchPath, `${appName}/Contents/Resources/App.icns`);
const path2 = path.join(searchPath, `${appName}/Contents/Resources/AppIcon.icns`);
@ -175,21 +217,45 @@ APP_FINDER_PATH.forEach((searchPath) => {
} else {
// 性能最低的方式
const resourceList = fs.readdirSync(path.join(searchPath, `${appName}/Contents/Resources`));
const iconName = resourceList.filter(file => path.extname(file) === '.icns')[0];
const iconName = resourceList.filter((file) => path.extname(file) === '.icns')[0];
iconPath = path.join(searchPath, `${appName}/Contents/Resources/${iconName}`);
}
const img = await nativeImage.createThumbnailFromPath(iconPath, {width: 64, height: 64});
fileLists.push({
name: appSubStr,
const img = await nativeImage.createThumbnailFromPath(iconPath, { width: 64, height: 64 });
const appZhName = await getAppZhName(searchPath, appName);
const fileOptions = {
value: 'plugin',
icon: img.toDataURL(),
desc: path.join(searchPath, appName),
type: 'app',
action: `open ${path.join(searchPath, appName).replace(' ', '\\ ')}`
})
} catch (e) {
}
};
fileLists.push({
...fileOptions,
name: appSubStr,
keyWord: appSubStr
});
if (appZhName && isZhRegex.test(appZhName)) {
let cmds = [];
const pinyinArr = pinyin(appZhName, { style: pinyin.STYLE_NORMAL });
// pinyinArr = [['pin'], ['yin']]
const firstLetterArr = pinyinArr.map((str) => str[0][0]);
cmds.push(appZhName);
cmds.push(pinyinArr.join(''));
cmds.push(firstLetterArr.join(''));
cmds.forEach((cmd) => {
fileLists.push({
...fileOptions,
name: appZhName,
keyWord: cmd
});
});
}
} catch (e) {}
}
}
} catch (e) {
@ -198,27 +264,17 @@ APP_FINDER_PATH.forEach((searchPath) => {
});
});
function debounce(fn, delay) {
let timer
return function () {
const context = this
const args = arguments
let timer;
return function() {
const context = this;
const args = arguments;
clearTimeout(timer)
timer = setTimeout(function () {
fn.apply(context, args)
}, delay)
}
clearTimeout(timer);
timer = setTimeout(function() {
fn.apply(context, args);
}, delay);
};
}
export {
getWindowHeight,
searchKeyValues,
sysFile,
mergePlugins,
find,
downloadZip,
fileLists,
debounce,
}
export { getWindowHeight, searchKeyValues, sysFile, mergePlugins, find, downloadZip, fileLists, debounce };

View File

@ -1,4 +1,4 @@
import {clipboard, ipcRenderer, remote} from "electron";
import { clipboard, ipcRenderer, remote } from 'electron';
import { v4 as uuidv4 } from 'uuid';
import {
getWindowHeight,
@ -7,12 +7,12 @@ import {
mergePlugins,
find,
downloadZip,
fileLists,
fileLists
} from '../../assets/common/utils';
import systemMethod from '../../assets/common/system';
import fs from "fs";
import fs from 'fs';
import path from 'path';
import {execSync} from 'child_process';
import { execSync } from 'child_process';
const state = {
selected: null,
@ -25,17 +25,17 @@ const state = {
pluginInfo: (() => {
try {
console.log(window.pluginInfo);
return window.pluginInfo || {}
return window.pluginInfo || {};
} catch (e) {}
})(),
}
})()
};
const mutations = {
commonUpdate (state, payload) {
commonUpdate(state, payload) {
Object.keys(payload).forEach((key) => {
state[key] = payload[key];
if (key === 'devPlugins') {
sysFile.savePlugins(payload[key])
sysFile.savePlugins(payload[key]);
}
});
},
@ -43,16 +43,16 @@ const mutations = {
state.subPlaceHolder = payload;
},
deleteDevPlugin(state, payload) {
state.devPlugins = state.devPlugins.filter(plugin => plugin.name !== payload.name);
state.devPlugins = state.devPlugins.filter((plugin) => plugin.name !== payload.name);
sysFile.savePlugins(state.devPlugins);
},
deleteProdPlugin(state, payload) {
state.devPlugins = state.devPlugins.filter(plugin => plugin.id !== payload.id);
state.devPlugins = state.devPlugins.filter((plugin) => plugin.id !== payload.id);
sysFile.savePlugins(state.devPlugins);
// todo 删除 static 目录下的对应插件
},
devPluginStatusChange(state, payload) {
state.devPlugins.forEach(plugin => {
state.devPlugins.forEach((plugin) => {
if (plugin.name === payload.name) {
plugin.status = !plugin.status;
}
@ -60,12 +60,12 @@ const mutations = {
state.devPlugins = [...state.devPlugins];
sysFile.savePlugins(state.devPlugins);
}
}
};
const actions = {
showMainUI ({ commit, state }, paylpad) {
showMainUI({ commit, state }, paylpad) {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
height: getWindowHeight()
});
setTimeout(() => {
commit('commonUpdate', {
@ -81,34 +81,34 @@ const actions = {
const config = JSON.parse(fs.readFileSync(path.join(payload.sourceFile, '../plugin.json'), 'utf-8'));
const pluginConfig = {
...config,
sourceFile: path.join(payload.sourceFile, `../${config.main}`),
sourceFile: path.join(payload.sourceFile, `../${config.main}`)
};
const devPlugins = [...state.devPlugins];
commit('commonUpdate', {
devPlugins: devPlugins.map(plugin => {
devPlugins: devPlugins.map((plugin) => {
if (plugin.name === payload.name) {
return {
...plugin,
...pluginConfig,
}
...pluginConfig
};
}
return plugin;
})
})
});
},
async onSearch ({ commit }, paylpad) {
async onSearch({ commit }, paylpad) {
if (state.selected && state.selected.key !== 'plugin-container') {
commit('commonUpdate', {searchValue: ''});
commit('commonUpdate', { searchValue: '' });
return;
}
const value = paylpad.value;
// 在插件界面不触发其他功能
if((state.selected && state.selected.key === 'plugin-container') || paylpad.searchType === 'subWindow') {
commit('commonUpdate', {searchValue: value});
if ((state.selected && state.selected.key === 'plugin-container') || paylpad.searchType === 'subWindow') {
commit('commonUpdate', { searchValue: value });
return;
}
const fileUrl = clipboard.read('public.file-url').replace('file://', '');
commit('commonUpdate', {searchValue: value})
commit('commonUpdate', { searchValue: value });
// 复制文件
if (fileUrl && value === 'plugin.json') {
const config = JSON.parse(fs.readFileSync(fileUrl, 'utf-8'));
@ -121,7 +121,7 @@ const actions = {
icon: 'image://' + path.join(fileUrl, `../${config.logo}`),
subType: (() => {
if (config.main) {
return ''
return '';
}
return 'template';
})()
@ -146,12 +146,12 @@ const actions = {
key: 'plugin',
name: '新建rubick开发插件'
},
current: ['dev'],
current: ['dev']
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
height: getWindowHeight()
});
router.push('/home/dev')
router.push('/home/dev');
}
},
{
@ -164,10 +164,10 @@ const actions = {
commit('commonUpdate', {
showMain: false,
selected: null,
options: [],
options: []
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([]),
height: getWindowHeight([])
});
remote.Notification('Rubick 通知', { body: '复制成功' });
}
@ -176,9 +176,9 @@ const actions = {
});
// 调整窗口大小
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options),
height: getWindowHeight(state.options)
});
return
return;
}
let options = [];
@ -189,7 +189,7 @@ const actions = {
// dev 插件未开启
if (plugin.type === 'dev' && !plugin.status) return;
const feature = plugin.features;
feature.forEach(fe => {
feature.forEach((fe) => {
const cmds = searchKeyValues(fe.cmds, value);
options = [
...options,
@ -200,31 +200,44 @@ const actions = {
desc: fe.explain,
type: plugin.type,
click: (router) => {
actions.openPlugin({commit}, {cmd, plugin, feature: fe, router});
actions.openPlugin({ commit }, { cmd, plugin, feature: fe, router });
}
}))
]
})
];
});
});
let descMap = new Map();
options = [
...options,
...(fileLists.filter(plugin => plugin.name.indexOf(value) >= 0)).map(plugin => {
plugin.click = () => {
actions.openPlugin({commit}, {plugin});
}
return plugin
}),
]
...fileLists
.filter((plugin) => {
if (!descMap.get(plugin)) {
descMap.set(plugin, true);
return plugin.keyWord.toLocaleUpperCase().indexOf(value.toLocaleUpperCase()) >= 0;
} else {
return false;
}
})
.map((plugin) => {
plugin.click = () => {
actions.openPlugin({ commit }, { plugin });
};
return plugin;
})
];
descMap = null;
}
commit('commonUpdate', {
options
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options),
height: getWindowHeight(state.options)
});
},
async downloadPlugin({commit}, payload) {
async downloadPlugin({ commit }, payload) {
const distUrl = await downloadZip(payload.downloadUrl, payload.name);
const fileUrl = find(distUrl);
@ -238,26 +251,26 @@ const actions = {
icon: payload.logo,
subType: (() => {
if (config.main) {
return ''
return '';
}
return 'template';
})()
};
commit('commonUpdate', {
devPlugins: [pluginConfig, ...state.devPlugins],
devPlugins: [pluginConfig, ...state.devPlugins]
});
},
openPlugin({commit}, {cmd, plugin, feature, router, payload}) {
openPlugin({ commit }, { cmd, plugin, feature, router, payload }) {
if (plugin.type === 'app') {
execSync(plugin.action);
commit('commonUpdate', {
selected: null,
showMain: false,
options: [],
searchValue: '',
searchValue: ''
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([]),
height: getWindowHeight([])
});
return;
}
@ -265,26 +278,26 @@ const actions = {
selected: {
key: 'plugin-container',
name: cmd.label ? cmd.label : cmd,
icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`),
icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`)
},
searchValue: '',
showMain: true
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
height: getWindowHeight()
});
if (plugin.type === 'system') {
systemMethod[plugin.tag][feature.code]()
systemMethod[plugin.tag][feature.code]();
commit('commonUpdate', {
selected: null,
showMain: false,
options: [],
options: []
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([]),
height: getWindowHeight([])
});
router.push({
path: '/home',
path: '/home'
});
return;
}
@ -293,7 +306,7 @@ const actions = {
cmd,
...plugin,
detail: feature,
payload,
payload
}
});
@ -303,14 +316,14 @@ const actions = {
...plugin,
_modify: Date.now(),
detail: JSON.stringify(feature)
},
})
}
});
}
}
};
export default {
namespaced: true,
state,
mutations,
actions
}
};