bugfix: 修复 windows 搜索系统应用报错问题

This commit is contained in:
muwoo 2021-09-06 11:32:02 +08:00
parent a04efd0d4f
commit f287d10ca9
2 changed files with 5 additions and 32 deletions

View File

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

View File

@ -1,4 +1,3 @@
import fs from "fs";
import path from "path"; import path from "path";
import os from 'os'; import os from 'os';
import child from 'child_process'; import child from 'child_process';
@ -6,31 +5,6 @@ import iconv from 'iconv-lite';
const fileLists = []; const fileLists = [];
const getico = apps =>{
const iconExtractor = require('icon-extractor');
iconExtractor.emitter.on('icon', function (data) {
let icondir = path.join(os.tmpdir(), 'ProcessIcon')
fs.exists(icondir, exists => {
if (!exists) { fs.mkdirSync(icondir) }
let iconpath = path.join(icondir, `${data.Context}.png`)
fs.exists(iconpath, exists => {
if (!exists) {
fs.writeFile(iconpath, data.Base64ImageData, "base64", err => {
if (err) { console.log(err); }
});
}
})
})
});
for (var app of apps) {
if (app.DisplayIcon !== undefined) {
app.DisplayIcon = app.DisplayIcon.split(',')[0];
}
iconExtractor.getIcon(app.LegalName, app.DisplayIcon);
}
}
const powershell = (cmd, callback) => { const powershell = (cmd, callback) => {
const ps = child.spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' }) const ps = child.spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' })
let chunks = []; let chunks = [];
@ -60,7 +34,7 @@ const getWinAppList = () => {
for (var app of apps) { for (var app of apps) {
const dict = {} const dict = {}
let lines = app.split('\r\n') let lines = app.split('\r\n')
for (const line of lines) { for (var line of lines) {
if (line) { if (line) {
const key = line.split(/\s+:\s*/)[0]; const key = line.split(/\s+:\s*/)[0];
const value = line.split(/\s+:\s*/)[1]; const value = line.split(/\s+:\s*/)[1];
@ -70,20 +44,20 @@ const getWinAppList = () => {
if (dict.DisplayName && dict.DisplayIcon && dict.DisplayIcon.indexOf('.exe') >= 0) { if (dict.DisplayName && dict.DisplayIcon && dict.DisplayIcon.indexOf('.exe') >= 0) {
dict.LegalName = dict.DisplayName.replace(/[\\\/\:\*\?\"\<\>\|]/g, ""); dict.LegalName = dict.DisplayName.replace(/[\\\/\:\*\?\"\<\>\|]/g, "");
dict.Icon = path.join(os.tmpdir(), 'ProcessIcon', `${encodeURIComponent(dict.LegalName)}.png`); dict.Icon = path.join(os.tmpdir(), 'ProcessIcon', `${encodeURIComponent(dict.LegalName)}.png`);
const appPath = dict.DisplayIcon.split(',')[0];
fileLists.push({ fileLists.push({
...dict, ...dict,
value: 'plugin', value: 'plugin',
icon: dict.Icon, icon: dict.Icon,
desc: dict.DisplayIcon, desc: appPath,
type: 'app', type: 'app',
action: `start "dummyclient" "${dict.DisplayIcon}"`, action: `start "dummyclient" "${appPath}"`,
keyWords: [dict.DisplayName], keyWords: [dict.DisplayName],
name: dict.DisplayName, name: dict.DisplayName,
names: [dict.DisplayName], names: [dict.DisplayName],
}); });
} }
} }
getico(fileLists);
}); });
} }