bugfix: #42; ref: 支持windows拼音搜索系统应用

This commit is contained in:
muwoo 2021-09-06 14:58:18 +08:00
parent f287d10ca9
commit 614d5ae369
3 changed files with 39 additions and 12 deletions

View File

@ -1,6 +1,6 @@
{
"name": "rubick2",
"version": "0.0.3-beta.11",
"version": "0.0.3-beta.12",
"author": "muwoo <2424880409@qq.com>",
"description": "An electron-vue project",
"license": null,
@ -69,6 +69,7 @@
"download-git-repo": "^3.0.2",
"electron-is-dev": "^2.0.0",
"electron-store": "^8.0.0",
"icon-extractor": "^1.0.3",
"iohook": "^0.9.3",
"is-chinese": "^1.4.2",
"jian-pinyin": "^0.2.3",

View File

@ -7,7 +7,7 @@ const configPath = path.join(getlocalDataFile(), './rubick-config.json')
let defaultConfig = {
Darwin: {
version: 2,
version: 3,
perf: {
shortCut: {
showAndHidden: 'Option+R',
@ -32,7 +32,7 @@ let defaultConfig = {
global: []
},
Windows_NT: {
version: 2,
version: 3,
perf: {
shortCut: {
showAndHidden: 'Option+R',
@ -57,7 +57,7 @@ let defaultConfig = {
global: []
},
Linux: {
version: 1,
version: 3,
perf: {
shortCut: {
showAndHidden: 'Option+R',
@ -85,13 +85,13 @@ let defaultConfig = {
global.opConfig = {
config: null,
get() {
const platform = os.type()
const platform = os.type();
try {
if (!opConfig.config) {
opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform]))
}
// 重置
if (!opConfig.version || opConfig.version < defaultConfig[platform].version) {
if (!opConfig.config.version || opConfig.config.version < defaultConfig[platform].version) {
opConfig.config = defaultConfig[platform]
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
}
@ -102,7 +102,7 @@ global.opConfig = {
}
},
set(key, value) {
opConfig.config[key] = value
opConfig.config[key] = value;
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
}
}

View File

@ -2,8 +2,22 @@ import path from "path";
import os from 'os';
import child from 'child_process';
import iconv from 'iconv-lite';
import translate from "./translate";
const fileLists = [];
const isZhRegex = /[\u4e00-\u9fa5]/;
const getico = apps =>{
const iconExtractor = require('icon-extractor');
iconExtractor.emitter.on('icon', function (data) {
apps[data.Context].icon = 'data:image/png;base64,' + data.Base64ImageData;
});
apps.forEach((app, i) => {
iconExtractor.getIcon(i, app.desc);
});
}
const powershell = (cmd, callback) => {
const ps = child.spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' })
@ -29,9 +43,8 @@ const getWinAppList = () => {
let Wow6432Node = `Get-ItemProperty HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | ${filterValues}`;
let x64 = process.arch === 'x64' ? `;${Wow6432Node}` : '';
powershell(`${localMatcine};${currentUser}${x64}`, (stdout, stderr) => {
let applist = [];
let apps = stdout.trim().replace(/\r\n[ ]{10,}/g,"").split('\r\n\r\n');
for (var app of apps) {
for (const app of apps) {
const dict = {}
let lines = app.split('\r\n')
for (var line of lines) {
@ -44,7 +57,19 @@ const getWinAppList = () => {
if (dict.DisplayName && dict.DisplayIcon && dict.DisplayIcon.indexOf('.exe') >= 0) {
dict.LegalName = dict.DisplayName.replace(/[\\\/\:\*\?\"\<\>\|]/g, "");
dict.Icon = path.join(os.tmpdir(), 'ProcessIcon', `${encodeURIComponent(dict.LegalName)}.png`);
const appPath = dict.DisplayIcon.split(',')[0];
const firstLatter = dict.DisplayName.split(' ').map(name => name[0]).join('');
const appPath = dict.DisplayIcon.split(',')[0].replace(/"/g, '');
const keyWords = [dict.DisplayName, firstLatter];
if (isZhRegex.test(dict.DisplayName)) {
const py = translate(dict.DisplayName);
const pinyinArr = py.split(',');
const zh_firstLatter = pinyinArr.map(py => py[0]);
// 拼音
keyWords.push(pinyinArr.join(''));
// 缩写
keyWords.push(zh_firstLatter.join(''));
}
fileLists.push({
...dict,
value: 'plugin',
@ -52,11 +77,12 @@ const getWinAppList = () => {
desc: appPath,
type: 'app',
action: `start "dummyclient" "${appPath}"`,
keyWords: [dict.DisplayName],
keyWords: keyWords,
name: dict.DisplayName,
names: [dict.DisplayName],
names: JSON.parse(JSON.stringify(keyWords)),
});
}
getico(fileLists);
}
});
}