From 614d5ae36953a0957baa9333a7713a2b82be9402 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Mon, 6 Sep 2021 14:58:18 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20#42;=20ref:=20=E6=94=AF=E6=8C=81windo?= =?UTF-8?q?ws=E6=8B=BC=E9=9F=B3=E6=90=9C=E7=B4=A2=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/main/common/config.js | 12 ++++----- src/renderer/assets/common/win-app.js | 36 +++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 11376b4..03e970b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main/common/config.js b/src/main/common/config.js index a844b8c..d3d91ea 100644 --- a/src/main/common/config.js +++ b/src/main/common/config.js @@ -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)) } } diff --git a/src/renderer/assets/common/win-app.js b/src/renderer/assets/common/win-app.js index bbce28a..0e5476a 100644 --- a/src/renderer/assets/common/win-app.js +++ b/src/renderer/assets/common/win-app.js @@ -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); } }); }