Merge branch 'master' of https://github.com/clouDr-f2e/rubick into master

This commit is contained in:
徐志鹏 2021-07-12 19:52:28 +08:00
commit 261a6db49e
11 changed files with 17094 additions and 54 deletions

View File

@ -18,7 +18,7 @@
之所以做这个工具箱一方面是 utools 本身并未开源,但是公司内部的工具库又无法发布到 utools 插件中,所以为了既要享受 utools 生态又要有定制化需求,我们自己参考 utools 设计,做了 Rubick 之所以做这个工具箱一方面是 utools 本身并未开源,但是公司内部的工具库又无法发布到 utools 插件中,所以为了既要享受 utools 生态又要有定制化需求,我们自己参考 utools 设计,做了 Rubick
## 安装包 ## 安装包
* [Rubick Mac OS V0.0.1](https://github.com/clouDr-f2e/rubick/releases/tag/v0.0.1-beta.2) * [Rubick Mac OS V0.0.1](https://github.com/clouDr-f2e/rubick/releases/download/v0.0.1-beta.3/rubick2-0.0.1.pkg)
## 支持能力 ## 支持能力

16892
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,7 @@ export default {
return dbData.find(d => d._id === key) || {}; return dbData.find(d => d._id === key) || {};
}, },
remove({key}) { remove({key}) {
key = typeof key === 'object' ? key.id : key; key = typeof key === 'object' ? key._id : key;
let dbData = getData(dbPath); let dbData = getData(dbPath);
let find = false; let find = false;
dbData.some((d, i) => { dbData.some((d, i) => {

View File

@ -99,6 +99,9 @@ export default {
ipcRenderer.on('new-window', this.newWindow); ipcRenderer.on('new-window', this.newWindow);
// //
ipcRenderer.on('superPanel-openPlugin', (e, args) => { ipcRenderer.on('superPanel-openPlugin', (e, args) => {
ipcRenderer.send('msg-trigger', {
type: 'showMainWindow',
});
this.openPlugin({ this.openPlugin({
cmd: args.cmd, cmd: args.cmd,
plugin: args.plugin, plugin: args.plugin,

View File

@ -110,6 +110,20 @@ function mergePlugins(plugins) {
target.push(item) target.push(item)
} }
}); });
ipcRenderer && ipcRenderer.send('optionPlugin', {
plugins: target.filter((plugin) => {
let hasOption = false;
plugin.features.forEach(fe => {
fe.cmds.forEach(cmd => {
if (cmd.type) {
hasOption = true;
}
})
});
return hasOption;
})
});
return target return target
} }

View File

@ -68,6 +68,19 @@ export default {
}), }),
}); });
} }
if (event.channel === 'removeFeature') {
this.commonUpdate({
devPlugins: this.devPlugins.map(plugin => {
if (plugin.name === this.query.name) {
return {
...plugin,
features: plugin.features.filter(fe => fe.code !== event.args[0].code)
}
}
return plugin;
}),
});
}
}) })
}, },
methods: { methods: {

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="dev-container"> <div class="dev-container">
<div class="dev-detail" v-if="devPlugin.length"> <div class="dev-detail" v-if="devPlugin.length">
<a-menu v-model="currentSelect" style="width: 200px; height: 100%" mode="vertical"> <a-menu v-model="currentSelect" style="width: 256px; height: 100%" mode="vertical">
<a-menu-item @click="currentSelect = [index]" v-for="(plugin, index) in devPlugin" :key="index"> <a-menu-item @click="currentSelect = [index]" v-for="(plugin, index) in devPlugin" :key="index">
<div class="menu-item"> <div class="menu-item">
<img width="40" height="40" :src="plugin.icon" /> <img width="40" height="40" :src="plugin.icon" />
@ -160,6 +160,10 @@ export default {
} }
.desc { .desc {
color: #999; color: #999;
width: 180px;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
} }
} }
} }
@ -170,11 +174,12 @@ export default {
width: 100%; width: 100%;
} }
.plugin-detail { .plugin-detail {
padding: 20px; padding: 20px 20px 0 20px;
box-sizing: border-box; box-sizing: border-box;
flex: 1; flex: 1;
width: 500px;
.detail-container { .detail-container {
height: 340px; height: 320px;
overflow: auto; overflow: auto;
max-height: 320px; max-height: 320px;
width: 100%; width: 100%;
@ -202,6 +207,8 @@ export default {
.desc-item { .desc-item {
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
padding: 10px 0; padding: 10px 0;
width: 100%;
overflow: auto;
.desc-title { .desc-title {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -111,9 +111,10 @@ export default {
overflow: auto; overflow: auto;
} }
.plugin-detail { .plugin-detail {
padding: 20px; padding: 20px 20px 0 20px;
box-sizing: border-box; box-sizing: border-box;
flex: 1; flex: 1;
height: 100%;
.plugin-top { .plugin-top {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;

View File

@ -77,7 +77,43 @@ new Vue({
const word = this.selectData.text; const word = this.selectData.text;
const isCh = isChinese(word); const isCh = isChinese(word);
this.translate(word, isCh ? 'en' : 'zh'); this.translate(word, isCh ? 'en' : 'zh');
this.targetOptions = this.options.translate; this.targetOptions = JSON.parse(JSON.stringify(this.options.translate));
(this.selectData.optionPlugin || []).forEach(plugin => {
plugin.features.forEach(fe => {
fe.cmds.forEach(cmd => {
if (cmd.type === 'regex' && eval(cmd.match).test(word)) {
this.targetOptions.push({
type: 'ext',
name: cmd.label,
icon: plugin.icon,
click: () => {
ipcRenderer.send('superPanel-openPlugin', {
cmd: cmd,
plugin: plugin,
feature: fe,
data: word
})
}
});
}
if (cmd.type === 'over') {
this.targetOptions.push({
type: 'ext',
name: cmd.label,
icon: plugin.icon,
click: () => {
ipcRenderer.send('superPanel-openPlugin', {
cmd: cmd,
plugin: plugin,
feature: fe,
data: word
})
}
});
}
})
});
});
} else if (!ext || path.parse(this.selectData.fileUrl).base === 'Desktop') { } else if (!ext || path.parse(this.selectData.fileUrl).base === 'Desktop') {
// 如果在桌面上或者没有选择任何文件,则展示通用选项 // 如果在桌面上或者没有选择任何文件,则展示通用选项
this.targetOptions = this.options.common; this.targetOptions = this.options.common;
@ -91,7 +127,6 @@ new Vue({
// 如果是图片,则唤起图片选项 // 如果是图片,则唤起图片选项
const regImg = /\.(png|jpg|gif|jpeg|webp)$/; const regImg = /\.(png|jpg|gif|jpeg|webp)$/;
if (cmd.type === 'img' && regImg.test(ext)) { if (cmd.type === 'img' && regImg.test(ext)) {
console.log(plugin);
this.targetOptions.push({ this.targetOptions.push({
type: 'ext', type: 'ext',
name: cmd.label, name: cmd.label,

View File

@ -1,6 +1,12 @@
const {getData, getlocalDataFile, saveData} = require("./utils");
const marked = require("marked"); const marked = require("marked");
const rendererMD = new marked.Renderer(); const rendererMD = new marked.Renderer();
const path = require('path'); const path = require('path');
const os = require('os');
const appPath = path.join(getlocalDataFile());
const dbPath = path.join(appPath, './db.json');
let filePath = ''; let filePath = '';
function getQueryVariable(variable) { function getQueryVariable(variable) {
@ -141,60 +147,88 @@ window.utools = window.rubick = {
}, },
db: { db: {
put(data) { put(data) {
ipcRenderer.send('msg-trigger', { data._rev = '';
type: 'db.put', let dbData = getData(dbPath) || [];
data, let target = [];
dbData.some((d, i) => {
if (d._id === data._id) {
target = [d, i]
return true;
}
return false;
}); });
return new Promise((resolve, reject) => {
ipcRenderer.once(`msg-back-db.put`, (e, result) => { // 更新
result ? resolve(result) : reject(); if (target[0]) {
}); dbData[target[1]] = data;
}) } else {
dbData.push(data);
}
saveData(dbPath, dbData);
return {
id: data._id,
ok: true,
rev: '',
}
}, },
get(key) { get(key) {
ipcRenderer.send('msg-trigger', { const dbData = getData(dbPath) || [];
type: 'db.get', return dbData.find(d => d._id === key) || '';
key,
});
return new Promise((resolve, reject) => {
ipcRenderer.once(`msg-back-db.get`, (e, result) => {
result ? resolve(result) : reject();
});
})
}, },
remove(key) { remove(key) {
ipcRenderer.send('msg-trigger', { key = typeof key === 'object' ? key._id : key;
type: 'db.remove', let dbData = getData(dbPath);
key, let find = false;
dbData.some((d, i) => {
if (d._id === key) {
dbData.splice(i, 1);
find = true;
return true;
}
return false;
}); });
return new Promise((resolve, reject) => { if (find) {
ipcRenderer.once(`msg-back-db.remove`, (e, result) => { saveData(dbPath, dbData);
result ? resolve(result) : reject(); return {
}); id: key,
}) ok: true,
}, rev: '',
allDocs(key) { }
ipcRenderer.send('msg-trigger', { } else {
type: 'db.allDocs', return {
key, id: key,
}); ok: false,
return new Promise((resolve, reject) => { rev: '',
ipcRenderer.once(`msg-back-db.allDocs`, (e, result) => { }
console.log(result); }
result ? resolve(result) : reject();
});
})
}, },
bulkDocs(docs) { bulkDocs(docs) {
ipcRenderer.send('msg-trigger', { const dbData = getData(dbPath);
type: 'db.bulkDocs', dbData.forEach((d, i) => {
key, const result = docs.find(data => data._id === d._id);
if (result) {
dbData[i] = result;
}
}); });
return new Promise((resolve, reject) => { saveData(dbPath, dbData);
ipcRenderer.once(`msg-back-db.bulkDocs`, (e, result) => { return docs.map(d => ({
result ? resolve(result) : reject(); id: d._id,
}); success: true,
}) rev: '',
}))
},
allDocs(key) {
const dbData = getData(dbPath);
if (!key) {
return dbData;
}
if (typeof key === 'string') {
return dbData.filter(d => d._id.indexOf(key) >= 0);
}
if (Array.isArray(key)) {
return dbData.filter(d => key.indexOf(d._id) >= 0);
}
return [];
} }
}, },
isDarkColors() { isDarkColors() {
@ -211,6 +245,10 @@ window.utools = window.rubick = {
setFeature(feature) { setFeature(feature) {
ipcRenderer.sendToHost('setFeature', {feature}); ipcRenderer.sendToHost('setFeature', {feature});
}, },
removeFeature(code) {
ipcRenderer.sendToHost('removeFeature', {code});
},
ubrowser: { ubrowser: {
winId: '', winId: '',
async goto(md, opts) { async goto(md, opts) {
@ -282,9 +320,19 @@ window.utools = window.rubick = {
} }
}, },
}, },
// 系统
shellOpenExternal(url) { shellOpenExternal(url) {
shell.openExternal(url); shell.openExternal(url);
} },
isMacOs() {
return os.type() === 'Darwin';
},
isWindows() {
return os.type() === 'Windows_NT';
},
} }
const preloadPath = getQueryVariable('preloadPath') || './preload.js'; const preloadPath = getQueryVariable('preloadPath') || './preload.js';

27
static/utils.js Normal file
View File

@ -0,0 +1,27 @@
const fs = require("fs");
const getlocalDataFile = () => {
let localDataFile = process.env.HOME;
if (!localDataFile) {
localDataFile = process.env.LOCALAPPDATA;
}
return localDataFile;
};
function saveData(path, value) {
fs.writeFileSync(path, JSON.stringify(value));
}
function getData(path, defaultValue) {
try {
return JSON.parse(fs.readFileSync(path, 'utf8'));
} catch (e) {
return defaultValue || undefined;
}
}
module.exports = {
getlocalDataFile,
saveData,
getData
}