Compare commits

...

6 Commits

6 changed files with 87 additions and 91 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "rubick2",
"version": "0.0.3-beta.10",
"version": "0.0.4",
"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

@@ -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

@@ -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,87 @@
import fs from "fs";
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 {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');
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); }
});
}
})
})
});
const icondir = path.join(os.tmpdir(), 'ProcessIcon');
const exists = fs.existsSync(icondir);
if (!exists) { fs.mkdirSync(icondir) }
for (var app of apps) {
if (app.DisplayIcon !== undefined) {
app.DisplayIcon = app.DisplayIcon.split(',')[0];
}
iconExtractor.getIcon(app.LegalName, app.DisplayIcon);
const getico = app =>{
try {
const buffer = fileIcon(app.desc, 32);
const iconpath = path.join(icondir, `${app.name}.png`);
fs.writeFileSync(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 applist = [];
let apps = stdout.trim().replace(/\r\n[ ]{10,}/g,"").split('\r\n\r\n');
for (var app of apps) {
const dict = {}
let lines = app.split('\r\n')
for (const 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`);
fileLists.push({
...dict,
value: 'plugin',
icon: dict.Icon,
desc: dict.DisplayIcon,
type: 'app',
action: `start "dummyclient" "${dict.DisplayIcon}"`,
keyWords: [dict.DisplayName],
name: dict.DisplayName,
names: [dict.DisplayName],
});
}
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,
action: `start "dummyclient" "${appDetail.target}"`,
keyWords: keyWords,
name: appName,
names: JSON.parse(JSON.stringify(keyWords)),
}
fileLists.push(appInfo);
getico(appInfo);
}
if(isDir) {
fileDisplay(filedir); // 递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
}
})
});
}
getico(fileLists);
});
}
export const getApp = {
init: getWinAppList,
fileLists,
};
init: () => fileDisplay(filePath),
fileLists
}