Compare commits

...

5 Commits

Author SHA1 Message Date
muwoo
9242f17cde ref: 优化window读取系统应用 2021-09-09 11:44:17 +08:00
muwoo
d047119076 ref: 优化window读取系统应用icon展示 2021-09-09 11:21:19 +08:00
muwoo
5118fa6ca4 ref: 优化window读取系统应用,增加自动更新提示 2021-09-08 20:46:38 +08:00
muwoo
424c40a99c bugfix: #44,支持windows应用图标展示 2021-09-07 16:58:04 +08:00
muwoo
651e202ab1 bugfix: windows 搜索图标有问题 2021-09-06 20:37:38 +08:00
5 changed files with 85 additions and 83 deletions

View File

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

View File

@@ -14,7 +14,7 @@ module.exports = () => {
win = new BrowserWindow({
height: 60,
useContentSize: true,
resizable: false,
resizable: true,
width: 800,
frame: false,
title: '拉比克',

View File

@@ -5,7 +5,7 @@ import pkg from '../../../package.json';
const os = require('os');
const version = pkg.version;
const releaseUrl = 'http://rubick-server.qa.91jkys.com/release/query';
const releaseUrl = 'http://118.195.176.247:8080/release/query';
export async function autoUpdate() {
let res;

View File

@@ -1,10 +1,12 @@
import { app, globalShortcut } from 'electron'
import '../renderer/store'
import init from './common/common'
import { autoUpdate } from './common/autoUpdate'
import createTray from './tray'
import { commonConst } from './common/utils'
import pkg from '../../package.json'
import Store from 'electron-store';
Store.initRenderer()
const { main } = require("./browsers")()
@@ -106,4 +108,4 @@ class initApp {
}
}
(new initApp()).launchApp()
(new initApp()).launchApp()

View File

@@ -1,93 +1,93 @@
import path from "path";
import fs from 'fs';
import path from 'path';
import os from 'os';
import child from 'child_process';
import iconv from 'iconv-lite';
import translate from "./translate";
import translate from './translate';
import {shell} from 'electron';
const fileIcon = require('extract-file-icon');
const filePath = path.resolve('C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs');
const fileLists = [];
const isZhRegex = /[\u4e00-\u9fa5]/;
const getico = apps =>{
const iconExtractor = require('icon-extractor');
const icondir = path.join(os.tmpdir(), 'ProcessIcon');
const exists = fs.existsSync(icondir);
if (!exists) { fs.mkdirSync(icondir) }
iconExtractor.emitter.on('icon', function (data) {
apps[data.Context].icon = 'data:image/png;base64,' + data.Base64ImageData;
});
const getico = app =>{
try {
const buffer = fileIcon(app.desc, 32);
const iconpath = path.join(icondir, `${app.name}.png`);
apps.forEach((app, i) => {
iconExtractor.getIcon(i, app.desc);
});
fs.exists(iconpath, exists => {
if (!exists) {
fs.writeFile(iconpath, buffer, 'base64', () => {});
}
});
} catch(e) {
console.log(e, app.desc);
}
}
const powershell = (cmd, callback) => {
const ps = child.spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' })
let chunks = [];
let err_chunks = [];
ps.stdout.on('data', chunk => {
chunks.push(iconv.decode(chunk, 'cp936'))
})
ps.stderr.on('data', err_chunk => {
err_chunks.push(iconv.decode(err_chunk, 'cp936'))
})
ps.on('close', code => {
let stdout = chunks.join("");
let stderr = err_chunks.join("");
callback(stdout, stderr)
})
}
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];
const appDetail = shell.readShortcutLink(filedir);
if (!appDetail.target) return;
const getWinAppList = () => {
let filterValues = "Select-Object DisplayName,DisplayIcon,UninstallString,DisplayVersion,InstallDate,Publisher,InstallLocation"
let localMatcine = `Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | ${filterValues}`;
let currentUser = `Get-ItemProperty HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | ${filterValues}`;
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 apps = stdout.trim().replace(/\r\n[ ]{10,}/g,"").split('\r\n\r\n');
for (const app of apps) {
const dict = {}
let lines = app.split('\r\n')
for (var line of lines) {
if (line) {
const key = line.split(/\s+:\s*/)[0];
const value = line.split(/\s+:\s*/)[1];
dict[key] = value;
}
}
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 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(''));
}
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);
}
fileLists.push({
...dict,
value: 'plugin',
icon: dict.Icon,
desc: appPath,
type: 'app',
action: `start "dummyclient" "${appPath}"`,
keyWords: keyWords,
name: dict.DisplayName,
names: JSON.parse(JSON.stringify(keyWords)),
});
}
getico(fileLists);
const icon = path.join(os.tmpdir(), 'ProcessIcon', `${encodeURIComponent(appName)}.png`);
const appInfo = {
value: 'plugin',
desc: appDetail.target,
type: 'app',
icon,
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 const getApp = {
init: getWinAppList,
fileLists,
};
init: () => fileDisplay(filePath),
fileLists
}