mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-12 22:44:05 +08:00
feat: suport windows search app
This commit is contained in:
parent
2cd6bab58c
commit
5cfaa70c67
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rubick",
|
"name": "rubick",
|
||||||
"version": "2.0.1-beta.5",
|
"version": "2.0.1-beta.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
@ -19,6 +19,7 @@
|
|||||||
"ant-design-vue": "^2.2.8",
|
"ant-design-vue": "^2.2.8",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
|
"extract-file-icon": "^0.3.2",
|
||||||
"fix-path": "^3.0.0",
|
"fix-path": "^3.0.0",
|
||||||
"get-mac-apps": "^1.0.2",
|
"get-mac-apps": "^1.0.2",
|
||||||
"got": "^11.8.3",
|
"got": "^11.8.3",
|
||||||
|
@ -1,3 +1,105 @@
|
|||||||
export default () => {
|
import fs from "fs";
|
||||||
// todo win search
|
import path from "path";
|
||||||
|
import os from "os";
|
||||||
|
import translate from "./translate";
|
||||||
|
import { shell } from "electron";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
const fileIcon = require("extract-file-icon");
|
||||||
|
const filePath = path.resolve("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs");
|
||||||
|
|
||||||
|
const fileLists: any = [];
|
||||||
|
const isZhRegex = /[\u4e00-\u9fa5]/;
|
||||||
|
|
||||||
|
const icondir = path.join(os.tmpdir(), "ProcessIcon");
|
||||||
|
const exists = fs.existsSync(icondir);
|
||||||
|
if (!exists) {
|
||||||
|
fs.mkdirSync(icondir);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getico = app => {
|
||||||
|
try {
|
||||||
|
const buffer = fileIcon(app.desc, 32);
|
||||||
|
const iconpath = path.join(icondir, `${app.name}.png`);
|
||||||
|
|
||||||
|
fs.exists(iconpath, exists => {
|
||||||
|
if (!exists) {
|
||||||
|
fs.writeFile(iconpath, buffer, "base64", () => {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e, app.desc);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function fileDisplay(filePath) {
|
||||||
|
//根据文件路径读取文件,返回文件列表
|
||||||
|
fs.readdir(filePath, function(err, files) {
|
||||||
|
if (err) {
|
||||||
|
console.warn(err);
|
||||||
|
} else {
|
||||||
|
files.forEach(function(filename) {
|
||||||
|
const filedir = path.join(filePath, filename);
|
||||||
|
fs.stat(filedir, function(eror, stats) {
|
||||||
|
if (eror) {
|
||||||
|
console.warn("获取文件stats失败");
|
||||||
|
} else {
|
||||||
|
const isFile = stats.isFile(); // 是文件
|
||||||
|
const isDir = stats.isDirectory(); // 是文件夹
|
||||||
|
if (isFile) {
|
||||||
|
const appName = filename.split(".")[0];
|
||||||
|
const keyWords = [appName];
|
||||||
|
let appDetail: any = {};
|
||||||
|
try {
|
||||||
|
appDetail = shell.readShortcutLink(filedir)
|
||||||
|
} catch(e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
if (!appDetail.target || appDetail.target.toLowerCase().indexOf("unin") >= 0) return;
|
||||||
|
|
||||||
|
if (isZhRegex.test(appName)) {
|
||||||
|
const py = translate(appName);
|
||||||
|
const pinyinArr = py.split(",");
|
||||||
|
const zh_firstLatter = pinyinArr.map(py => py[0]);
|
||||||
|
// 拼音
|
||||||
|
keyWords.push(pinyinArr.join(""));
|
||||||
|
// 缩写
|
||||||
|
keyWords.push(zh_firstLatter.join(""));
|
||||||
|
} else {
|
||||||
|
const firstLatter = appName.split(" ").map(name => name[0]).join("");
|
||||||
|
keyWords.push(firstLatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
const icon = path.join(os.tmpdir(), "ProcessIcon", `${encodeURIComponent(appName)}.png`);
|
||||||
|
|
||||||
|
const appInfo = {
|
||||||
|
value: "plugin",
|
||||||
|
desc: appDetail.target,
|
||||||
|
type: "app",
|
||||||
|
icon,
|
||||||
|
pluginType: "app",
|
||||||
|
action: `start "dummyclient" "${appDetail.target}"`,
|
||||||
|
keyWords: keyWords,
|
||||||
|
name: appName,
|
||||||
|
names: JSON.parse(JSON.stringify(keyWords))
|
||||||
|
};
|
||||||
|
fileLists.push(appInfo);
|
||||||
|
getico(appInfo);
|
||||||
|
}
|
||||||
|
if (isDir) {
|
||||||
|
fileDisplay(filedir); // 递归,如果是文件夹,就继续遍历该文件夹下面的文件
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
fileDisplay(filePath);
|
||||||
|
return fileLists;
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,8 @@ module.exports = {
|
|||||||
mainProcessFile: "src/main/index.ts",
|
mainProcessFile: "src/main/index.ts",
|
||||||
mainProcessWatch: ["src/main"],
|
mainProcessWatch: ["src/main"],
|
||||||
externals: [
|
externals: [
|
||||||
'pouchdb'
|
'pouchdb',
|
||||||
|
'extract-file-icon'
|
||||||
],
|
],
|
||||||
// Use this to change the entry point of your app's render process. default src/[main|index].[js|ts]
|
// Use this to change the entry point of your app's render process. default src/[main|index].[js|ts]
|
||||||
builderOptions: {
|
builderOptions: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user