Compare commits

...

16 Commits

Author SHA1 Message Date
muwoo
1c893542b9 bugfix: 修复windows下读取插件preload.js位置问题;
ref:搜索插件不区分大消息
2021-09-22 15:38:52 +08:00
木偶
e9fa7b2276 Merge pull request #47 from bijiwiki-community/dev-tcsnzh
使搜索框在存在输入内容时mousedown不会造成拖动
2021-09-21 11:05:11 +08:00
tcsnzh
db12d66ff7 适配Linux Gnome的复制plugin.json文件的功能。修复粘贴plugin.json受定时器影响不跳出按钮、搜索栏为空时退格路由报错两个Bug 2021-09-20 23:37:13 +08:00
tcsnzh
9d3e7fc4a5 使搜索框在存在输入内容时mousedown不会造成拖动 2021-09-20 18:56:16 +08:00
muwoo
be21302738 docs: update readme 2021-09-17 17:21:35 +08:00
muwoo
a535c5d89b feat:增加request功能 2021-09-17 16:23:51 +08:00
muwoo
1eeb0fad9a bugfix: #45, #40 2021-09-16 20:27:55 +08:00
muwoo
511b357e28 ref: 优化window读取系统应用 2021-09-13 17:25:45 +08:00
muwoo
87e7501c0a ref: bugfix windows rm 命令无法执行 2021-09-13 17:24:51 +08:00
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
muwoo
614d5ae369 bugfix: #42; ref: 支持windows拼音搜索系统应用 2021-09-06 14:58:18 +08:00
muwoo
f287d10ca9 bugfix: 修复 windows 搜索系统应用报错问题 2021-09-06 11:32:02 +08:00
15 changed files with 493 additions and 365 deletions

11
.gitignore vendored
View File

@@ -1,12 +1,21 @@
.DS_Store
dist/
dist/electron/*
dist/web/*
build/*
!build/icons/
node_modules/
npm-debug.log
npm-debug.log.*
.pnpm-debug.log
thumbs.db
!.gitkeep
.idea
dist/
.vscode

View File

@@ -1,5 +0,0 @@
{
"0 debug pnpm:scope": {
"selected": 1
}
}

View File

@@ -16,8 +16,12 @@
<a href="https://github.com/clouDr-f2e/rubick/blob/master/LICENSE">
<img alt="npm" src="https://img.shields.io/github/license/clouDr-f2e/rubick" />
</a>
<img alt="star" src="https://img.shields.io/github/stars/clouDr-f2e/rubick?style=social"></a>
<a href="https://github.com/clouDr-f2e/rubick/stargazers">
<img alt="star" src="https://img.shields.io/github/stars/clouDr-f2e/rubick?style=social">
</a>
<a href="https://gitee.com/monkeyWang/rubick">
<img alt="码云" src="https://img.shields.io/badge/Gitee--yellow.svg?style=social&logo=data:image/svg+xml;base64,PHN2ZyB0PSIxNTc0ODM3MTM4ODM3IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE3NzAiICAgICB3aWR0aD0iMTYiIGhlaWdodD0iMTYiPiAgICA8cGF0aCBkPSJNODkxIDQyOC44SDQ2NS44Yy0yMC40IDAtMzcgMTYuNS0zNyAzN3Y5Mi40YzAgMjAuNCAxNi41IDM3IDM3IDM3aDI1OC45YzIwLjQgMCAzNyAxNi42IDM3IDM3djE4LjRjMCA2MS4zLTQ5LjcgMTEwLjktMTEwLjkgMTEwLjlIMjk5LjRjLTIwLjQgMC0zNy0xNi42LTM3LTM3VjM3My4yYzAtNjEuMyA0OS43LTExMC45IDExMC45LTExMC45aDUxNy42YzIwLjQgMCAzNy0xNi41IDM3LTM3bDAuMS05Mi4zYzAtMjAuNC0xNi41LTM3LTM3LTM3SDM3My4zQzIyMC4yIDk2IDk2IDIyMC4yIDk2IDM3My4zVjg5MWMwIDIwLjQgMTYuNiAzNyAzNyAzN2g1NDUuNEM4MTYuMiA5MjggOTI4IDgxNi4zIDkyOCA2NzguNFY0NjUuOGMwLTIwLjQtMTYuNi0zNy0zNy0zN3oiICAgICAgICAgIGZpbGw9IiNkODFlMDYiIHAtaWQ9IjE3NzEiPjwvcGF0aD48L3N2Zz4="/>
</a>
</div>

View File

@@ -1,6 +1,6 @@
{
"name": "rubick2",
"version": "0.0.3-beta.10",
"version": "0.0.7-beta.2",
"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",
@@ -85,6 +85,7 @@
"request-promise": "^4.2.6",
"robotjs": "git+https://github.com/Toinane/robotjs.git",
"semver": "^7.3.5",
"shelljs": "^0.8.4",
"sudo-prompt": "^9.2.1",
"systeminformation": "^5.8.0",
"unzip": "^0.1.11",

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,4 +1,14 @@
import {app, nativeImage, BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen, TouchBar} from "electron";
import {
app,
nativeImage,
BrowserWindow,
clipboard,
globalShortcut,
ipcMain,
Notification,
screen,
TouchBar
} from 'electron';
import {exec, spawn} from "child_process";
import robot from "robotjs";
import Api from "./api";
@@ -54,7 +64,7 @@ class Listener {
// 注册偏好快捷键
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
const {x, y} = screen.getCursorScreenPoint();
const currentDisplay = screen.getDisplayNearestPoint({ x, y });
const currentDisplay = screen.getDisplayNearestPoint({x, y});
const wx = parseInt(currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400);
const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200);
@@ -86,7 +96,7 @@ class Listener {
init(mainWindow) {
this.fn = throttle(({x, y}, picker) => {
const { scaleFactor } = screen.getDisplayNearestPoint({x, y});
const {scaleFactor} = screen.getDisplayNearestPoint({x, y});
const img = robot.screen.capture(
x - parseInt(5 / scaleFactor),
y - parseInt(5 / scaleFactor),
@@ -96,7 +106,7 @@ class Listener {
const colors = {}
for(let i = 0; i< 9; i++) {
for (let i = 0; i < 9; i++) {
colors[i] = {};
for (let j = 0; j < 9; j++) {
colors[i][j] = img.colorAt(j, i);
@@ -142,7 +152,7 @@ class Listener {
const colors = {}
for(let i = 0; i< 9; i++) {
for (let i = 0; i < 9; i++) {
colors[i] = {};
for (let j = 0; j < 9; j++) {
colors[i][j] = img.colorAt(j, i);
@@ -173,7 +183,7 @@ class Listener {
let y = e.y
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
new Notification({title: 'Rubick 通知', body: `${color} 已保存到剪切板`}).show();
this.closePicker();
}
});
@@ -195,7 +205,7 @@ class Listener {
initTouchBar(mainWindow) {
if (!commonConst.macOS()) return;
const { TouchBarButton, TouchBarGroup, TouchBarPopover } = TouchBar;
const {TouchBarButton, TouchBarGroup, TouchBarPopover} = TouchBar;
let items = [];
let system = [];
ipcMain.on('pluginInit', (e, args) => {
@@ -218,7 +228,7 @@ class Listener {
}).filter(Boolean);
system = args.plugins.map((item) => {
if(item.type === 'system') {
if (item.type === 'system') {
return new TouchBarButton({
icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}),
click() {
@@ -364,6 +374,7 @@ class Listener {
windowMoveInit(win) {
let hasInit = false;
ipcMain.on('window-move', () => {
let bounds = win.getBounds();
if (!hasInit) {
hasInit = true;
ioHook.start(false);
@@ -377,8 +388,9 @@ class Listener {
const cursorPosition = screen.getCursorScreenPoint();
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
let {x, y} = {x: dx, y: dy};
win.setPosition(parseInt(x), parseInt(y));
bounds.x = parseInt(dx);
bounds.y = parseInt(dy);
win.setBounds(bounds);
});
ioHook.on('mouseup', e => {

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,6 +1,6 @@
<template>
<div @mousedown="drag" >
<a-layout id="components-layout">
<div @mousedown="drag">
<a-layout id="components-layout">
<div v-if="!searchType" class="rubick-select">
<div class="tag-container" v-if="selected">
<a-tag
@@ -16,23 +16,26 @@
<a-input
id="search"
:placeholder="
subPlaceHolder && selected && selected.key === 'plugin-container'
? subPlaceHolder
: 'Hi, Rubick'
"
subPlaceHolder && selected && selected.key === 'plugin-container'
? subPlaceHolder
: 'Hi, Rubick'
"
@mousedown.stop="dragWhenInput"
class="main-input"
@change="(e) => search({ value: e.target.value })"
@keydown.ctrl.86="shouldPaste"
:value="searchValue"
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
:maxLength="
selected && selected.key !== 'plugin-container' ? 0 : 1000
"
@keydown.down="(e) => changeCurrent(1)"
@keydown.up="() => changeCurrent(-1)"
@keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
@keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
>
<div @click="goMenu" class="suffix-tool" slot="suffix">
<a-icon
@@ -42,12 +45,14 @@
/>
<div v-if="selected && selected.icon" style="position: relative">
<a-spin v-show="pluginLoading" class="loading">
<a-icon slot="indicator" type="loading" style="font-size: 42px" spin />
<a-icon
slot="indicator"
type="loading"
style="font-size: 42px"
spin
/>
</a-spin>
<img
class="icon-tool"
:src="selected.icon"
/>
<img class="icon-tool" :src="selected.icon" />
</div>
<div v-else class="rubick-logo">
<img src="./assets/imgs/logo.png" />
@@ -87,19 +92,19 @@
:placeholder="subPlaceHolder"
class="sub-input"
@change="
(e) =>
search({
value: e.target.value,
searchType: pluginInfo.searchType,
})
"
(e) =>
search({
value: e.target.value,
searchType: pluginInfo.searchType,
})
"
:value="searchValue"
@keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
(e) => targetSearch({ value: e.target.value, type: 'enter' })
"
@keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
(e) => targetSearch({ value: e.target.value, type: 'space' })
"
></a-input>
</div>
@@ -121,6 +126,7 @@ import {
searchKeyValues,
fileLists,
} from "./assets/common/utils";
import { commonConst } from "../main/common/utils";
const opConfig = remote.getGlobal("opConfig");
const { Menu, MenuItem } = remote;
@@ -167,20 +173,21 @@ export default {
const feature = plugin.features;
feature.forEach((fe) => {
const cmd = searchKeyValues(fe.cmds, args)[0];
const systemPlugin = fileLists.filter(
(plugin) => {
let has = false;
plugin.keyWords.some(keyWord => {
if (keyWord.toLocaleUpperCase().indexOf(args.toLocaleUpperCase()) >= 0) {
has = keyWord;
plugin.name = keyWord;
return true;
}
return false;
});
return has;
}
)[0];
const systemPlugin = fileLists.filter((plugin) => {
let has = false;
plugin.keyWords.some((keyWord) => {
if (
keyWord.toLocaleUpperCase().indexOf(args.toLocaleUpperCase()) >=
0
) {
has = keyWord;
plugin.name = keyWord;
return true;
}
return false;
});
return has;
})[0];
if (cmd) {
config = {
cmd: cmd,
@@ -210,18 +217,56 @@ export default {
...mapActions("main", ["onSearch", "showMainUI", "openPlugin"]),
...mapMutations("main", ["commonUpdate"]),
shouldPaste(e) {
let filePath = '';
if (process.platform === 'win32') {
const rawFilePath = clipboard.read('FileNameW');
filePath = rawFilePath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
if (filePath.indexOf('plugin.json') >= 0) {
let filePath = "";
if (commonConst.windows()) {
const rawFilePath = clipboard.read("FileNameW");
filePath = rawFilePath.replace(
new RegExp(String.fromCharCode(0), "g"),
""
);
if (filePath.indexOf("plugin.json") >= 0) {
this.search({
filePath,
disableDebounce: true,
});
}
} else if (commonConst.linux()) {
const text = clipboard.readText("selection");
// 在gnome的文件管理器中复制文件的结果通常是
//
// x-special/nautilus-clipboard
// copy
// file:///home/admin/dir/plugin.json
const splitLF = text.split(" ");
let pathUrl;
if (
splitLF.length == 3 &&
splitLF[0] === "x-special/nautilus-clipboard" &&
splitLF[1] === "copy" &&
(pathUrl = splitLF[2]).startsWith("file://") &&
pathUrl.indexOf("plugin.json") >= 0
) {
filePath = pathUrl.slice(7);
this.search({
filePath,
disableDebounce: true,
});
}
// 其他的发行版、文件管理器尚未测试
}
},
/**
* @param {Object} v 搜索配置对象。
* 若v.disableDebounce为true则不会触发防抖动保护。
* 该值的作用是让search()方法被多个监听器同时调用时,在某些情况下无视其他监听器的防抖动保护。
* 其他属性 v.value、v.filePath 参见 src/renderer/store/modules/main.js的onSearch函数。
*/
search(v) {
console.log("search was called , param v is :", v);
if (!v.disableDebounce) {
this.onSearch(v);
return;
}
if (!this.searchFn) {
this.searchFn = debounce(this.onSearch, 200);
}
@@ -260,7 +305,7 @@ export default {
renderTitle(title) {
if (typeof title !== "string") return;
const result = title.split(this.searchValue);
const result = title.toLowerCase().split(this.searchValue.toLowerCase());
if (result && result.length > 1) {
return `<div>${result[0]}<span style="color: red">${this.searchValue}</span>${result[1]}</div>`;
} else {
@@ -288,9 +333,13 @@ export default {
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight([]),
});
this.$router.push({
path: "/home",
});
if (this.$router.history.current.fullPath !== "/home") {
// 该if是为了避免跳转到相同路由而报错。
// (之前在输入栏为空时按退格会疯狂报错)
this.$router.push({
path: "/home",
});
}
},
newWindow() {
ipcRenderer.send("new-window", {
@@ -340,8 +389,13 @@ export default {
this.changePath({ key: "market" });
},
drag() {
ipcRenderer.send('window-move');
}
ipcRenderer.send("window-move");
},
dragWhenInput(e) {
if (this.searchValue == "") {
ipcRenderer.send("window-move");
}
},
},
computed: {
...mapState("main", [
@@ -479,7 +533,7 @@ export default {
cursor: pointer;
}
.loading {
position:absolute;
position: absolute;
top: 0;
left: 0;
}

View File

@@ -1,11 +1,11 @@
import { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS } from './constans';
import path from 'path';
import fs from 'fs';
import child_process from 'child_process';
import Store from 'electron-store';
import downloadFile from 'download';
import { ipcRenderer } from 'electron';
import { getlocalDataFile } from '../../../main/common/utils';
import shell from 'shelljs';
const getApp = process.platform === 'win32' ? require('./win-app').getApp : require('./darwin-app').getApp;
@@ -24,8 +24,8 @@ function getWindowHeight(searchList) {
function searchKeyValues(lists, value) {
return lists.filter((item) => {
if (typeof item === 'string') return item.indexOf(value) >= 0;
return item.type.indexOf(value) >= 0;
if (typeof item === 'string') return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
return item.type.toLowerCase().indexOf(value.toLowerCase()) >= 0;
});
}
@@ -50,7 +50,7 @@ async function downloadZip(downloadRepoUrl, name) {
const temp_dest = `${plugin_path}/${name}`;
// 下载模板
if (await existOrNot(temp_dest)) {
await child_process.execSync(`rm -rf ${temp_dest}`);
shell.rm('-rf', temp_dest);
}
await downloadFile(downloadRepoUrl, plugin_path, { extract: true });

View File

@@ -1,93 +1,93 @@
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.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 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
}

View File

@@ -2,14 +2,19 @@
<div class="market">
<a-carousel v-if="bannerList && !!bannerList.length" arrows>
<div
slot="prevArrow"
slot-scope="props"
class="custom-slick-arrow"
style="left: 10px;zIndex: 1"
slot="prevArrow"
slot-scope="props"
class="custom-slick-arrow"
style="left: 10px;zIndex: 1"
>
<a-icon type="left-circle" />
</div>
<div slot="nextArrow" slot-scope="props" class="custom-slick-arrow" style="right: 10px">
<div
slot="nextArrow"
slot-scope="props"
class="custom-slick-arrow"
style="right: 10px"
>
<a-icon type="right-circle" />
</div>
<div v-for="banner in bannerList">
@@ -18,38 +23,49 @@
</a-carousel>
<a-divider v-if="bannerList && !!bannerList.length"></a-divider>
<h2>插件</h2>
<a-list item-layout="horizontal" style="width: 100%" :grid="{ gutter: 16, column: 2 }" :data-source="pluginList">
<a-list
item-layout="horizontal"
style="width: 100%"
:grid="{ gutter: 16, column: 2 }"
:data-source="pluginList"
>
<a-list-item slot="renderItem" slot-scope="item, index">
<a-button v-if="showButton(item)" :loading="loading[index]" type="link" slot="actions" @click="download(index, item)">
<a-icon v-show="!loading[index]" style="font-size: 20px;" type="cloud-download" />
<a-button
v-if="showButton(item)"
:loading="loading[index]"
type="link"
slot="actions"
@click="download(index, item)"
>
<a-icon
v-show="!loading[index]"
style="font-size: 20px;"
type="cloud-download"
/>
</a-button>
<a-list-item-meta
@click="showPannel(item, index)"
:description="item.description"
@click="showPannel(item, index)"
:description="item.description"
>
<div slot="title">{{ item.pluginName }}</div>
<a-avatar
slot="avatar"
:src="item.logo"
/>
<a-avatar slot="avatar" :src="item.logo" />
</a-list-item-meta>
</a-list-item>
</a-list>
<a-drawer
placement="right"
:visible="show"
@close="show=false"
@close="show = false"
width="100%"
>
<div class="plugin-market-desc" slot="title">
<img width="80" :src="currentSelect.logo"/>
<img width="80" :src="currentSelect.logo" />
<div class="desc">
<h4>{{currentSelect.pluginName}}</h4>
<h4>{{ currentSelect.pluginName }}</h4>
<div class="info">
<div class="actor">
开发者{{currentSelect.author}}
开发者{{ currentSelect.author }}
<a-button
v-if="showButton(currentSelect)"
:loading="loading[currentSelect.index]"
@@ -60,7 +76,7 @@
获取
</a-button>
</div>
<div>{{currentSelect.description}}</div>
<div>{{ currentSelect.description }}</div>
</div>
</div>
</div>
@@ -70,10 +86,10 @@
</template>
<script>
import api from '../../../assets/api';
import {mapActions, mapState} from 'vuex';
import api from "../../../assets/api";
import { mapActions, mapState } from "vuex";
import marked from "marked";
import {shell} from "electron";
import { shell } from "electron";
const rendererMD = new marked.Renderer();
export default {
@@ -83,8 +99,8 @@ export default {
loading: {},
bannerList: [],
show: false,
currentSelect: {}
}
currentSelect: {},
};
},
async created() {
const [result, bannerRes] = await Promise.all([
@@ -93,7 +109,7 @@ export default {
]);
this.pluginList = result.result;
this.bannerList = bannerRes.result;
console.log(bannerRes)
console.log(bannerRes);
},
methods: {
@@ -108,7 +124,9 @@ export default {
this.$set(this.loading, index, false);
},
showButton(item) {
return !this.devPlugins.filter(plugin => (plugin.name === item.name && plugin.type === 'prod')).length;
return !this.devPlugins.filter(
(plugin) => plugin.name === item.name && plugin.type === "prod"
).length;
},
showPannel(item, index) {
this.show = true;
@@ -117,13 +135,13 @@ export default {
},
jumpTo(link) {
if (link) {
shell.openExternal(link)
shell.openExternal(link);
}
},
...mapActions('main', ['downloadPlugin'])
...mapActions("main", ["downloadPlugin"]),
},
computed: {
...mapState('main', ['devPlugins']),
...mapState("main", ["devPlugins"]),
readme() {
marked.setOptions({
renderer: rendererMD,
@@ -133,17 +151,16 @@ export default {
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
smartypants: false,
});
try {
return marked(this.currentSelect.detail);
} catch (e) {
return '暂无描述信息'
return "暂无描述信息";
}
}
}
}
},
},
};
</script>
<style lang="less">
@@ -177,49 +194,48 @@ export default {
justify-content: space-between;
}
}
.market {
height: calc(~'100vh - 110px');
background: #fff;
padding: 20px;
box-sizing: border-box;
overflow: auto;
.ant-carousel .slick-slide {
text-align: center;
height: 235px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}
.market {
height: calc(~"100vh - 110px");
background: #fff;
padding: 20px;
box-sizing: border-box;
overflow: auto;
.ant-carousel .slick-slide {
text-align: center;
height: 235px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}
.ant-carousel .custom-slick-arrow {
width: 25px;
height: 25px;
font-size: 25px;
color: #fff;
background-color: rgba(31, 45, 61, 0.11);
opacity: 0.3;
}
.ant-carousel .custom-slick-arrow:before {
display: none;
}
.ant-carousel .custom-slick-arrow:hover {
opacity: 0.5;
}
.ant-carousel .slick-slide h3 {
color: #fff;
}
.ant-list-item {
display: flex !important;
align-items: center;
justify-content: space-between;
}
.ant-list-item-meta-description {
width: 200px;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
}
.ant-carousel .custom-slick-arrow {
width: 25px;
height: 25px;
font-size: 25px;
color: #fff;
background-color: rgba(31, 45, 61, 0.11);
opacity: 0.3;
}
.ant-carousel .custom-slick-arrow:before {
display: none;
}
.ant-carousel .custom-slick-arrow:hover {
opacity: 0.5;
}
.ant-carousel .slick-slide h3 {
color: #fff;
}
.ant-list-item {
display: flex !important;
align-items: center;
justify-content: space-between;
}
.ant-list-item-meta-description {
width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
</style>

View File

@@ -1,5 +1,5 @@
import { clipboard, ipcRenderer, remote } from 'electron';
import { v4 as uuidv4 } from 'uuid';
import { clipboard, ipcRenderer, remote } from "electron";
import { v4 as uuidv4 } from "uuid";
import {
getWindowHeight,
searchKeyValues,
@@ -7,34 +7,34 @@ import {
mergePlugins,
find,
downloadZip,
fileLists
} from '../../assets/common/utils';
import systemMethod from '../../assets/common/system';
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
fileLists,
} from "../../assets/common/utils";
import systemMethod from "../../assets/common/system";
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
const state = {
selected: null,
options: [],
showMain: false,
current: ['market'],
searchValue: '',
current: ["market"],
searchValue: "",
devPlugins: mergePlugins(sysFile.getUserPlugins() || []),
subPlaceHolder: '',
subPlaceHolder: "",
pluginLoading: true,
pluginInfo: (() => {
try {
return window.pluginInfo || {};
} catch (e) {}
})()
})(),
};
const mutations = {
commonUpdate(state, payload) {
Object.keys(payload).forEach((key) => {
state[key] = payload[key];
if (key === 'devPlugins') {
if (key === "devPlugins") {
sysFile.savePlugins(payload[key]);
}
});
@@ -43,11 +43,15 @@ const mutations = {
state.subPlaceHolder = payload;
},
deleteDevPlugin(state, payload) {
state.devPlugins = state.devPlugins.filter((plugin) => plugin.name !== payload.name);
state.devPlugins = state.devPlugins.filter(
(plugin) => plugin.name !== payload.name
);
sysFile.savePlugins(state.devPlugins);
},
deleteProdPlugin(state, payload) {
state.devPlugins = state.devPlugins.filter((plugin) => plugin.id !== payload.id);
state.devPlugins = state.devPlugins.filter(
(plugin) => plugin.id !== payload.id
);
sysFile.savePlugins(state.devPlugins);
// todo 删除 static 目录下的对应插件
},
@@ -59,124 +63,136 @@ const mutations = {
});
state.devPlugins = [...state.devPlugins];
sysFile.savePlugins(state.devPlugins);
}
},
};
const actions = {
showMainUI({ commit, state }, paylpad) {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight()
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight(),
});
setTimeout(() => {
commit('commonUpdate', {
commit("commonUpdate", {
showMain: true,
selected: {
key: 'market',
name: '插件中心'
}
key: "market",
name: "插件中心",
},
});
}, 50);
},
reloadDevPlugin({ commit }, payload) {
const config = JSON.parse(fs.readFileSync(path.join(payload.sourceFile, '../plugin.json'), 'utf-8'));
const config = JSON.parse(
fs.readFileSync(path.join(payload.sourceFile, "../plugin.json"), "utf-8")
);
const pluginConfig = {
...config,
sourceFile: path.join(payload.sourceFile, `../${config.main}`)
sourceFile: path.join(payload.sourceFile, `../${config.main}`),
};
const devPlugins = [...state.devPlugins];
commit('commonUpdate', {
commit("commonUpdate", {
devPlugins: devPlugins.map((plugin) => {
if (plugin.name === payload.name) {
return {
...plugin,
...pluginConfig
...pluginConfig,
};
}
return plugin;
})
}),
});
},
async onSearch({ commit }, paylpad) {
if (state.selected && state.selected.key !== 'plugin-container') {
commit('commonUpdate', { searchValue: '' });
/**
* @param {Object} payload payload.filePath为配置文件的绝对路径。payload.value为搜索栏文字值。
*/
async onSearch({ commit }, payload) {
if (state.selected && state.selected.key !== "plugin-container") {
commit("commonUpdate", { searchValue: "" });
return;
}
const value = paylpad.value;
const value = payload.value;
// 在插件界面不触发其他功能
if ((state.selected && state.selected.key === 'plugin-container') || paylpad.searchType === 'subWindow') {
commit('commonUpdate', { searchValue: value });
if (
(state.selected && state.selected.key === "plugin-container") ||
payload.searchType === "subWindow"
) {
commit("commonUpdate", { searchValue: value });
return;
}
const fileUrl = paylpad.filePath || clipboard.read('public.file-url').replace('file://', '');
commit('commonUpdate', { searchValue: value });
const fileUrl =
payload.filePath ||
clipboard.read("public.file-url").replace("file://", "");
commit("commonUpdate", { searchValue: value });
// 复制文件
if (paylpad.filePath || (fileUrl && value === 'plugin.json')) {
const config = JSON.parse(fs.readFileSync(fileUrl, 'utf-8'));
if (payload.filePath || (fileUrl && value === "plugin.json")) {
const config = JSON.parse(fs.readFileSync(fileUrl, "utf-8"));
const pluginConfig = {
...config,
sourceFile: path.join(fileUrl, `../${config.main || 'index.html'}`),
sourceFile: path.join(fileUrl, `../${config.main || "index.html"}`),
id: uuidv4(),
type: 'dev',
icon: 'image://' + path.join(fileUrl, `../${config.logo}`),
type: "dev",
icon: "image://" + path.join(fileUrl, `../${config.logo}`),
subType: (() => {
if (config.main) {
return '';
return "";
}
return 'template';
})()
return "template";
})(),
};
commit('commonUpdate', {
commit("commonUpdate", {
selected: {
key: 'plugin',
name: 'plugin.json'
key: "plugin",
name: "plugin.json",
},
searchValue: '',
searchValue: "",
options: [
{
name: '新建rubick开发插件',
value: 'new-plugin',
icon: 'https://static.91jkys.com/activity/img/b37ff555c748489f88f3adac15b76f18.png',
desc: '新建rubick开发插件',
name: "新建rubick开发插件",
value: "new-plugin",
icon:
"https://static.91jkys.com/activity/img/b37ff555c748489f88f3adac15b76f18.png",
desc: "新建rubick开发插件",
click: (router) => {
commit('commonUpdate', {
commit("commonUpdate", {
showMain: true,
devPlugins: [pluginConfig, ...state.devPlugins],
selected: {
key: 'plugin',
name: '新建rubick开发插件'
key: "plugin",
name: "新建rubick开发插件",
},
current: ['dev']
current: ["dev"],
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight()
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight(),
});
router.push('/home/dev');
}
router.push("/home/dev");
},
},
{
name: '复制路径',
desc: '复制路径',
value: 'copy-path',
icon: 'https://static.91jkys.com/activity/img/ac0d4df0247345b9a84c8cd7ea3dd696.png',
name: "复制路径",
desc: "复制路径",
value: "copy-path",
icon:
"https://static.91jkys.com/activity/img/ac0d4df0247345b9a84c8cd7ea3dd696.png",
click: () => {
clipboard.writeText(fileUrl);
commit('commonUpdate', {
commit("commonUpdate", {
showMain: false,
selected: null,
options: []
options: [],
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([])
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight([]),
});
remote.Notification('Rubick 通知', { body: '复制成功' });
}
}
]
remote.Notification("Rubick 通知", { body: "复制成功" });
},
},
],
});
// 调整窗口大小
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options)
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight(state.options),
});
return;
}
@@ -187,7 +203,7 @@ const actions = {
if (value) {
state.devPlugins.forEach((plugin) => {
// dev 插件未开启
if (plugin.type === 'dev' && !plugin.status) return;
if (plugin.type === "dev" && !plugin.status) return;
const feature = plugin.features;
feature.forEach((fe) => {
const cmds = searchKeyValues(fe.cmds, value);
@@ -195,14 +211,19 @@ const actions = {
...options,
...cmds.map((cmd) => ({
name: cmd,
value: 'plugin',
icon: plugin.sourceFile ? 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`) : plugin.logo,
value: "plugin",
icon: plugin.sourceFile
? "image://" + path.join(plugin.sourceFile, `../${plugin.logo}`)
: plugin.logo,
desc: fe.explain,
type: plugin.type,
click: (router) => {
actions.openPlugin({ commit }, { cmd, plugin, feature: fe, router });
}
}))
actions.openPlugin(
{ commit },
{ cmd, plugin, feature: fe, router }
);
},
})),
];
});
});
@@ -215,8 +236,12 @@ const actions = {
if (!descMap.get(plugin)) {
descMap.set(plugin, true);
let has = false;
plugin.keyWords.some(keyWord => {
if (keyWord.toLocaleUpperCase().indexOf(value.toLocaleUpperCase()) >= 0) {
plugin.keyWords.some((keyWord) => {
if (
keyWord
.toLocaleUpperCase()
.indexOf(value.toLocaleUpperCase()) >= 0
) {
has = keyWord;
plugin.name = keyWord;
return true;
@@ -233,17 +258,17 @@ const actions = {
actions.openPlugin({ commit }, { plugin });
};
return plugin;
})
}),
];
descMap = null;
}
commit('commonUpdate', {
options
commit("commonUpdate", {
options,
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options)
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight(state.options),
});
},
async downloadPlugin({ commit }, payload) {
@@ -251,88 +276,90 @@ const actions = {
const fileUrl = find(distUrl);
// 复制文件
const config = JSON.parse(fs.readFileSync(`${fileUrl}/plugin.json`, 'utf-8'));
const config = JSON.parse(
fs.readFileSync(`${fileUrl}/plugin.json`, "utf-8")
);
const pluginConfig = {
...config,
id: uuidv4(),
sourceFile: `${fileUrl}/${config.main}`,
type: 'prod',
type: "prod",
icon: payload.logo,
subType: (() => {
if (config.main) {
return '';
return "";
}
return 'template';
})()
return "template";
})(),
};
commit('commonUpdate', {
devPlugins: [pluginConfig, ...state.devPlugins]
commit("commonUpdate", {
devPlugins: [pluginConfig, ...state.devPlugins],
});
},
openPlugin({ commit }, { cmd, plugin, feature, router, payload }) {
if (plugin.type === 'app') {
if (plugin.type === "app") {
execSync(plugin.action);
commit('commonUpdate', {
commit("commonUpdate", {
selected: null,
showMain: false,
options: [],
searchValue: ''
searchValue: "",
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([])
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight([]),
});
return;
}
commit('commonUpdate', {
commit("commonUpdate", {
selected: {
key: 'plugin-container',
key: "plugin-container",
name: cmd.label ? cmd.label : cmd,
icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`)
icon: "image://" + path.join(plugin.sourceFile, `../${plugin.logo}`),
},
searchValue: '',
showMain: true
searchValue: "",
showMain: true,
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight()
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight(),
});
if (plugin.type === 'system') {
if (plugin.type === "system") {
systemMethod[plugin.tag][feature.code]();
commit('commonUpdate', {
commit("commonUpdate", {
selected: null,
showMain: false,
options: []
options: [],
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([])
ipcRenderer.send("changeWindowSize-rubick", {
height: getWindowHeight([]),
});
router.push({
path: '/home'
path: "/home",
});
return;
}
commit('commonUpdate', {
commit("commonUpdate", {
pluginInfo: {
cmd,
...plugin,
detail: feature,
payload
}
payload,
},
});
router.push({
path: '/plugin',
path: "/plugin",
query: {
...plugin,
_modify: Date.now(),
detail: JSON.stringify(feature)
}
detail: JSON.stringify(feature),
},
});
}
},
};
export default {
namespaced: true,
state,
mutations,
actions
actions,
};

View File

@@ -1,5 +1,5 @@
const {getData, getlocalDataFile, saveData} = require("./utils");
const axios = require('axios');
const marked = require("marked");
const rendererMD = new marked.Renderer();
const path = require('path');
@@ -22,7 +22,7 @@ function getQueryVariable(variable) {
if (location.href.indexOf('targetFile') > -1) {
filePath = decodeURIComponent(getQueryVariable('targetFile'));
} else {
filePath = process.platform === 'win32' ? location.pathname.split(':')[1] : location.pathname.replace('file://', '');
filePath = process.platform === 'win32' ? location.pathname.replace('/', '') : location.pathname.replace('file://', '');
}
const {ipcRenderer, nativeImage, clipboard, remote, shell} = require('electron');
@@ -255,6 +255,14 @@ window.rubick = {
shellOpenPath(path) {
shell.openPath(path)
},
request(config = {}) {
return axios.create({
timeout: 10000,
withCredentials: true,
...config,
});
}
}
const preloadPath = getQueryVariable('preloadPath') || './preload.js';